Problem saving
#1

Hello,i've made my registration/login system from scratch,it works good but i've a problem.When a player disconnects or the server restart,the player loses ALL their stats. (So they arent saved).

Here is the variables to store:

pawn Код:
if (dialogid == 1) // Register
    {
    new name[MAX_PLAYER_NAME], file[128], string[128];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), SERVER_USER_FILE, name);
    if (!strlen(inputtext)) return
    ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "New Account", "Seems this is your first join on server,register an account now.", "Register", "");
    dini_Create(file);
    dini_IntSet(file, "Password", udb_hash(inputtext));
    dini_IntSet(file, "AdminLevel",PlayerInfo[playerid][pAdminLevel] = 0);
    dini_IntSet(file, "Money",PlayerInfo[playerid][pCash] = 500);
    dini_IntSet(file, "Score",PlayerInfo[playerid][pScore] = 0);
    dini_IntSet(file, "WantedLevel",PlayerInfo[playerid][pWantedLevel] = 0);
    dini_IntSet(file, "Deaths",PlayerInfo[playerid][pDeaths] = 0);
    format(string, 128, "You succesfully registered the nickname %s with password %s,you have been auto logged in.", name, inputtext);
    SendClientMessage(playerid, yellow, string);
    gPlayerLogged[playerid] = 1;
    }
Login:

pawn Код:
if (dialogid == 2) // Login
    {
    new name[MAX_PLAYER_NAME], file[128];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), SERVER_USER_FILE, name);
    if(!response) return Kick(playerid);
    if (!strlen(inputtext)) return ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Load Account", "Welcome back!", "Login", "");
    new tmp;
    tmp = dini_Int(file, "Password");
    if(udb_hash(inputtext) != tmp) {
    SendClientMessage(playerid, red, "Wrong password sir.");
    ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Load Account", "Welcome back!", "Login", "");
    }
    else
    {
    gPlayerLogged[playerid] = 1;
    PlayerInfo[playerid][pAdminLevel] = dini_Int(file, "AdminLevel");
    SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
    SetPlayerWantedLevel(playerid, PlayerInfo[playerid][pWantedLevel]);
    GivePlayerMoney(playerid, dini_Int(file, "Money")-GetPlayerMoney(playerid));
    SendClientMessage(playerid,red, "Successfully logged in!");
    }
    }
This is the stock i use in OnGameModeExit to save stats.

pawn Код:
stock SavePlayer(playerid)
{
    new file[128], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), SERVER_USER_FILE, name);
    if(gPlayerLogged[playerid] == 1)
    {
        dini_IntSet(file, "Score", PlayerInfo[playerid][pScore]);
        dini_IntSet(file, "Deaths", PlayerInfo[playerid][pDeaths]);
        dini_IntSet(file, "Money", PlayerInfo[playerid][pCash]);
        dini_IntSet(file, "AdminLevel",PlayerInfo[playerid][pAdminLevel]);
        dini_IntSet(file, "WantedLevel", PlayerInfo[playerid][pWantedLevel]);
    }
}
OnPlayerDisconnect:

pawn Код:
new file[128];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), SERVER_USER_FILE, name);
    if(gPlayerLogged[playerid] == 1)
    {
        dini_IntSet(file, "Score", PlayerInfo[playerid][pScore]);
        dini_IntSet(file, "Deaths", PlayerInfo[playerid][pDeaths]);
        dini_IntSet(file, "Money", PlayerInfo[playerid][pCash]);
        dini_IntSet(file, "AdminLevel",PlayerInfo[playerid][pAdminLevel]);
        dini_IntSet(file, "WantedLevel", PlayerInfo[playerid][pWantedLevel]);
    }
    gPlayerLogged[playerid] = 0;
Thanks.
Reply
#2

try on player disconnect
or make a stock
which saves the Files

and put it on OnPlayerDisconnect
and also when server restarts
Reply
#3

Quote:
Originally Posted by RicaNiel
Посмотреть сообщение
try on player disconnect
or make a stock
which saves the Files

and put it on OnPlayerDisconnect
and also when server restarts
...is what i done and said in the topic...
Reply
#4

Are you able to manually open a user's .ini? If so, what does it look like? I suggest switching to y_ini. There are tons less errors to be made.
Reply
#5

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
Are you able to manually open a user's .ini? If so, what does it look like? I suggest switching to y_ini. There are tons less errors to be made.
Yes i can.It looks like this:

pawn Код:
Password=70123830
AdminLevel=0
Money=0
Score=0
WantedLevel=0
Deaths=0
Reply
#6

Show us your SERVER_USER_FILE define.
Reply
#7

pawn Код:
#define SERVER_USER_FILE "Accs/%s.ini"
Reply
#8

Use a custom command, like so: (I do so in a dialog)

