04.03.2011, 09:12
Stats saving fine if you reconnect but if you restart server then you will start all over again, what may cause it?
// GameModeInit
SetTimer( "SaveStats", 120000, 1 ); // Saves all stats every 2 minutes.
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;
}
#include < a_npc >
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;
}
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
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