Restarting & Saving player files
#1

Well, i'm looking for a command that will make sure that before it restarts the server, it will save every single player's file.. Currently I have the following command:

pawn Code:
COMMAND:restart(playerid, params[])
{
    new File[50];
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        format(File, sizeof(File), PFiles, pName(i));
        GetPlayerPos(i, PVar[i][pLastX], PVar[i][pLastY], PVar[i][pLastZ]);
        djSetInt        (File, "Kills",     PVar[i][pKills]);
        djSetInt        (File, "Deaths",    PVar[i][pDeaths]);
        djSetInt        (File, "Admin",     PVar[i][pAdmin]);
        djSetInt        (File, "Level",     PVar[i][pLevel]);

        djSetFloat      (File, "LastX",     PVar[i][pLastX]);
        djSetFloat      (File, "LastY",     PVar[i][pLastY]);
        djSetFloat      (File, "LastZ",     PVar[i][pLastZ]);
        printf("%s has been saved.", pName(i));
               //What's the function to make the server restart itself? I don't remember. OnGameModeExit(?)
    }
    return 1;
}
But the problem with this is, it just spams a print with a blank name 500 times, and doesn't actually save the file.
Reply
#2

If the server is restarting put it under
Code:
public OnGameModeExit()
it does the same thing -_-

and for the problem.... its something wrong with your loop, and IsPlayerConnected isnt there so it will go through all of the player slots

also, for a function to restart the server - SendRconCommand("gmx");
Reply
#3

Managed to fix it with a ConnectedPlayers & IsPlayerConnected check.

pawn Code:
COMMAND:restart(playerid, params[])
{
    new File[50];
    printf("Saving %d players...", ConnectedPlayers);
    for(new i = 0; i < ConnectedPlayers; i++)
    {
        if(IsPlayerConnected(i))
        {
            format(File, sizeof(File), PFiles, pName(i));
            GetPlayerPos(i, PVar[i][pLastX], PVar[i][pLastY], PVar[i][pLastZ]);
            djSetInt        (File, "Kills",     PVar[i][pKills]);
            djSetInt        (File, "Deaths",    PVar[i][pDeaths]);
            djSetInt        (File, "Admin",     PVar[i][pAdmin]);
            djSetInt        (File, "Level",     PVar[i][pLevel]);
            djSetInt        (File, "Money",     PVar[i][pMoney]);
            djSetInt        (File, "Skin",     PVar[i][pSkin]);

            djSetFloat      (File, "LastX",     PVar[i][pLastX]);
            djSetFloat      (File, "LastY",     PVar[i][pLastY]);
            djSetFloat      (File, "LastZ",     PVar[i][pLastZ]);
            printf("%s has been saved.", pName(i));
        }
    }
    GameModeExit();
    return 1;
}
Reply
#4

pawn Code:
SendRconCommand("gmx");
Reply
#5

Allright, awesome that you fixed it... and L3thal i already said that xD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)