pawn Код:
case 3: { //Restart the Server
                   
                        for( new gPlayers; gPlayers < MAX_PLAYERS; gPlayers++ )
                        {
                            if(accLogged[gPlayers] == true)
                            {
                                new
                                    INI:accFile = INI_Open(find_accPath(gPlayers));
                                   
                                GetPlayerPos(gPlayers, accInfo[gPlayers][PosX], accInfo[gPlayers][PosY], accInfo[gPlayers][PosZ]);
                                GetPlayerFacingAngle(gPlayers, accInfo[gPlayers][PosAng]);
                               
                                GetPlayerHealth(gPlayers, accInfo[gPlayers][Health]);
                                GetPlayerArmour(gPlayers, accInfo[gPlayers][Armour]);
                                   
                                INI_SetTag(accFile, "data");
                               
                                INI_WriteInt(accFile,   "Authorization",accInfo[gPlayers][Authorization]);
                                INI_WriteString(accFile, "PreviousName", accInfo[gPlayers][PreviousName]);
                               
                                INI_WriteInt(accFile,   "Funds",        accInfo[gPlayers][Funds]);
                                INI_WriteInt(accFile,   "BankFunds",    accInfo[gPlayers][BankFunds]);
                               
                                INI_WriteInt(accFile,   "Kills",        accInfo[gPlayers][Kills]);
                                INI_WriteInt(accFile,   "Deaths",       accInfo[gPlayers][Deaths]);
                               
                                INI_WriteFloat(accFile, "Health",       accInfo[playerid][Health]);
                                INI_WriteFloat(accFile, "Armour",       accInfo[playerid][Armour]);
                               
                                INI_WriteFloat(accFile, "X_Pos",        accInfo[gPlayers][PosX]);
                                INI_WriteFloat(accFile, "Y_Pos",        accInfo[gPlayers][PosY]);
                                INI_WriteFloat(accFile, "Z_Pos",        accInfo[gPlayers][PosZ]);
                                INI_WriteFloat(accFile, "Ang_Pos",      accInfo[gPlayers][PosAng]);
                               
                                INI_WriteInt(accFile,   "SkinModel",    accInfo[gPlayers][SkinModel]);
                               
                                INI_WriteInt(accFile,   "EventsWon",    accInfo[gPlayers][EventsWon]);
                               
                                INI_WriteInt(accFile,   "FactionID",    accInfo[gPlayers][FactionID]);
                                INI_WriteInt(accFile,   "FactionRank",  accInfo[gPlayers][FactionRank]);
                               
                                INI_WriteInt(accFile, "WepSlot1",      accInfo[playerid][w_Slot1]);
                                INI_WriteInt(accFile, "WepSlot1Ammo",      accInfo[playerid][w_Slot1A]);
                                INI_WriteInt(accFile, "WepSlot2",      accInfo[playerid][w_Slot2]);
                                INI_WriteInt(accFile, "WepSlot2Ammo",      accInfo[playerid][w_Slot2A]);
                                INI_WriteInt(accFile, "WepSlot3",      accInfo[playerid][w_Slot3]);
                                INI_WriteInt(accFile, "WepSlot3Ammo",      accInfo[playerid][w_Slot3A]);
                                INI_WriteInt(accFile, "WepSlot4",      accInfo[playerid][w_Slot4]);
                                INI_WriteInt(accFile, "WepSlot4Ammo",      accInfo[playerid][w_Slot4A]);
                                INI_WriteInt(accFile, "WepSlot5",      accInfo[playerid][w_Slot5]);
                                INI_WriteInt(accFile, "WepSlot5Ammo",      accInfo[playerid][w_Slot5A]);
                                INI_WriteInt(accFile, "WepSlot6",      accInfo[playerid][w_Slot6]);
                                INI_WriteInt(accFile, "WepSlot6Ammo",      accInfo[playerid][w_Slot6A]);
                                INI_WriteInt(accFile, "WepSlot7",      accInfo[playerid][w_Slot7]);
                                INI_WriteInt(accFile, "WepSlot7Ammo",      accInfo[playerid][w_Slot7A]);
                                INI_WriteInt(accFile, "WepSlot9",      accInfo[playerid][w_Slot9]);
                                INI_WriteInt(accFile, "WepSlot9Ammo",      accInfo[playerid][w_Slot9A]);
                               
                                INI_Close(accFile);
                                accLogged[gPlayers] = false;
                               
                                if(gPlayers != INVALID_PLAYER_ID)
                                    printf("[SAVE] Player ID %d saved.", gPlayers);
                            }
                        }
                        SendClientMessageToAll(-1, ""#CYAN"» "#WHITE"Everything has been saved. Server restarting...");
                        SendRconCommand("gmx");
                    }
It works perfectly for me.
Reply
#9

Emh.
I dont need a command because i've a stock.
I use dini and not Y_INI.
Reply
#10

bump.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)