03.02.2014, 12:28
pawn Код:
GetAccountID(playerid)
{
// Setup local variables
new query[128], sn[24];
// Get playername
GetPlayerName(playerid, sn, sizeof(sn));
// Format the query to get the ID from the player's account (limit the amount of rows to 1 to prevent MySQL searching through the entire database)
format(query, 128,"SELECT ID FROM "TABLE_ACCOUNT" WHERE Name = '%s' LIMIT 1", sn);
// Execute the threaded query and call the callback "OnAccountIDLoad" with "playerid" as parameter when MySQL finished executing the query
mysql_tquery(1, query, "OnAccountIDLoad", "i", playerid);
return 0;
}
// This callback is called by MySQL when the query has finished execution
forward OnAccountIDLoad(playerid);
public OnAccountIDLoad(playerid)
{
// Check if there was a result
if (cache_get_row_count() == 1)
{
// Get the contents of the "ID" field as an integer (from row 0) and store it
PlayerInfo[playerid][pID] = cache_get_field_content_int(0, "ID");
}
// Clear the cache-data upon exiting this callback
return 1;
}