case DIALOG_LOGIN:
{
if(!response) return Kick(playerid);
if(strlen(inputtext) < 3 || strlen(inputtext) > 30) {
ShowLoginDialog(playerid, "Password length must be at least 3 characters and below 30 characters.");
return true;
}
new query[128];
mysql_format(sqlConnection, query, sizeof(query), "SELECT id FROM players WHERE Name = '%e' AND Password = sha1('%e') LIMIT 1", GetName(playerid), inputtext);
mysql_pquery(sqlConnection, query, "SQL_OnAccountLogin", "i", playerid);
}
Server:SQL_OnAccountLogin(playerid)
{
if(cache_num_rows() == 0){
ShowLoginDialog(playerid, "Incorrect Password.");
return true;
}
SendClientMessage(playerid, COLOR_WHITE, "You have successfully logged in.");
//debug
new string[128];
format(string, sizeof(string), "* Your SQL id is: %i", PlayerData[playerid][pSQLID]);
SendClientMessage(playerid, COLOR_WHITE, string);
//debug end
LoadPlayerData(playerid);
return true;
}
Server: SQL_OnLoadAccount(playerid)
{
LoggedIn[playerid] = true;
PlayerData[playerid][pSQLID] = cache_get_field_content_int(0, "id", sqlConnection);
PlayerData[playerid][pAdminLevel] = cache_get_field_content_int(0, "AdminLevel", sqlConnection);
PlayerData[playerid][pMoney] = cache_get_field_content_int(0, "Money", sqlConnection);
PlayerData[playerid][pLevel] = cache_get_field_content_int(0, "Level", sqlConnection);
PlayerData[playerid][pRespect] = cache_get_field_content_int(0, "Respect", sqlConnection);
PlayerData[playerid][pLastPos][0] = cache_get_field_content_float(0, "LastX", sqlConnection);
PlayerData[playerid][pLastPos][1] = cache_get_field_content_float(0, "LastY", sqlConnection);
PlayerData[playerid][pLastPos][2] = cache_get_field_content_float(0, "LastZ", sqlConnection);
PlayerData[playerid][pLastPos][3] = cache_get_field_content_float(0, "LastRot", sqlConnection);
PlayerData[playerid][pLastInt] = cache_get_field_content_int(0, "Interior", sqlConnection);
PlayerData[playerid][pLastWorld] = cache_get_field_content_int(0, "World", sqlConnection);
SetPlayerScore(playerid, PlayerData[playerid][pLevel]);
ResetPlayerMoney(playerid); GivePlayerMoney(playerid, PlayerData[playerid][pMoney]);
SetPlayerSpawn(playerid);
return true;
}
Server:LoadPlayerData(playerid)
{
new query[255];
mysql_format(sqlConnection, query, sizeof(query), "SELECT * FROM players WHERE id = %i LIMIT 1", PlayerData[playerid][pSQLID]);
mysql_pquery(sqlConnection, query, "SQL_OnLoadAccount", "i", playerid);
return true;
}
mysql_pquery(sqlConnection, query, "SQL_OnAccountLogin", "is", playerid,password);
Server:SQL_OnAccountLogin(playerid,password)
//and ...
"SELECT * FROM players WHERE id = %i LIMIT 1"
cache_delete();
ALTER TABLE table
ADD Pos FLOAT;
//and
Float:pLastPos;
Server:SetPlayerSpawn(playerid)
{
SetSpawnInfo(playerid, 0, DEFAULT_SKIN, PlayerData[playerid][pLastPos][0], PlayerData[playerid][pLastPos][1], PlayerData[playerid][pLastPos][2], PlayerData[playerid][pLastPos][3], 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
SetPlayerVirtualWorld(playerid, PlayerData[playerid][pLastWorld]);
SetPlayerInterior(playerid, PlayerData[playerid][pLastInt]);
return true;
}
enum PLAYER_DATA
{
pSQLID,
pAdminLevel,
pMoney,
pLevel,
pRespect,
Float:pLastPos[4],
pLastInt,
pLastWorld
}
Something to help you pinpoint this error may be to print the output to the console when the script loads it. Then maybe you could see what it's loading, and what it's saving by also doing the same on the save function.
Use printf to push it out to the log with all the values you're wanting to check. |
Float:pLastPosx,
Float:pLastPosy,
Float:pLastPosz,
Float:pLastPosr,
When your debug message gets sent ("Your SQL id is ...") then nothing has been assigned yet so obviously that will show 0. Then you call LoadPlayerData and since we just established that the the id is 0 you also query for id 0. Control then transfers to SQL_OnLoadAccount where you try to fetch a row that doesn't exist.
You need to actually fetch the id before sending the message and before calling LoadPlayerData. |