Player position not saved on crash/timeout
#1

Hey guys, whenever a player disconnects the server, their position is always saved and it works when a player quits, or is kicked/banned. However if the player times out it doesn't save properly and then spawns them at blueberry.

If you guys have any ideas they would greatly be appreciated. Here is my load, save and ondisconnect callbacks.

PHP код:

public SaveAccountStats(playerid)
{
    new 
query1[1024],query2[1024],query3[1024],Float:pos[4],cash
    
cash=GetPlayerMoney(playerid);
    if(
LoggedIn[playerid] == 1)
    {
        
GetPlayerPos(playeridpos[0], pos[1], pos[2]); 
        
GetPlayerFacingAngle(playeridpos[3]); 
        
mysql_format(ServerMySQL,query1,sizeof(query1),"UPDATE `Users` SET  Name ='%s',pIP='%s',pCash = %d,pAdmin=%d, pXPos = %f, pYPos = %f, pZPos = %f, pAPos = %f,Interior=%d WHERE Name = '%s'",GetName(playerid),playerip[playerid],cash,PlayerInfo[playerid][pAdmin], pos[0], pos[1], pos[2], pos[3],PlayerInfo[playerid][Interior],GetName(playerid));
        
mysql_tquery(ServerMySQLquery1""""); 
        
mysql_format(ServerMySQL,query2,sizeof(query2),"UPDATE Users SET pSkin=%d,Support=%d,VIP=%d, VIPJoinDate='%s', VIPExpireDate='%s', muted=%d, pUCAdmin=%d, pBanned=%d WHERE Name='%s'",PlayerInfo[playerid][pSkin],PlayerInfo[playerid][Support],PlayerInfo[playerid][VIP], PlayerInfo[playerid][VIPJoinDate],PlayerInfo[playerid][VIPExpireDate], PlayerInfo[playerid][muted], PlayerInfo[playerid][pUCAdmin], PlayerInfo[playerid][pBanned],GetName(playerid));
        
mysql_tquery(ServerMySQL,query2,"","");
        
mysql_format(ServerMySQL,query3,sizeof(query3),"UPDATE Users SET pBannedBy='%s', pReason='%s',Vehicle=%d WHERE Name='%s'"PlayerInfo[playerid][pBannedBy], PlayerInfo[playerid][pReason],PlayerInfo[playerid][Vehicle],GetName(playerid));
        
mysql_tquery(ServerMySQL,query3,"","");
    }
    return 
1;
}
public 
OnAccountLoad(playerid

    
PlayerInfo[playerid][pAdmin] = cache_get_field_content_int(0"pAdmin"); 
    
cache_get_field_content(0,"pIP",PlayerInfo[playerid][pIP]);
    
PlayerInfo[playerid][pCash] = cache_get_field_content_int(0,"pCash");
    
PlayerInfo[playerid][pAdmin] = cache_get_field_content_int(0,"pAdmin");
    
PlayerInfo[playerid][pXPos] = cache_get_field_content_float(0,"pXPos");
    
PlayerInfo[playerid][pYPos] = cache_get_field_content_float(0,"pYPos");
    
PlayerInfo[playerid][pZPos] = cache_get_field_content_float(0,"pZPos");
    
PlayerInfo[playerid][pAPos] = cache_get_field_content_float(0,"pAPos");
    
PlayerInfo[playerid][Interior] = cache_get_field_content_int(0,"Interior");
    
PlayerInfo[playerid][pSkin] = cache_get_field_content_int(0,"pSkin");
     
PlayerInfo[playerid][Support]= cache_get_field_content_int(0,"Support");
    
PlayerInfo[playerid][pUCAdmin] = cache_get_field_content_int(0,"pUCAdmin");
    
PlayerInfo[playerid][TotalTime] = cache_get_field_content_int(0,"TotalTime");
    
PlayerInfo[playerid][ConnectTime]= cache_get_field_content_int(0,"ConnectTime");
    
PlayerInfo[playerid][VIP]= cache_get_field_content_int(0,"VIP");
    
cache_get_field_content(0,"VIPJoinDate",PlayerInfo[playerid][VIPJoinDate]);
    
cache_get_field_content(0,"VIPExpireDate",PlayerInfo[playerid][VIPExpireDate]);
    
PlayerInfo[playerid][muted]= cache_get_field_content_int(0,"muted");
    
PlayerInfo[playerid][hours] = cache_get_field_content_int(0,"hours");
    
PlayerInfo[playerid][minutes] = cache_get_field_content_int(0,"minutes");
    
PlayerInfo[playerid][seconds] = cache_get_field_content_int(0,"seconds");
    
PlayerInfo[playerid][pDriverLicense] = cache_get_field_content_int(0,"pDriverLicense");
    
PlayerInfo[playerid][WantedLvl] = cache_get_field_content_int(0,"WantedLvl");
    
PlayerInfo[playerid][pInJail] = cache_get_field_content_int(0,"pInJail");
    
PlayerInfo[playerid][pInJailTime] = cache_get_field_content_int(0,"pInJailTime");
    
PlayerInfo[playerid][pBanned] = cache_get_field_content_int(0,"pBanned");
    
PlayerInfo[playerid][Vehicle] = cache_get_field_content_int(0,"Vehicle");
    
cache_get_field_content(0,"pBannedBy",    PlayerInfo[playerid][pBannedBy]);
     
cache_get_field_content(0,"pReason",PlayerInfo[playerid][pReason]);
    
cache_get_field_content(0,"BannedIP",PlayerInfo[playerid][BannedIP]);
    
PlayerInfo[playerid][OrgID] = cache_get_field_content_int(0,"OrgID");
    
PlayerInfo[playerid][OrgTier] = cache_get_field_content_int(0,"OrgTier");
    
cache_get_field_content(0,"OrgRank",PlayerInfo[playerid][OrgRank]);
    
GivePlayerMoney(playeridPlayerInfo[playerid][pCash]); 
    if(
PlayerInfo[playerid][pBanned] == 1)
    {
        
SendClientMessage(playerid, -1"You have been banned from this server.");
        
Kick(playerid);
    }
    
LoggedIn[playerid] = 1//Changes the value of our variable "Logged" to 1("true").
    
SendClientMessage(playerid, -1"You have successfully logged in."); 
    if(
PlayerInfo[playerid][pAdmin] != 0)
    {
        new 
msgID[128], msg[128];
        if(
PlayerInfo[playerid][pUCAdmin] == 0)
        {
            
format(msgID32"Administration Level - %d"PlayerInfo[playerid][pAdmin]);
            
SendClientMessage(playeridCOLOR_ADMINmsgID);
            if(
PlayerInfo[playerid][pAdmin] >= 6)
            {
                
format(msg,sizeof(msg), "* %s (ID%d) has logged in as Administrator Level 5."GetName(playerid), playerid);
            }
            else
            {
                
format(msgsizeof(msg), "* %s (ID%d) has logged in as Administrator Level %d."GetName(playerid), playeridPlayerInfo[playerid][pAdmin]);
            }
            for(new 
0MAX_PLAYERSi++)
            {
                if(!
IsPlayerConnected(i)) continue;
                if(
PlayerInfo[i][pAdmin] != && != playeridSendClientMessage(i,COLOR_ADMIN,msg);
            }
        }
        else
        {
            
format(msgID64"Administration Level - %d (Undercover)"PlayerInfo[playerid][pAdmin]);
            
SendClientMessage(playeridCOLOR_ADMINmsgID);
        }
    }
    if(
PlayerInfo[playerid][muted] == 1)
    {
        new 
string[128];
        
format(string,sizeof(string), "[Anti - Spam] %s has joined the server and has been auto-muted!"GetName(playerid));
        
SendClientMessageToAll(0xFFFFFFstring);
        
SetTimerEx("AutoUnMute",AutoUnmuteTime*60000,false,"i",playerid);
    }
    if(
PlayerInfo[playerid][VIP] == 1)
    {
        
SendClientMessage(playeridCOLOR_VIP2"Vip Level - Donator");
        if(
PlayerInfo[playerid][VIP] == 1)
        {
            new 
yearmonthday;
            
getdate(yearmonthday);
            new 
spyear[32], spmonth[32], spday[32];
            
strmid(spyearPlayerInfo[playerid][VIPExpireDate], 61032);
            
strmid(spmonthPlayerInfo[playerid][VIPExpireDate], 0232);
            
strmid(spdayPlayerInfo[playerid][VIPExpireDate], 3532);
            new 
pyear strval(spyear);
            new 
pmonth strval(spmonth);
            new 
pday strval(spday);
            if(
pyear == 2016 && pmonth == 1)
            {
                
format(PlayerInfo[playerid][VIPExpireDate], 32"%02d/%02d/%d"pmonthpdaypyear +1);
            }
            if(
year pyear && month == pmonth && day pday)
            {
                
SendClientMessage(playeridCOLOR_ORANGE"Sorry, your VIP has expired. Please donate to get it restored.");
                
RemoveVIP(playerid);
            }
            if(
month == pmonth && day pday)
            {
                
SendClientMessage(playeridCOLOR_ORANGE"Sorry, your VIP has expired. Please donate to get it restored.");
                
RemoveVIP(playerid);
            }
        }
    }
    return 
true
}
public 
OnPlayerDisconnect(playeridreason)
{
    new 
temp[pInfo];
    
PlayerTextDrawDestroy(playeridTxtZones[playerid]);
    
PlayerTextDrawDestroy(playeridSpeedoText[playerid]);
    if(
HasTrash[playerid]) Trash_ResetPlayer(playerid);
    if(
PlayerInfo[playerid][Vehicle] > 0DestroyVehicle(pvehicle[playerid][0]);
    
Cash[playerid]=0;
    
Help[playerid] = 0;
       if( 
LoggedIn[playerid] == 1)
    {
        
SaveAccountStats(playerid);
        
LoggedIn[playerid]=0;
    }
       if(
reason == 0)
    {
         
SendConnectionMessage(playerid2);
    }
    else if(
reason == 1)
    {
        
SendConnectionMessage(playerid3);
    }
    else
    {
        
SendConnectionMessage(playerid0);
    }
    if(
PlayerInfo[playerid][Vehicle] > -1)
    {
        
DestroyVehicle(pvehicle[playerid][0]);
    }
    
PlayerInfo[playerid]=temp;
    if(
IsBeingSpeced[playerid] == || IsBeingSpeced[playerid] == 2)//If the player being spectated, disconnects, then turn off the spec mode for the spectator.
    
{
        foreach(
Player,i)
        {
            if(
spectatorid[i] == playerid)
            {
                
TogglePlayerSpectating(i,false);// This justifies what's above, if it's not off then you'll be either spectating your connect screen, or somewhere in blueberry (I don't know why)
            
}
        }
    }
    
SaveAccountStats(playerid);
    
sellon[playerid] = 1;   //Enable the player to sell cars
    
if(checkon[playerid] == 1//If they are online and the checkpoint is active
    
{
        
DisablePlayerCheckpoint(playerid); //Remove the checkpoint
    
}     //Remove the checkpoint
    
checkon[playerid] = 0//Set the checkpoint variable to 0
    
return 1;

If you need anymore information let me know.

Cheers Tass.
Reply
#2

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new temp[pInfo];
    PlayerTextDrawDestroy(playerid, TxtZones[playerid]);
    PlayerTextDrawDestroy(playerid, SpeedoText[playerid]);
    if(HasTrash[playerid]) Trash_ResetPlayer(playerid);
    if(PlayerInfo[playerid][Vehicle] > 0) DestroyVehicle(pvehicle[playerid][0]);
    Cash[playerid]=0;
    Help[playerid] = 0;
       if( LoggedIn[playerid] == 1)
    {
        SaveAccountStats(playerid);
        LoggedIn[playerid]=0; // try to remove it
    }
LoggedIn[playerid]=0; // try to remove it
Reply
#3

or try this
pawn Код:
if(LoggedIn[playerid] == 1) SaveAccountStats(playerid);
    static string[64];
    switch(reason)
    {
        case 0: format(string,sizeof string,"» "cred"%s has left the server. (Timed out)",GetPName(playerid));
        case 1: format(string,sizeof string,"» "cred"%s has left the server. (Leaving)",GetPName(playerid));
        case 2: format(string,sizeof string,"» "cred"%s has left the server. (Kicked/Banned)",GetPName(playerid));
    }
Reply
#4

I removed the loggedin part, but with the last part, I already have messages showing the disconnections.
Reply
#5

try replacing
PHP код:
        mysql_format(ServerMySQL,query1,sizeof(query1),"UPDATE `Users` SET  Name ='%s',pIP='%s',pCash = %d,pAdmin=%d, pXPos = %f, pYPos = %f, pZPos = %f, pAPos = %f,Interior=%d WHERE Name = '%s'",GetName(playerid),playerip[playerid],cash,PlayerInfo[playerid][pAdmin], pos[0], pos[1], pos[2], pos[3],PlayerInfo[playerid][Interior],GetName(playerid)); 
with:
Код:
        mysql_format(ServerMySQL,query1,sizeof(query1),"UPDATE `Users` SET  `Name` = '%s', `pIP` = '%s', `pCash` = '%d', `pAdmin` = '%d', `pXPos` = '%f', `pYPos` = '%f', `pZPos` = '%f', `pAPos` = '%f', `Interior` = '%d' WHERE `Name` = '%s'",GetName(playerid),playerip[playerid],cash,PlayerInfo[playerid][pAdmin], pos[0], pos[1], pos[2], pos[3],PlayerInfo[playerid][Interior],GetName(playerid));
Reply
#6

Unless you get the player's position in a timer and store it to global array, you can't retrieve them when the client crashes/timeouts.

Another option is what I did in the example script: using the last saved position: https://github.com/pBlueG/SA-MP-MySQ....pwn#L343-L349
Reply
#7

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Unless you get the player's position in a timer and store it to global array, you can't retrieve them when the client crashes/timeouts.

Another option is what I did in the example script: using the last saved position: https://github.com/pBlueG/SA-MP-MySQ....pwn#L343-L349
Thanks for your input on that. I noticed that in your query you also have like
PHP код:
mysql_format(ServerMySQL,query1,sizeof(query1),"UPDATE `Users` SET  `Name` = '%s', `pIP` = '%s', `pCash` = '%d', `pAdmin` = '%d', `pXPos` = '%f', `pYPos` = '%f', `pZPos` = '%f', `pAPos` = '%f', `Interior` = '%d' WHERE `Name` = '%s'",GetName(playerid),playerip[playerid],cash,PlayerInfo[playerid][pAdmin], pos[0], pos[1], pos[2], pos[3],PlayerInfo[playerid][Interior],GetName(playerid)); 
And in mine I have
PHP код:
        mysql_format(ServerMySQL,query1,sizeof(query1),"UPDATE `Users` SET  Name ='%s', pIP='%s',pCash = %d, pAdmin=%d, pXPos = %f, pYPos = %f, pZPos = %f, pAPos = %f,Interior=%d WHERE Name = '%s'",GetName(playerid),playerip[playerid],cash,PlayerInfo[playerid][pAdmin], pos[0], pos[1], pos[2], pos[3],PlayerInfo[playerid][Interior],GetName(playerid)); 
However when I change my query to the above, none of my Admin levels get saved or anything.
Reply
#8

Are you referring to the grave accent character around the name of table/columns? That is only necessary if the name of the said column/table is the same as a MySQL keyword.

Another thing you should avoid doing is to save literally everything. Few of them to point out:
- The IP does not change, update it once when the player logins.
- The name does not change unless you use do it via scripting which should save directly right then.
- Admin does not change. Same as the above.

Since you have got a unique ID for each player, take advantage of it and use it as index in WHERE clause instead of the name.

About the data not being updated, check your mysql logs.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)