Save stats problem
#1

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

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.
Reply
#3

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.
Reply
#4

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)
Reply
#5

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.
Reply
#6

Just as I said, use a timer ^^.
Reply
#7

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)
Reply
#8

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.
Reply
#9

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)" ?
Reply
#10

Joining the question, same problem!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)