Can't Save data player after shutdown
#1

hello
i have problem.
save data player (money, admin level, password)
But after server shutdown, data player not saved.
please help.
-----------------
sorry, my bad english.
Reply
#2

we can't help until you show your codes related to it.
Reply
#3

Код:
#include <a_samp>
#include <YSI\y_ini>
#include <zcmd>
#include <sscanf2>
#include <foreach>
native WP_Hash(buffer[], len, const str[]);
#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
#define DIALOG_SUCCESS_1 3
#define DIALOG_SUCCESS_2 4
#define PATH "/Admin/Users/%s.ini"
enum pInfo
{
    pPass[129],
    pCash,
    pAdmin,
    pKills,
    pDeaths
}
new PlayerInfo[MAX_PLAYERS][pInfo];
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_String("Password",PlayerInfo[playerid][pPass], 129);
    INI_Int("Cash",PlayerInfo[playerid][pCash]);
    INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
    INI_Int("Kills",PlayerInfo[playerid][pKills]);
    INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
    return 1;
}
stock UserPath(playerid)
{
    new string[128],playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),PATH,playername);
    return string;
}
public OnPlayerConnect(playerid)
{
    if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_data", .bExtra = true, .extra = playerid);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,"Login","Please Type Password.","Login","Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,"Register","Please Type Password For Register.","Register","Quit");
    }
    return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch( dialogid )
    {
        case DIALOG_REGISTER:
        {
            if (!response) return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register","Password Is Wrong. Please Type Password.","Register","Quit");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"PlayerData");
                new HashPass[129];
                WP_Hash(HashPass, sizeof(HashPass), inputtext);
                INI_WriteString(File, "Password", HashPass);
                INI_WriteInt(File,"Cash",0);
                INI_WriteInt(File,"Admin",-1);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                INI_Close(File);

                SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
                ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,"Creating Account","Check Site : www.sitename.com","ok","");
            }
        }

        case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                new HashPass[129];
                WP_Hash(HashPass, sizeof(HashPass), inputtext);
                if(strcmp(HashPass, PlayerInfo[playerid][pPass]) == 0)
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_data", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,"Register End","You have successfully entered a severe account. Check Site: www.sitename.com","ok","");
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,"Login","wrong password.","Login","Quit");
                }
                return 1;
            }
        }
    }
    return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"PlayerData");
    INI_WriteInt(File,"Cash",GetPlayerMoney(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;
}
public OnPlayerDeath(playerid, killerid, reason)
{
    PlayerInfo[killerid][pKills]++;
    PlayerInfo[playerid][pDeaths]++;
    return 1;
}
Reply
#4

Are you hosting it right now or not? Make a folder named Admin inside scriptfiles and make a folder again named Users inside scriptfiles.
Reply
#5

i made folders.
I'm not hosting.
but not save.
Reply
#6

Change
pawn Код:
INI_ParseFile(UserPath(playerid), "LoadUser_data", .bExtra = true, .extra = playerid);
to
pawn Код:
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
Reply
#7

LoadUser_data is work.
LoadUser_%s is not work.
--------------------------
I found the problem.
player connected = save data
player disconnected = save data
--------------------------
If a player is on the server.
When the server will restart.
Everything goes back to the previous state.
--------------------------
(Data)Should be saved every second.
Thanks for help and tips
--------------------------
sorry. my bad english.
Reply
#8

Quote:
Originally Posted by Miladajir
Посмотреть сообщение
LoadUser_data is work.
LoadUser_%s is not work.
--------------------------
I found the problem.
player connected = save data
player disconnected = save data
--------------------------
If a player is on the server.
When the server will restart.
Everything goes back to the previous state.
--------------------------
(Data)Should be saved every second.
Thanks for help and tips
--------------------------
sorry. my bad english.
If you're going to save data every second, it will lag your server. You better set some timer for about 10 minutes? and simply make a function to save the player data in OnGameModeExit so that player data would be saved. As far as I know, OnPlayerDisconnect is also called when the server restarts.
Reply
#9

thanks.
How do I do it?
Reply
#10

Use SetTimer and loop through all the players and save their data.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)