Why This Won't Save The Players' Information?
#1

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;
}
Reply
#2

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

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

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;
}
Reply
#5

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

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

You will find the answer to that, here.
Reply
#8

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


Forum Jump:


Users browsing this thread: 1 Guest(s)