SA-MP Forums Archive
Why This Won't Save The Players' Information? - 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)
+--- Thread: Why This Won't Save The Players' Information? (/showthread.php?tid=519158)



Why This Won't Save The Players' Information? - Youssef214 - 13.06.2014

On These Codes,When Closing The Server,I Want To Save Everyone's Data,But It Doesn't Save In These Codes:

pawn Код:
public OnGameModeExit()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    if(fexist(UserPath(i)))
    {
    new INI:File = INI_Open(UserPath(i));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Cash",GetPlayerMoney(i));
    INI_WriteInt(File,"Admin",PlayerInfo[i][pAdmin]);
    INI_WriteInt(File,"Kills",PlayerInfo[i][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[i][pDeaths]);
    INI_WriteInt(File,"Score",LPinfo[i][Score]);
    INI_WriteInt(File,"Drugs",LPinfo[i][Drugs]);
    INI_WriteInt(File,"Adrenaline",LPinfo[i][Adre]);
    INI_WriteInt(File,"Registered",1);
    INI_WriteInt(File,"Logged",0);
    INI_WriteInt(File,"VIPLevel",Info[i][VIPLevel]);
    INI_WriteInt(File,"Banned",Info[i][Banned]);
    INI_WriteInt(File,"MissionsCompleted",Info[i][MissionsCompleted]);
    INI_WriteInt(File,"MissionsFailed",Info[i][MissionsFailed]);
    INI_WriteInt(File,"Robbed",Info[i][Robbed]);
    INI_WriteInt(File,"MaximumRobbed",Info[i][MaximumRobbed]);
    INI_WriteInt(File,"Muted",Info[i][Muted]);
    INI_WriteInt(File,"Jailed",Info[i][Jailed]);
    INI_WriteInt(File,"MuteWarnings",Info[i][MuteWarnings]);
    INI_WriteInt(File,"Warnings",Info[i][Warnings]);
    INI_WriteInt(File,"TimesKicked",Info[i][TimesKicked]);
    INI_WriteInt(File,"EventsWon",Info[i][EventsWon]);
    INI_WriteInt(File,"EventsLost",Info[i][EventsLost]);
    INI_Close(File);
    }
    return 1;
}



Re: Why This Won't Save The Players' Information? - rangerxxll - 13.06.2014

Instead of doing it ongamemodeinit, just do it under onplayerdisconnect. So when players disconnect, it will save their data no matter what.

pawn Код:
stock SaveUser(playerid)
{
    new INI:File = INI_Open(UserPath(i));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Cash",GetPlayerMoney(i));
    INI_WriteInt(File,"Admin",PlayerInfo[i][pAdmin]);
    INI_WriteInt(File,"Kills",PlayerInfo[i][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[i][pDeaths]);
    INI_WriteInt(File,"Score",LPinfo[i][Score]);
    INI_WriteInt(File,"Drugs",LPinfo[i][Drugs]);
    INI_WriteInt(File,"Adrenaline",LPinfo[i][Adre]);
    INI_WriteInt(File,"Registered",1);
    INI_WriteInt(File,"Logged",0);
    INI_WriteInt(File,"VIPLevel",Info[i][VIPLevel]);
    INI_WriteInt(File,"Banned",Info[i][Banned]);
    INI_WriteInt(File,"MissionsCompleted",Info[i][MissionsCompleted]);
    INI_WriteInt(File,"MissionsFailed",Info[i][MissionsFailed]);
    INI_WriteInt(File,"Robbed",Info[i][Robbed]);
    INI_WriteInt(File,"MaximumRobbed",Info[i][MaximumRobbed]);
    INI_WriteInt(File,"Muted",Info[i][Muted]);
    INI_WriteInt(File,"Jailed",Info[i][Jailed]);
    INI_WriteInt(File,"MuteWarnings",Info[i][MuteWarnings]);
    INI_WriteInt(File,"Warnings",Info[i][Warnings]);
    INI_WriteInt(File,"TimesKicked",Info[i][TimesKicked]);
    INI_WriteInt(File,"EventsWon",Info[i][EventsWon]);
    INI_WriteInt(File,"EventsLost",Info[i][EventsLost]);
    INI_Close(File);
    return 1;


//onplayerdisonnect
for(new i; i < MAX_PLAYERS; i++)
{
      SaveUser(i);
}
}
EDIT: I don't remember if onplayerdisconnect is called when a gamemode exits. Or if yini would even have a chance to write once you exit.


Re: Why This Won't Save The Players' Information? - Youssef214 - 13.06.2014

If Server Got Crashed,Or Closed For Some Reason,I want it to be saved On "OnGameModeExit",and i have already codes to save under "OnPlayerDisconnect"


Re: Why This Won't Save The Players' Information? - Laure - 13.06.2014

It will save it just under OnGameModeExit add SaveUser(i), use foreach if you have included for example
pawn Код:
public OnGameModeExit()
{
    foreach(Player, i)
    {
        SaveUser(i);
    }
    return 1;
}



Re: Why This Won't Save The Players' Information? - BroZeus - 13.06.2014

if Gamemode has exited that means no user is connected so how will you save the information if no user is connected


Re: Why This Won't Save The Players' Information? - AroseKhanNiazi - 13.06.2014

Quote:
Originally Posted by BroZeus
Посмотреть сообщение
if Gamemode has exited that means no user is connected so how will you save the information if no user is connected
he means when the server crash before server crashing there are players in the server so it will save the data for them youssef use the stock that is given above and the up method


Re: Why This Won't Save The Players' Information? - RajatPawar - 13.06.2014

You will find the answer to that, here.


Re: Why This Won't Save The Players' Information? - Youssef214 - 13.06.2014

Quote:
Originally Posted by Imperor
Посмотреть сообщение
It will save it just under OnGameModeExit add SaveUser(i), use foreach if you have included for example
pawn Код:
public OnGameModeExit()
{
    foreach(Player, i)
    {
        SaveUser(i);
    }
    return 1;
}
Thanks Imperor This Worked..