[Help] - Login Dialog 'Leave' Button
#1

So, whenever i click the 'Leave' Button in Login Dialog. It kicks me, but when i came in on my server again, it makes my Data (Score, Money, etc.) = 0.

Help,
Thanks in Advance.

By the way,
This is the Tutorial i've used = https://sampforum.blast.hk/showthread.php?tid=352703.
Код:
if(!response) return Kick(playerid);
Reply
#2

Show your OnPlayerDisconnect? I think it's because you save the data without checking that the player is registered or not.
Reply
#3

Show the code... dialog login and onplayerdisconnect
Reply
#4

OnPlayerDisconnect Callback :-
pawn Код:
public OnPlayerDisconnect(playerid,reason)
{
    pInfo[playerid][pRStatus] = 0;
    pInfo[playerid][pRDonator] = 0;
    pInfo[playerid][pRCash] = 0;
    pInfo[playerid][pRScores] = 0;
    pInfo[playerid][pRKills] = 0;
    pInfo[playerid][pRDeaths] = 0;
   //... codes
    return 1;
}
pawn Код:
if(dialogid == dlogin) //If dialog id is a login dialog
    {//then
        if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
        if(response) //if they clicked the first button "Register"
        {//then
            new hashpass[129]; //Will create a new variable to hash his/her password
            WP_Hash(hashpass,sizeof(hashpass),inputtext); //Will hash inputted password
            if(!strcmp(hashpass, pInfo[playerid][Pass], false)) //If they have insert their correct password
            {//then
                INI_ParseFile(Path(playerid),"loadaccount_%s",.bExtra = true, .extra = playerid);//We will load his account's data from user's path
                SetPlayerScore(playerid,pInfo[playerid][Scores]);//We will get their score inside of his user's account and we will set it here
                GivePlayerMoney(playerid,pInfo[playerid][Money]);//As explained above
                SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");//Tell them that they've successfully logged in
            }
            else //If they've entered an incorrect password
            {//then
                ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account.\nIncorrect password!","Login","Quit");//We will tell to them that they've entered an incorrect password
                return 1;
            }
        }
    }
Reply
#5

Under OnPlayerDisconnect
Код:
new INI:file = INI_Open(Path(playerid)); 
        INI_SetTag(file,"Player's Data");
        INI_WriteInt(file,"Status",pInfo[playerid][pRStatus]); 
        INI_WriteInt(file,"Money",GetPlayerMoney(playerid));
        INI_WriteInt(file,"Scores",GetPlayerScore(playerid));
        INI_WriteInt(file,"Kills",pInfo[playerid][pRKills]);
        INI_WriteInt(file,"Deaths",pInfo[playerid][pRDeaths]);
        INI_WriteInt(file,"Donator",pInfo[playerid][pRDonator]);
        INI_Close(file);
Reply
#6

pInfo[playerid][pRStatus] = 0; ....
the lines like these^ should be at bottom of OnPlayerDisconnect not at top of it it should be after you save player's data and show the full OnPlayerDisconnect to us
Reply
#7

Quote:
Originally Posted by Rittik
Посмотреть сообщение
Under OnPlayerDisconnect
Код:
new INI:file = INI_Open(Path(playerid)); 
        INI_SetTag(file,"Player's Data");
        INI_WriteInt(file,"Status",pInfo[playerid][pRStatus]); 
        INI_WriteInt(file,"Money",GetPlayerMoney(playerid));
        INI_WriteInt(file,"Scores",GetPlayerScore(playerid));
        INI_WriteInt(file,"Kills",pInfo[playerid][pRKills]);
        INI_WriteInt(file,"Deaths",pInfo[playerid][pRDeaths]);
        INI_WriteInt(file,"Donator",pInfo[playerid][pRDonator]);
        INI_Close(file);
I have this one.

Quote:
Originally Posted by BroZeus
Посмотреть сообщение
pInfo[playerid][pRStatus] = 0; ....
the lines like these^ should be at bottom of OnPlayerDisconnect not at top of it it should be after you save player's data and show the full OnPlayerDisconnect to us
I've change the destination, i've put it under the OnPlayerConnect Callback.

Please Help.
Reply
#8

Set it so that it only saves the players details if the player is spawned
Reply
#9

Use a variable to set their login state, and check for their login state when they disconnect.

Example:

pawn Код:
new bool: logged[MAX_PLAYERS]; // var


if(dialogid == dlogin) //If dialog id is a login dialog
    {//then
        if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
        if(response) //if they clicked the first button "Register"
        {//then
            new hashpass[129]; //Will create a new variable to hash his/her password
            WP_Hash(hashpass,sizeof(hashpass),inputtext); //Will hash inputted password
            if(!strcmp(hashpass, pInfo[playerid][Pass], false)) //If they have insert their correct password
            {//then
                INI_ParseFile(Path(playerid),"loadaccount_%s",.bExtra = true, .extra = playerid);//We will load his account's data from user's path
                SetPlayerScore(playerid,pInfo[playerid][Scores]);//We will get their score inside of his user's account and we will set it here
                GivePlayerMoney(playerid,pInfo[playerid][Money]);//As explained above
                SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");//Tell them that they've successfully logged in
                logged[playerid] = true; // set it here
            }
            else //If they've entered an incorrect password
            {//then
                ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account.\nIncorrect password!","Login","Quit");//We will tell to them that they've entered an incorrect password
                return 1;
            }
        }
    }

public OnPlayerDisconnect(playerid,reason)
{
    if(logged[playerid])
    {
        pInfo[playerid][pRStatus] = 0;
        pInfo[playerid][pRDonator] = 0;
        pInfo[playerid][pRCash] = 0;
        pInfo[playerid][pRScores] = 0;
        pInfo[playerid][pRKills] = 0;
        pInfo[playerid][pRDeaths] = 0;
       //... codes
    }
    return 1;
}
Reply
#10

pawn Код:
// At top
new IsSpawned[MAX_PLAYERS];

// OnPlayerConnect
IsSpawned[playerid] = 0;

// OnPlayerSpawn
IsSpawned[playerid] = 1;


// OnPlayerDisconnect
if (IsSpawned[playerid] == 1)
{
        new INI:file = INI_Open(Path(playerid));
        INI_SetTag(file,"Player's Data");
        INI_WriteInt(file,"Status",pInfo[playerid][pRStatus]);
        INI_WriteInt(file,"Money",GetPlayerMoney(playerid));
        INI_WriteInt(file,"Scores",GetPlayerScore(playerid));
        INI_WriteInt(file,"Kills",pInfo[playerid][pRKills]);
        INI_WriteInt(file,"Deaths",pInfo[playerid][pRDeaths]);
        INI_WriteInt(file,"Donator",pInfo[playerid][pRDonator]);
        INI_Close(file);
        return 1;
}
This may help you, the player stats will only be saved if the player has spawned.

EDIT: The method posted above, using boolean variable logged is better.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)