Y_Ini Login script is mixing player stats.
#1

Hey, I used Kush's tutorial to make a simple login system, and for the most part it works OK. After spending ages trying to figure out how to stop files being created for players that haven't set a password I've come across a brand new issue. After I register the first account, any accounts made after take stats from the initial account. For example:

I create an account w/ username "Poo" and the stats look like so:
CASH: 100
ADMIN: 0
KILLS: 0
I then give "Poo" admin by editing the .ini:
CASH: 100
ADMIN: 4
KILLS: 0

I then make a new account called "Dog Poo" and the stats, instead of being default, will be like "Poo's":
CASH: 100
ADMIN: 4
KILLS: 0

I'm at a loss, any help would be appreciated!

PHP код:
public OnPlayerConnect(playerid)
{
    if(
fexist(UserPath(playerid)))
    {
        
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra true, .extra playerid);
          
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_PASSWORD,""COL_WHITE"Login",""COL_WHITE"Type your password below to login.","Login","Quit");
    }
    else
    {
         
ShowPlayerDialog(playeridDIALOG_REGISTERDIALOG_STYLE_PASSWORD,""COL_WHITE"Registering...",""COL_WHITE"Type your password below to register a new account.","Register","Quit");
    }
      
SendClientMessage(playerid,COLOR_WHITE,"Welcome to EverGM. Use {00FF00}/help {FFFFFF}for information on commands.");
    return 
1;
}
public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    switch( 
dialogid )
    {
        case 
DIALOG_REGISTER:
        {
            if (!
response) return Kick(playerid);
            if(
response)
            {
                if(!
strlen(inputtext)) return ShowPlayerDialog(playeridDIALOG_REGISTERDIALOG_STYLE_PASSWORD""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,"Admin Level",0);
                
INI_WriteInt(File,"Cash",0);
                
INI_WriteInt(File,"Score",0);
                
INI_WriteInt(File,"Deaths",0);
                
INI_Close(File);
                
SpawnPlayer(playerid);
                
GivePlayerMoney(playerid10000);
                
ShowPlayerDialog(playeridDIALOG_SUCCESS_1DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"Sign up successful! Relogging is recommended","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(playeridPlayerInfo[playerid][pCash]);
                    
SetPlayerScore(playeridPlayerInfo[playerid][pScore]);
                    
ShowPlayerDialog(playeridDIALOG_SUCCESS_2DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
                }
                else
                {
                    
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_PASSWORD,""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;

PHP код:
public OnPlayerDisconnect(playeridreason)
{
    if(
fexist(UserPath(playerid)))
    {
    new 
INI:File INI_Open(UserPath(playerid));
    
INI_SetTag(File,"data");
    
INI_WriteInt(File,"Admin Level",PlayerInfo[playerid][pAdmin]);
    
INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
     
INI_WriteInt(File,"Score",GetPlayerScore(playerid));
     
INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    
INI_Close(File);
    }
    return 
1;

Reply
#2

pawn Код:
public OnPlayerConnect(playerid)
{
    PlayerInfo[playerid][pAdmin] = 0;
    PlayerInfo[playerid][pDeaths] = 0;
    PlayerInfo[playerid][pScore] = 0;
    PlayerInfo[playerid][pCash] = 0;
    if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
          ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,""COL_WHITE"Login",""COL_WHITE"Type your password below to login.","Login","Quit");
    }
    else
    {
         ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,""COL_WHITE"Registering...",""COL_WHITE"Type your password below to register a new account.","Register","Quit");
    }
      SendClientMessage(playerid,COLOR_WHITE,"Welcome to EverGM. Use {00FF00}/help {FFFFFF}for information on commands.");
    return 1;
}
Reply
#3

Worked a charm Jelly. Thanks.

This can be locked I guess.
Reply
#4

It will be better to clear PlayerInfo when the player disconnects the server. Add them after INI_Close so it won't bug the next player who joins with the same ID.
Код:
public OnPlayerDisconnect(playerid, reason) 
{ 
    if(fexist(UserPath(playerid))) 
    { 
        new INI:File = INI_Open(UserPath(playerid)); 
        INI_SetTag(File,"data"); 
        INI_WriteInt(File,"Admin Level",PlayerInfo[playerid][pAdmin]); 
        INI_WriteInt(File,"Cash",GetPlayerMoney(playerid)); 
        INI_WriteInt(File,"Score",GetPlayerScore(playerid)); 
        INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]); 
        INI_Close(File);
        PlayerInfo[playerid][pAdmin] = 0;
        PlayerInfo[playerid][pDeaths] = 0;
        PlayerInfo[playerid][pScore] = 0;
        PlayerInfo[playerid][pCash] = 0;
    } 
    return 1; 
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)