SA-MP Forums Archive
Restarting & Saving player files - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Restarting & Saving player files (/showthread.php?tid=238517)



Restarting & Saving player files - Skylar Paul - 11.03.2011

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.


Re: Restarting & Saving player files - airsoft - 11.03.2011

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");


Re: Restarting & Saving player files - Skylar Paul - 12.03.2011

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;
}



Re: Restarting & Saving player files - [L3th4l] - 12.03.2011

pawn Code:
SendRconCommand("gmx");



Re: Restarting & Saving player files - airsoft - 12.03.2011

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