Here you go:
pawn Код:
new SaveTimer[MAX_PLAYERS],name[MAX_PLAYER_NAME], file[32];//This MUST not be inside a call back, just put it at the top where the others are (It's a global variable)
SaveTimer[playerid] = SetTimerEx("Save",1800000,true,"i",playerid);//Put this where you say "You've be logged in" or something like that, it must go where the player logs in.
forward Save(playerid);//Put this at the bottom of the script (anywhere once it's outside another callback)
public Save(playerid)
{
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(file), SERVER_USER_FILE, name);
if(gPlayerLogged[playerid] == 1)
{
dini_IntSet(file, "Score", PlayerInfo[playerid][pScore]);
dini_IntSet(file, "Money", PlayerInfo[playerid][pCash]);
dini_IntSet(file, "Kicks", PlayerInfo[playerid][pKicks]);
dini_IntSet(file, "Bans", PlayerInfo[playerid][pBans]);
dini_IntSet(file, "Kills", PlayerInfo[playerid][pKills]);
dini_IntSet(file, "Deaths", PlayerInfo[playerid][pDeaths]);
dini_IntSet(file, "AdminLevel",PlayerInfo[playerid][pAdminLevel]);
}
}
stock SaveEx(playerid)
{
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(file), SERVER_USER_FILE, name);
if(gPlayerLogged[playerid] == 1)
{
dini_IntSet(file, "Score", PlayerInfo[playerid][pScore]);
dini_IntSet(file, "Money", PlayerInfo[playerid][pCash]);
dini_IntSet(file, "Kicks", PlayerInfo[playerid][pKicks]);
dini_IntSet(file, "Bans", PlayerInfo[playerid][pBans]);
dini_IntSet(file, "Kills", PlayerInfo[playerid][pKills]);
dini_IntSet(file, "Deaths", PlayerInfo[playerid][pDeaths]);
dini_IntSet(file, "AdminLevel",PlayerInfo[playerid][pAdminLevel]);
}
}
public OnPlayerDisconnect(playerid, reason)
{
KillTimer(SaveTimer[playerid]);
SaveEx(playerid);
return 1;
}
And I'd advise you not to create a variable everytime you need it, just make one Global variable, you'd see I did that for you. The timer will save stats every 30 minutes (You don't need to save it like every second) and the SaveEx function will get called once the player disconnects, so if they only played like 10 minutes (that means the Save Function was not called) then it will execute the SaveEx function when they disconnect.