SA-MP Forums Archive
Save stats problem - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Save stats problem (/showthread.php?tid=234699)



Save stats problem - tuuker - 04.03.2011

Stats saving fine if you reconnect but if you restart server then you will start all over again, what may cause it?


Re: Save stats problem - Mean - 04.03.2011

Because OnPlayerDisconnect can't be called when player time outs. You need to make a timer to save all players stats.
pawn Код:
// GameModeInit
SetTimer( "SaveStats", 120000, 1 ); // Saves all stats every 2 minutes.
Later in script
pawn Код:
forward SaveStats( );
public SaveStats( )
{
    for( new playerid = 0; playerid < MAX_PLAYERS; playerid++ ) if( IsPlayerConnected( playerid ) && !IsPlayerNPC( playerid ) )
    {
        // Your save code, from OnPlayerDisconnect goes here
    }
    return 1;
}
Also, make sure you include a_npc,
pawn Код:
#include < a_npc >
You need it because the loop I made works like foreach, it excludes NPCs and skips non-connected players.


Re: Save stats problem - tuuker - 04.03.2011

Still after server restart player will start all over again even if i disconnect first from server and then restart server even then it will start all over again.


Re: Save stats problem - iggy1 - 04.03.2011

Show the code where you save the stats, can't help w/o code. It may be better to save players stats individually to prevent lag spikes. (SetTimerEx)


Re: Save stats problem - tuuker - 04.03.2011

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new name[MAX_PLAYER_NAME], file[128], Float:x, Float:y, Float:z;
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), SERVER_USER_FILE, name);
    if(gPlayerLogged[playerid] == 1)
    {
        dini_IntSet(file, "Score", GetPlayerScore(playerid));
        dini_IntSet(file, "Money", GetPlayerMoney(playerid));
        dini_IntSet(file, "AdminLevel",PlayerInfo[playerid][pAdminLevel]);
        dini_IntSet(file, "WantedLevel",GetPlayerWantedLevel(playerid));
        dini_IntSet(file, "Skin", GetPlayerSkin(playerid));
        dini_IntSet(file, "Cop", PlayerInfo[playerid][pCop]);
        dini_IntSet(file, "Civilian", PlayerInfo[playerid][pCivilian]);
        dini_IntSet(file, "FirstTime", PlayerInfo[playerid][pFirstTime] = 1);
        GetPlayerPos(playerid, x, y, z);
        dini_FloatSet(file, "posX", x);
        dini_FloatSet(file, "posY", y);
        dini_FloatSet(file, "posZ", z);
    }
    gPlayerLogged[playerid] = 0;
    return 1;
}
Here it will save stats if player will be disconnected, as i said it sould work fine because if i reconnect then stats are fine but if i restart server then everything is back to 0 even if i disconnect before restarting server.


Re: Save stats problem - Mean - 04.03.2011

Just as I said, use a timer ^^.


Re: Save stats problem - iggy1 - 04.03.2011

So inside the file, everything is set to zero, if you restart the server? or just the variables? Are you sure your reading the right file when you load a players stats? I have a feeling the problem might be where you load the stats to variables. (obviously not sure, just a hunch) Because if you restart the server all vars will reset, but if you just disconnect the vars will remain the same. (unless you reset them)


Re: Save stats problem - tuuker - 04.03.2011

Heres my .ini before restart
pawn Код:
Password=151323286
AdminLevel=0
Money=0
Score=0
WantedLevel=0
Skin=21
Cop=-1
Civilian=1
FirstTime=1
posX=2080.544921
posY=1672.667236
posZ=11.508196
Heres after restart
pawn Код:
Password=151323286
AdminLevel=0
Money=0
Score=0
WantedLevel=0
Skin=0
Cop=-1
Civilian=1
FirstTime=1
posX=0.000000
posY=0.000000
posZ=0.000000
I used auto save timer too but still same problem. It saves data in files fine but just if you restart server and relog then it sets everything back to 0.


Re: Save stats problem - BMUK - 04.03.2011

Quote:
Originally Posted by Mean
Посмотреть сообщение
Because OnPlayerDisconnect can't be called when player time outs.
I only just thought: If it can't be called, how can it say "Mean(2) Has Left The Server (Timeout)" ?


Re: Save stats problem - [MWR]Blood - 04.03.2011

Joining the question, same problem!