How do I return something from the callback of the pquery method? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How do I return something from the callback of the pquery method? (
/showthread.php?tid=643208)
How do I return something from the callback of the pquery method? -
EtayJ - 15.10.2017
I have this:
PHP код:
forward CheckIfAccountExists(accountName[128]);
public CheckIfAccountExists(accountName[128])
{
new query[128];
mysql_format(db, query, sizeof(query), "SELECT * FROM logindata WHERE uName = '%e';", accountName);
mysql_pquery(db, query, "OnLoginDataLoaded");
}
forward OnLoginDataLoaded();
public OnLoginDataLoaded()
{
new rows = cache_num_rows();
if(rows == 1)
return 1;
return 0;
}
and I wanna do something like this:
PHP код:
COMMAND:checkplayerexists(playerid, params[])
{
new playerName[128]; //The player in question
if(sscanf(params, "s", playerName)) SendClientMessage(playerid, COLOR_WHITE, "Usage: /checkplayerexists <name>");
else
{
if(CheckIfAccountExists(playerName))
{
new msg[128], name[128];
format(msg, sizeof(msg), "Player %s exists in the database", playerName);
SendClientMessage(playerid, COLOR_GREEN, msg);
GetPlayerName(playerid, name, sizeof(name));
format(msg, sizeof(msg), "Admin %s has just checked if the player %s exists in the database and he does.", name, playerName);
print(msg);
}
else
{
new msg[128], name[128];
format(msg, sizeof(msg), "Player %s doesn't exist in the database", playerName);
SendClientMessage(playerid, COLOR_RED, msg);
GetPlayerName(playerid, name, sizeof(name));
format(msg, sizeof(msg), "Admin %s has just checked if the player %s exists in the database and he doesn't.", name, playerName);
print(msg);
}
}
return 1;
}
But I am really don't know how to do that because I am only able to access the row count in the callback and not after sending the query in the first method
Re: How do I return something from the callback of the pquery method? -
Kyle - 15.10.2017
Quote:
Originally Posted by EtayJ
I have this:
PHP код:
forward CheckIfAccountExists(accountName[128]);
public CheckIfAccountExists(accountName[128])
{
new query[128];
mysql_format(db, query, sizeof(query), "SELECT * FROM logindata WHERE uName = '%e';", accountName);
mysql_pquery(db, query, "OnLoginDataLoaded");
}
forward OnLoginDataLoaded();
public OnLoginDataLoaded()
{
new rows = cache_num_rows();
if(rows == 1)
return 1;
return 0;
}
and I wanna do something like this:
PHP код:
COMMAND:checkplayerexists(playerid, params[])
{
new playerName[128]; //The player in question
if(sscanf(params, "s", playerName)) SendClientMessage(playerid, COLOR_WHITE, "Usage: /checkplayerexists <name>");
else
{
if(CheckIfAccountExists(playerName))
{
new msg[128], name[128];
format(msg, sizeof(msg), "Player %s exists in the database", playerName);
SendClientMessage(playerid, COLOR_GREEN, msg);
GetPlayerName(playerid, name, sizeof(name));
format(msg, sizeof(msg), "Admin %s has just checked if the player %s exists in the database and he does.", name, playerName);
print(msg);
}
else
{
new msg[128], name[128];
format(msg, sizeof(msg), "Player %s doesn't exist in the database", playerName);
SendClientMessage(playerid, COLOR_RED, msg);
GetPlayerName(playerid, name, sizeof(name));
format(msg, sizeof(msg), "Admin %s has just checked if the player %s exists in the database and he doesn't.", name, playerName);
print(msg);
}
}
return 1;
}
But I am really don't know how to do that because I am only able to access the row count in the callback and not after sending the query in the first method
|
Pass the admin variable in the callback. Then send the message to that admin ID that you have passed within the callback.
https://pastebin.com/hg0RfbeQ
Re: How do I return something from the callback of the pquery method? -
EtayJ - 15.10.2017
Thanks Kyle!