Player stats not saving upon disconnect [y_ini]
#1

Hi. I'm having trouble saving player stats with y_ini, when a user connects it writes the following information in their scriptfile fine, IP, Password, Cash etc. Although when a player disconnects everything in the file is turned to '0' which in turn doesn't allow them to access their account.

I've spent about 2 hours searching forums/****** and trial and error with different methods, and I haven't had any luck. I'm really all out of ideas, and I'm hoping someone can help me out with this.

pawn Код:
SaveAccountStats(playerid)
{
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"IP",PlayerInfo[playerid][pIP]);
    INI_WriteInt(File,"Banned",PlayerInfo[playerid][pBanned]);
    INI_WriteInt(File,"PermaBanned",PlayerInfo[playerid][pPermaBanned]);
    INI_WriteInt(File,"Cash",PlayerInfo[playerid][pCash]);
    INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"VIP",PlayerInfo[playerid][pVIP]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_WriteInt(File,"Faction",PlayerInfo[playerid][pFaction]);
    INI_WriteInt(File,"FacRank",PlayerInfo[playerid][pFacRank]);
    INI_WriteInt(File,"FacDiv",PlayerInfo[playerid][pFacDiv]);
    INI_WriteInt(File,"Leader",PlayerInfo[playerid][pLeader]);
    INI_WriteInt(File,"Job",PlayerInfo[playerid][pJob]);
    INI_WriteInt(File,"JobVIP",PlayerInfo[playerid][pJobVIP]);
    INI_WriteInt(File,"OPrison",PlayerInfo[playerid][pOPrison]);
    INI_WriteInt(File,"IPrison",PlayerInfo[playerid][pIPrison]);
    INI_WriteInt(File,"Age",PlayerInfo[playerid][pAge]);
    INI_WriteInt(File,"Sex",PlayerInfo[playerid][pSex]);
    INI_WriteInt(File,"WantedLevel",PlayerInfo[playerid][pWantedLevel]);
    INI_WriteInt(File,"Pot",PlayerInfo[playerid][pPot]);
    INI_WriteInt(File,"Crack",PlayerInfo[playerid][pCrack]);
    INI_WriteInt(File,"Helper",PlayerInfo[playerid][pPass]);
    INI_WriteInt(File,"CarLic",PlayerInfo[playerid][pCash]);
    INI_WriteInt(File,"FlyLic",PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"BoatLic",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Badged",PlayerInfo[playerid][pVIP]);
    INI_Close(File);
    return 1;
}
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch( dialogid )
    {
        case DIALOG_REGISTER:
        {
            if (!response) return Kick(playerid);
            if(response)
            {
                new IP[16];
                GetPlayerIp(playerid, IP, 16);
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                INI_WriteString(File,"IP",IP);
                INI_WriteInt(File,"Banned",0);
                INI_WriteInt(File,"PermaBanned",0);
                INI_WriteInt(File,"Password",udb_hash(inputtext));
                INI_WriteInt(File,"Cash",20000);
                INI_WriteInt(File,"Admin",0);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"VIP",0);
                INI_WriteInt(File,"Deaths",0);
                INI_WriteInt(File,"Faction",0);
                INI_WriteInt(File,"FacRank",0);
                INI_WriteInt(File,"FacDiv",0);
                INI_WriteInt(File,"Leader",0);
                INI_WriteInt(File,"Job",0);
                INI_WriteInt(File,"JobVIP",0);
                INI_WriteInt(File,"OPrison",0);
                INI_WriteInt(File,"IPrison",0);
                INI_WriteInt(File,"Age",0);
                INI_WriteInt(File,"Sex",0);
                INI_WriteInt(File,"WantedLevel",0);
                INI_WriteInt(File,"Pot",0);
                INI_WriteInt(File,"Crack",0);
                INI_WriteInt(File,"Helper",0);
                INI_WriteInt(File,"CarLic",0);
                INI_WriteInt(File,"FlyLic",0);
                INI_WriteInt(File,"BoatLic",0);
                INI_WriteInt(File,"Badged",0);
                INI_Close(File);
                ShowPlayerDialog(playerid, DIALOG_LOGIN_AGE, DIALOG_STYLE_INPUT, "Enter Age", "Enter your characters age.\nAge must be between 18-80.", "Enter", "Cancel");
            }
        }
pawn Код:
enum pInfo
{
    pIP,
    pBanned,
    pPermaBanned,
    pPass,
    pCash,
    pAdmin,
    pKills,
    pVIP,
    pDeaths,
    pFaction,
    pFacRank,
    pFacDiv,
    pLeader,
    pJob,
    pJobVIP,
    pOPrison,
    pIPrison,
    pAge,
    pSex,
    pWantedLevel,
    pPot,
    pCrack,
    pHelper,
    pCarLic,
    pFlyLic,
    pBoatLic,
    pBadged,
}
new PlayerInfo[MAX_PLAYERS][pInfo];

forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_Int("IP",PlayerInfo[playerid][pIP]);
    INI_Int("Banned",PlayerInfo[playerid][pBanned]);
    INI_Int("PermaBanned",PlayerInfo[playerid][pPermaBanned]);
    INI_Int("Password",PlayerInfo[playerid][pPass]);
    INI_Int("Cash",PlayerInfo[playerid][pCash]);
    INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
    INI_Int("Kills",PlayerInfo[playerid][pKills]);
    INI_Int("VIP",PlayerInfo[playerid][pVIP]);
    INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
    INI_Int("Faction",PlayerInfo[playerid][pFaction]);
    INI_Int("FacRank",PlayerInfo[playerid][pFacRank]);
    INI_Int("FacDiv",PlayerInfo[playerid][pFacDiv]);
    INI_Int("Leader",PlayerInfo[playerid][pLeader]);
    INI_Int("Job",PlayerInfo[playerid][pJob]);
    INI_Int("JobVIP",PlayerInfo[playerid][pJobVIP]);
    INI_Int("OPrison",PlayerInfo[playerid][pOPrison]);
    INI_Int("IPrison",PlayerInfo[playerid][pIPrison]);
    INI_Int("Age",PlayerInfo[playerid][pAge]);
    INI_Int("Sex",PlayerInfo[playerid][pSex]);
    INI_Int("WantedLevel",PlayerInfo[playerid][pWantedLevel]);
    INI_Int("Pot",PlayerInfo[playerid][pPot]);
    INI_Int("Crack",PlayerInfo[playerid][pCrack]);
    INI_Int("Helper",PlayerInfo[playerid][pPass]);
    INI_Int("CarLic",PlayerInfo[playerid][pCash]);
    INI_Int("FlyLic",PlayerInfo[playerid][pAdmin]);
    INI_Int("BoatLic",PlayerInfo[playerid][pKills]);
    INI_Int("Badged",PlayerInfo[playerid][pVIP]);
    return 1;
}
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    SaveAccountStats(playerid);
    return 1;
}
If you need anymore code or further information, feel free to request so in your comment. Thanks in advance for any assistance!

This is the userfile while they're still connect after registering. As you can see the information had saved fine.

Quote:

[data]
IP = 5.49.73.172
Banned = 0
PermaBanned = 0
Password = 266732406
Cash = 20000
Admin = 0
Kills = 0
VIP = 0
Deaths = 0
Faction = 0
FacRank = 0
FacDiv = 0
Leader = 0
Job = 0
JobVIP = 0
OPrison = 0
IPrison = 0
Age = 0
Sex = 0
WantedLevel = 0
Pot = 0
Crack = 0
Helper = 0
CarLic = 0
FlyLic = 0
BoatLic = 0
Badged = 0

Now after that player has disconnected the file looks like this. The hashed password has saved, although when the player goes to log in again their password will not work, and they are unable to login.

Quote:

[data]
IP = 0
Banned = 0
PermaBanned = 0
Password = 266732406
Cash = 0
Admin = 0
Kills = 0
VIP = 0
Deaths = 0
Faction = 0
FacRank = 0
FacDiv = 0
Leader = 0
Job = 0
JobVIP = 0
OPrison = 0
IPrison = 0
Age = 45
Sex = 0
WantedLevel = 0
Pot = 0
Crack = 0
Helper = 0
CarLic = 0
FlyLic = 0
BoatLic = 0
Badged = 0

Reply
#2

This is happening because you have that onlplayerdisconnect public at filterscript as well as in gamemode. I had the same exactly problem and what I did was to replace in filterscript, the onplayerdisconnect with on playerupdate.
Reply
#3

Quote:
Originally Posted by HurtLocker
Посмотреть сообщение
This is happening because you have that onlplayerdisconnect public at filterscript as well as in gamemode. I had the same exactly problem and what I did was to replace in filterscript, the onplayerdisconnect with on playerupdate.
Thanks for your quick response.

In response to your answer, I am not using any filterscripts. This is my server configuration file. As you can see the only extra resources I am using is the streamer and sscanf plugin.

Quote:

echo Executing Server Config...
lanmode 0
rcon_password united001
maxplayers 50
port 7777
hostname SA-MP 0.3 Server
gamemode0 SAMP 1
filterscripts
plugins streamer sscanf
announce 0
query 1
chatlogging 0
weburl www.sa-mp.com
onfoot_rate 40
incar_rate 40
weapon_rate 40
stream_distance 300.0
stream_rate 1000
maxnpc 0
logtimeformat [%H:%M:%S]

Reply
#4

Anyway, replace onplayerdisconnect with onplayerupdate. This will consume more cpu but the true player's stats will be viewable at any minute.
Reply
#5

Quote:
Originally Posted by HurtLocker
Посмотреть сообщение
Anyway, replace onplayerdisconnect with onplayerupdate. This will consume more cpu but the true player's stats will be viewable at any minute.
That still gives me the login error, I register my account and log out, then re-connect and attempt to login and it gives me incorrect password.

File is printed as.
Quote:

[data]
IP = 0
Banned = 0
PermaBanned = 0
Password = 0
Cash = 0
Admin = 0
Kills = 0
VIP = 0
Deaths = 0
Faction = 0
FacRank = 0
FacDiv = 0
Leader = 0
Job = 0
JobVIP = 0
OPrison = 0
IPrison = 0
Age = 43
Sex = 0
WantedLevel = 0
Pot = 0
Crack = 0
Helper = 0
CarLic = 0
FlyLic = 0
BoatLic = 0
Badged = 0

Reply
#6

Of course you won't include password to be updated!

EDIT: Nor things like age, sex, these are stable forever, don't need to be under onplayerupdate.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)