That's simple register login system tutorial, only saves password.... You need to make public for saveing everythink.
And to call it in OnPlayerDisconnect and in GameModeExitFunc.... |
for(new a; a < MAX_PLAYERS; a++) { new name[MAX_PLAYER_NAME], file[256]; GetPlayerName(a, name, sizeof(name)); format(file, sizeof(file), SERVER_USER_FILE, name); if(gPlayerLogged[a] == 1) { dini_IntSet(file, "Score", PlayerInfo[a][pScore]); dini_IntSet(file, "Money", PlayerInfo[a][pCash]); dini_IntSet(file, "Kicks", PlayerInfo[a][pKicks]); dini_IntSet(file, "Bans", PlayerInfo[a][pBans]); dini_IntSet(file, "Kills", PlayerInfo[a][pKills]); dini_IntSet(file, "Deaths", PlayerInfo[a][pDeaths]); dini_IntSet(file, "AdminLevel",PlayerInfo[a][pAdminLevel]); } gPlayerLogged[a] = 0; }
for(new a; a < MAX_PLAYERS; a++)
{
if(!IsPlayerConnected(a))continue;
new name[MAX_PLAYER_NAME], file[256];
GetPlayerName(a, name, sizeof(name));
format(file, sizeof(file), SERVER_USER_FILE, name);
if(gPlayerLogged[a] == 1)
{
dini_IntSet(file, "Score", PlayerInfo[a][pScore]);
dini_IntSet(file, "Money", PlayerInfo[a][pCash]);
dini_IntSet(file, "Kicks", PlayerInfo[a][pKicks]);
dini_IntSet(file, "Bans", PlayerInfo[a][pBans]);
dini_IntSet(file, "Kills", PlayerInfo[a][pKills]);
dini_IntSet(file, "Deaths", PlayerInfo[a][pDeaths]);
dini_IntSet(file, "AdminLevel",PlayerInfo[a][pAdminLevel]);
printf("Player (id: %d) %s: stats saved to filepath: %s.\n", a, name, file);
}
gPlayerLogged[a] = 0;
}
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;
}