Server Restart = Lose Stats
#1

Heey,

I have made an account system in my gamemode but when i restart server you will lose all u stats.
The stats will not lose when you quiting the server.
After server restart you have login dialog to login so no problem with that.
I need to add the onplayerdisconnect code where it saves to ongamemodeexit?
I will give Rep

Admigo
Reply
#2

Try make a simple command that save the all-player data then send gmx command

HairStyle

EDIT:

like:

LOOP all player {
save for player
}
gmx

EDIT2:

or yea just make a loop all player in OnGameModeExit for connected player that save .. but i dont know how efficent is that way
Reply
#3

Show your variables from the OnPlayerDisconnect(playerid, reason) - What saving system are using ? Also, show you enum values too.
Reply
#4

Like:
pawn Код:
for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
                new INI:File = INI_Open(UserPath(i));
                INI_SetTag(File,"data");
                INI_WriteInt(File,"Cash",GetPlayerMoney(i));
            INI_WriteInt(File,"Score",GetPlayerScore(i));
                INI_WriteInt(File,"Admin",PlayerInfo[i][pAdmin]);
                INI_WriteInt(File,"Kills",PlayerInfo[i][pKills]);
                INI_WriteInt(File,"Deaths",PlayerInfo[i][pDeaths]);
                INI_Close(File);
            }
       }
?
This will work?
Reply
#5

Код:
CMD:gmx(playerid)
{
    SaveStats(playerid);
    SetTimer(#Restart, 2 * 1000, 0);
}

forward Restart();
public Restart()
{
     SendRconCommand(#gmx);
}
Код:
stock SaveStats(playerid)
{
 //put what u have on player disconnect here and they u have it player stats saved
    return 1;
}
eg of my savestats
/*
stock SaveStats(playerid)
{
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Years", GetPlayerScore(playerid));
    INI_WriteInt(File,"Bank",PlayerInfo[playerid][pBank]);
    INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"House1",PlayerInfo[playerid][pHouse1]);
    INI_WriteInt(File,"House2",PlayerInfo[playerid][pHouse2]);
    INI_WriteInt(File,"House3",PlayerInfo[playerid][pHouse3]);
    INI_WriteInt(File,"Helper",PlayerInfo[playerid][pHelper]);
    INI_WriteInt(File,"NMute",PlayerInfo[playerid][pNMute]);
    INI_WriteInt(File,"VHouse",PlayerInfo[playerid][pVHouse]);
    INI_WriteInt(File,"Bizey",PlayerInfo[playerid][pBiz]);
    INI_WriteInt(File,"VBizkey",PlayerInfo[playerid][pVBiz]);
    INI_WriteInt(File,"Viplvl",PlayerInfo[playerid][pVIP]);
    INI_WriteInt(File,"pHouse",PlayerInfo[playerid][pHouse]);
    INI_WriteInt(File,"Cigar",PlayerInfo[playerid][pCigar]);
    INI_WriteInt(File,"HPhone",PlayerInfo[playerid][pHasCellphone]);
    INI_WriteInt(File,"Phone",PlayerInfo[playerid][pCellphone]);
    INI_WriteInt(File,"PhoneBook",PlayerInfo[playerid][pPhonebook]);
    INI_WriteInt(File,"Dice",PlayerInfo[playerid][pDice]);
    INI_WriteInt(File,"Sprunk",PlayerInfo[playerid][pSprunk]);
    INI_WriteInt(File,"Rope",PlayerInfo[playerid][pRope]);
    INI_WriteInt(File,"BFold",PlayerInfo[playerid][pBlindfold]);
    INI_WriteInt(File,"Spray",PlayerInfo[playerid][pSpray]);
    INI_WriteInt(File,"walkietalkie",PlayerInfo[playerid][pWT]);
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Ban",PlayerInfo[playerid][pBanned]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_Close(File);
    return 1;
}
*/
Reply
#6

Yes just try
Reply
#7

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Score",GetPlayerScore(playerid));
    INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_Close(File);
    return 1;
}
Reply
#8

OnPlayerDisconnect callback is not called when you close / restart your server. Simple as that.

What you can do, is use a timer to save every players account every 5 minutes or so.
Reply
#9

Quote:
Originally Posted by trapstar2020
Посмотреть сообщение
Код:
CMD:gmx(playerid)
{
    SaveStats(playerid);
    SetTimer(#Restart, 2 * 1000, 0);
}

forward Restart();
public Restart()
{
     SendRconCommand(#gmx);
}
Код:
stock SaveStats(playerid)
{
 //put what u have on player disconnect here and they u have it player stats saved
    return 1;
}
eg of my savestats
/*
stock SaveStats(playerid)
{
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Years", GetPlayerScore(playerid));
    INI_WriteInt(File,"Bank",PlayerInfo[playerid][pBank]);
    INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"House1",PlayerInfo[playerid][pHouse1]);
    INI_WriteInt(File,"House2",PlayerInfo[playerid][pHouse2]);
    INI_WriteInt(File,"House3",PlayerInfo[playerid][pHouse3]);
    INI_WriteInt(File,"Helper",PlayerInfo[playerid][pHelper]);
    INI_WriteInt(File,"NMute",PlayerInfo[playerid][pNMute]);
    INI_WriteInt(File,"VHouse",PlayerInfo[playerid][pVHouse]);
    INI_WriteInt(File,"Bizey",PlayerInfo[playerid][pBiz]);
    INI_WriteInt(File,"VBizkey",PlayerInfo[playerid][pVBiz]);
    INI_WriteInt(File,"Viplvl",PlayerInfo[playerid][pVIP]);
    INI_WriteInt(File,"pHouse",PlayerInfo[playerid][pHouse]);
    INI_WriteInt(File,"Cigar",PlayerInfo[playerid][pCigar]);
    INI_WriteInt(File,"HPhone",PlayerInfo[playerid][pHasCellphone]);
    INI_WriteInt(File,"Phone",PlayerInfo[playerid][pCellphone]);
    INI_WriteInt(File,"PhoneBook",PlayerInfo[playerid][pPhonebook]);
    INI_WriteInt(File,"Dice",PlayerInfo[playerid][pDice]);
    INI_WriteInt(File,"Sprunk",PlayerInfo[playerid][pSprunk]);
    INI_WriteInt(File,"Rope",PlayerInfo[playerid][pRope]);
    INI_WriteInt(File,"BFold",PlayerInfo[playerid][pBlindfold]);
    INI_WriteInt(File,"Spray",PlayerInfo[playerid][pSpray]);
    INI_WriteInt(File,"walkietalkie",PlayerInfo[playerid][pWT]);
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Ban",PlayerInfo[playerid][pBanned]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_Close(File);
    return 1;
}
*/
I can use SaveStats(i); ?
Because i am using a timer without playerid to restart the server.
Reply
#10

The easiest way is to loop through all players and kick them from the server.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)