This OnPlayerDataLoad thingy is the callback that will be fired. You specify the callback in your mysql_function_query call. This string is the callback that will be called once the query is finished.
This is in OnPlayerConnect:
pawn Код:
format(query, sizeof(query), "SELECT ... FROM bans WHERE BanName = '%s' LIMIT 0,1", name);
mysql_function_query(1, query, "OnBanCheckFinish", "i", playerid);
You run the ban check query.
This is OnBanCheckFinish, the callback called when the ban checking query finishes.
pawn Код:
forward OnBanCheckFinish(playerid);
public OnBanCheckFinish(playerid)
{
new rows, fields;
cache_get_data(rows, fields);
if(rows == 1)
{
// player is banned!?
}
else
{
// player is not banned, so call the data loading query
new name[24];
GetPlayerName(playerid, name, sizeof(name));
format(query, sizeof(query), "SELECT ... FROM accounts WHERE Name = '%s' LIMIT 0,1", name);
mysql_function_query(1, query, true, "OnPlayerDataLoad", "i", playerid);
}
}
Now, in case the player is not banned, we will select the player's data from the accounts table. As you can see from the code above, OnPlayerDataLoad(playerid) is the callback that will be fired when our accounts query finishes.
Now the OnPlayerDataLoad query, same as I described before:
pawn Код:
forward OnUserDataLoad(playerid);
public OnUserDataLoad(playerid)
{
// Get the amount of rows and fields in each row returned by this query.
new rows, fields;
cache_get_data(rows, fields);
// We should only have ONE row, this is why I added the LIMIT 0,1 clause to your query.
if(rows)
{
// We have a row!
new name[24];
cache_get_row(0, 0, name);
}
else
{
// This player most likely does not exist :(
}
// Return 1 to make sure that the plugin clears the cache.
return 1;
}
Now a major thing which I think you still did not understand:
QUERIES LIKE "SELECT name FROM players WHERE name = 'ANDRE'" ARE VERY USELESS - YOU ALREADY KNOW THE NAME. SO SELECT OTHER DATA.