When you use "mysql_tquery", you need to add a callback name inside the function, along with parameters if you want to read any data from it's results.
t-query's are threaded and return the result when it's ready, not immediately after it.
You're getting that message because there is no data ready yet.
Use it like this:
pawn Код:
// Try to get all data for this player from the SQL-table (he might have already registered and needs to login properly by entering the password, or he might be a new player)
mysql_format(SQL_db, Query, sizeof(Query), "SELECT * FROM %s WHERE PlayerName = '%e' LIMIT 1", table_playerdata, APlayerData[playerid][PlayerName]);
mysql_tquery(SQL_db, Query, "Player_OnAccountLoad", "i", playerid);
pawn Код:
// This custom callback is called when a player connects to the server (MySQL received a query to get his password using the function "Player_AccountCheck")
forward Player_OnAccountLoad(playerid);
public Player_OnAccountLoad(playerid)
{
// Check if this player's account exists (number of rows should be 1)
if (cache_get_row_count(SQL_db) == 1)
{
// Setup local variables
new IP[16], Query[128];
// Read the SQLID of this player from the query-result
APlayerData[playerid][SQLID] = cache_get_field_content_int(0, "ID", SQL_db);
// Get the player's IP (needed to check if his stored IP in the database is the same as his current IP)
GetPlayerIp(playerid, IP, sizeof(IP));
// Update the IP in MySQL, just in case the player's IP changed
mysql_format(SQL_db, Query, sizeof(Query), "UPDATE %s SET IP = '%s' WHERE ID = '%i'", table_playerdata, IP, APlayerData[playerid][SQLID]);
mysql_tquery(SQL_db, Query, "", "");
// Check if this account is banned (the player might have changed his IP and the previous ban-check didn't give any results)
if (cache_get_field_content_int(0, "Banned", SQL_db) == 1)
{
// Kick the player and give a reason
SUP_Player_Kick(playerid, "{FF0000}Your account is banned, contact an administrator");
return 1;
}
// Read all data from the account
cache_get_field_content(0, "Password", APlayerData[playerid][PlayerPassword], SQL_db, 130);
cache_get_field_content(0, "IP", APlayerData[playerid][PlayerIP], SQL_db, 16);
if (cache_get_field_content_int(0, "SpeedInMph", SQL_db) == 1)
APlayerData[playerid][SpeedInMph] = true; // Set the SpeedInMph as mph
else
APlayerData[playerid][SpeedInMph] = false; // Set the SpeedInMph as kph
APlayerData[playerid][PlayerFine] = cache_get_field_content_int(0, "Fines", SQL_db);
APlayerData[playerid][PlayerTickets] = cache_get_field_content_int(0, "Tickets", SQL_db);
APlayerData[playerid][PlayerTicketPrice] = cache_get_field_content_int(0, "TicketCost", SQL_db);
APlayerData[playerid][PlayerMoney] = cache_get_field_content_int(0, "Money", SQL_db);
APlayerData[playerid][PlayerScore] = cache_get_field_content_int(0, "Score", SQL_db);
APlayerData[playerid][AdminLevel] = cache_get_field_content_int(0, "AdminLevel", SQL_db);
APlayerData[playerid][JailTime] = cache_get_field_content_int(0, "JailTime", SQL_db);
APlayerData[playerid][CompanyID] = cache_get_field_content_int(0, "CompanyID", SQL_db);
APlayerData[playerid][CompanyAccessLevel] = cache_get_field_content_int(0, "CompanyAccessLevel", SQL_db);
APlayerData[playerid][CompanyContribution] = cache_get_field_content_int(0, "CompanyContribution", SQL_db);
// If the IP matches the RegisterIP or the LastIP, auto-login the player (if enabled)
if ((AutoLogin == true) && (strcmp(APlayerData[playerid][PlayerIP], IP, false, 16) == 0))
{
// Send a message to the client to inform him that he logged in automatically
SendClientMessage(playerid, 0xFFFFFFFF, "{00FF00}Auto-logging in ...");
// The player has logged in properly
APlayerData[playerid][LoggedIn] = true;
// Send a message to the client to inform him that he logged in properly
SendClientMessage(playerid, 0xFFFFFFFF, "{00FF00}You logged in, welcome back");
// Exit the function to prevent executing the code below
return 1;
}
// Ask the player to enter his password to login (in case auto-login is disabled, or the player logs in with another IP, different from the one stored in the database)
ShowPlayerDialog(playerid, DialogLogin, DIALOG_STYLE_PASSWORD, "Welcome", "Please login by entering your password:", "Login", "Cancel");
}
else // The player isn't registered yet (he has no account), so let him enter a password to register his account
ShowPlayerDialog(playerid, DialogRegister, DIALOG_STYLE_PASSWORD, "Welcome", "Please register by entering your password:", "Register", "Cancel");
// always return 1 inside mysql callbacks to cleanup the cache and prevent memory leaks
return 1;
}
And to answer your second question:
Index is the same as the row-number, and field equals the column number, both start at 0.