Cache_get_field_content, converting to R33+
#1

I have been converting an old script to R33, and will from there upgrade to R40 later on. Currently I am planning to use R33 (in regards to BlueG's MySQL plugin).

I now want to convert my script, exactly as described here: https://sampforum.blast.hk/showthread.php?tid=544437 - I don't know how to convert this part of the code. I am now having the same solution as the dude has, but I am not sure if it is correct.

I have the exact same question, there is nothing to add, however no one replied ever to this dude. If anyone have a solution on that, it would be awesome

EDIT:
Код:
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.
Reply
#2

Is "OnPlayerCheckBannedAccount" used as a callback to mysql_(t|p)query?
Reply
#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
#4

CAN ANYONE HLEP ME PLEASE!
Reply
#5

Who keeps deleting my comment?
Reply
#6

Learn to debug. Check mysql_log. Add print(f) everywhere you can, and look in server's console. This way you can pinpoint what exactly is not firing.
Reply
#7

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Learn to debug. Check mysql_log. Add print(f) everywhere you can, and look in server's console. This way you can pinpoint what exactly is not firing.
So that's all I have to do?
Reply
#8

It will help you find the problem, not solve it right away.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)