SA-MP Forums Archive
Y_INI Saving System - 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)
+--- Thread: Y_INI Saving System (/showthread.php?tid=503370)



Y_INI Saving System - AnonScripter - 29.03.2014

Код:
default code of the Y_INI
https://sampforum.blast.hk/showthread.php?tid=273088

When the player clicks on "Quit" button before registering, it will kick the player from the server and his name will be saved in the user files with no password, and when the player join back again with the same name, it will show him the login dialog instead of register dialog, WHY?

Any solution for this problem? Y_INI Has so much bugs


Re: Y_INI Saving System - EiresJason - 29.03.2014

This isn't a bug with Y_INI, it all depends on how you script it.

The reason this particular issue occurs is because when a player is Kicked, it still calls OnPlayerDisconnect.

If you look on the tutorial, the server will create a file for that user if he disconnects.

So when you click Quit and are kicked, the OnPlayerDisconnect callback is called and therefor the file is created.

A temporary way to fix this is this:
pawn Код:
new Spawned[MAX_PLAYERS];
public OnPlayerSpawn(playerid)
{
    Spawned[playerid] = 1;

    return 1;
}
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    if(Spawned[playerid] != 1) return 1;

    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    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;
}



Re: Y_INI Saving System - AnonScripter - 29.03.2014

This will create a user file too. i want not to create user file if he pressed Quit button (Register Dialog)


Re: Y_INI Saving System - BroZeus - 29.03.2014

no that will not have u tried that script which Jason told
It will work


Re: Y_INI Saving System - AnonScripter - 29.03.2014

Fixed!! Thanks you gave me the idea <3


Re: Y_INI Saving System - EiresJason - 29.03.2014

EDIT: Ops, never refreshed xD

Do you spawn before you get the dialogues?

If you do, you can fix it by doing this..
pawn Код:
//add a pRegister variable to the enum..
enum pInfo
{
    pPass,
    pCash,
    pAdmin,
    pKills,
    pDeaths,
    pRegistered
}
new PlayerInfo[MAX_PLAYERS][pInfo];

forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    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("Deaths",PlayerInfo[playerid][pDeaths]);
    INI_Int("Registered",PlayerInfo[playerid][pRegistered]);
    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_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_WriteInt(File,"Password",udb_hash(inputtext));
                INI_WriteInt(File,"Cash",0);
                INI_WriteInt(File,"Admin",0);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                INI_WriteInt(File,"Registered",1);
                INI_Close(File);
               
                PlayerInfo[playerid][pRegistered] = 1;
                SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
                SpawnPlayer(playerid);
                ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"Great! Your Y_INI system works perfectly. Relog to save your stats!","Ok","");
            }
        }

        case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Quit");
                }
                return 1;
            }
        }
    }
    return 1;
}


public OnPlayerDisconnect(playerid, reason)
{
    if(PlayerInfo[playerid][pRegistered] == 1)
    {
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    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;
}



Re: Y_INI Saving System - AnonScripter - 29.03.2014

Fixed! Thank you, i didn't notice the "OnPlayerDisconnect" i forgot it thank you


Re: Y_INI Saving System - EiresJason - 29.03.2014

No problem


Re: Y_INI Saving System - AnonScripter - 29.03.2014

+Rep