Cache_get_field_content, converting to R33+
#3

Код:
public OnQueryFinish(query[], resultid, extraid, connectionHandle) {
// a lot of threads and stuff.
// .....

	case THREAD_OFFLINE_FINE: {
	        mysql_store_result(g_MySQLConnections);

	        new
	            szMessage[128],
	            szPlayerIP[20],
	            iPlayerAdminLevel,
	            iPlayerBanned,
	            szReason[128],
	            iPlayerPermabanned,
	            iCash,
	            iBankAccount,
	            iFinedAmount,
	            szPlayerName[MAX_PLAYER_NAME],
	            szResult[256],
				iTotalCashAfterFine;

	        if(mysql_fetch_row_format(szResult, "|", g_MySQLConnections)) {
				sscanf(szResult, "p<|>dddssdd", iPlayerPermabanned, iPlayerBanned, iPlayerAdminLevel, szPlayerName, szPlayerIP, iBankAccount, iCash);

				if(iPlayerPermabanned > 0)
				    return SendClientMessage(extraid, COLOR_GREY, "The specified player is permanently banned.");
				    
				if(iPlayerAdminLevel > 0)
				    return SendClientMessage(extraid, COLOR_GREY, "You can't fine other administrators.");
				    
				GetPVarString(extraid, "ofinereason", szReason, sizeof(szReason));
				mysql_real_escape_string(szReason, szReason, g_MySQLConnections);
				
				iFinedAmount = GetPVarInt(extraid, "ofineamount");
				
				iTotalCashAfterFine = iCash - iFinedAmount;
				format(szQuery, sizeof(szQuery), "UPDATE players SET Cash = %d WHERE Username = '%s'", iTotalCashAfterFine, szPlayerName);
				mysql_query(szQuery, THREAD_NO_RESULT, extraid, g_MySQLConnections);

				format(szMessage, sizeof(szMessage), "AdmCmd: %s was offline fined $%d by %s, reason: %s", szPlayerName, iFinedAmount, GetPlayerNameEx(extraid), szReason);
				Log("logs/admin.log", szMessage);
				format(szMessage, sizeof(szMessage), "AdmCmd: %s was offline fined $%d by %s, reason: %s", szPlayerName, iFinedAmount, GetPlayerNameEx(extraid), szReason);
				ABroadCast(COLOR_LIGHTRED,szMessage,1);
	        } else SendClientMessage(extraid, COLOR_GREY, "The player specified does not exist.");

	        mysql_free_result(g_MySQLConnections);
	    }
}
That is the old code, I converted it to:

Код:
// under OnQueryFinish method
	case THREAD_OFFLINE_FINE: {

		   new
	            szMessage[128],
	            szPlayerIP[20],
	            iPlayerAdminLevel,
	            iPlayerBanned,
	            szReason[128],
	            iPlayerPermabanned,
	            iCash,
	            iBankAccount,
	            iFinedAmount,
	            szPlayerName[MAX_PLAYER_NAME],
	            szResult[256],
				iTotalCashAfterFine,
				rows,
				fields;

            cache_get_data(rows, fields);
            
            if(rows) {
     
			   cache_get_field_content(0, "PermaBanned", iPlayerPermaBanned);
			   cache_get_field_content(0, "Banned", iPlayerBanned);
			   cache_get_field_content(0, "AdminLevel", iPlayerAdminLevel);
			   cache_get_field_content(0, "Username", szPlayerName);
			   cache_get_field_content(0, "LastIP", szPlayerIP);
			   cache_get_field_Content(0, "Bank", iBankAccount);
			   cache_get_field_content(0, "Cash", iCash);
				
				if(iPlayerPermabanned > 0)
				    return SendClientMessage(extraid, COLOR_GREY, "The specified player is permanently banned.");

				if(iPlayerAdminLevel > 0)
				    return SendClientMessage(extraid, COLOR_GREY, "You can't fine other administrators.");

				GetPVarString(extraid, "ofinereason", szReason, sizeof(szReason));

				mysql_escape_string(szReason, szReason, g_MySQLConnections);

				iFinedAmount = GetPVarInt(extraid, "ofineamount");

				iTotalCashAfterFine = iCash - iFinedAmount;
				format(szQuery, sizeof(szQuery), "UPDATE players SET Cash = %d WHERE Username = '%s'", iTotalCashAfterFine, szPlayerName);
		    	mysql_tquery(g_MySQLConnections, szQuery, "OnQueryFinish", "ii", THREAD_NO_RESULT, extraid);
				
				format(szMessage, sizeof(szMessage), "AdmCmd: %s was offline fined $%d by %s, reason: %s", szPlayerName, iFinedAmount, GetPlayerNameEx(extraid), szReason);
				Log("logs/admin.log", szMessage);
				format(szMessage, sizeof(szMessage), "AdmCmd: %s was offline fined $%d by %s, reason: %s", szPlayerName, iFinedAmount, GetPlayerNameEx(extraid), szReason);
				ABroadCast(COLOR_LIGHTRED,szMessage,1);
	        } else SendClientMessage(extraid, COLOR_GREY, "The player specified does not exist.");

	       
	    }
I am calling it in the command cmdfine by using:
Код:
mysql_tquery(g_MySQLConnections, query, "OnQueryFinish", "ii", THREAD_OFFLINE_FINE, playerid);
It was apparently actually different, looked at the wrong script. Updated the main thread as well. It was actually different than the question I linked to.

Using MySQL R33.
Reply


Messages In This Thread
Cache_get_field_content, converting to R33+ - by vdraco - 08.08.2017, 21:21
Re: Cache_get_field_content, converting to R33+ - by Misiur - 08.08.2017, 21:49
Re: Cache_get_field_content, converting to R33+ - by vdraco - 08.08.2017, 23:42
Re: Cache_get_field_content, converting to R33+ - by vdraco - 09.08.2017, 00:22
Re: Cache_get_field_content, converting to R33+ - by vdraco - 09.08.2017, 00:26
Re: Cache_get_field_content, converting to R33+ - by Misiur - 09.08.2017, 00:27
Re: Cache_get_field_content, converting to R33+ - by vdraco - 09.08.2017, 01:16
Re: Cache_get_field_content, converting to R33+ - by Misiur - 09.08.2017, 01:17

Forum Jump:


Users browsing this thread: 1 Guest(s)