Doesn't load/save user's data
#1

Everytime I connect to my localhost server, the password saves but the rest doesn't. Here's the info of the server.

PHP код:
public OnPlayerConnect(playerid)
{
    
GangZoneShowForPlayer(playeridBlackRadar0x000000FF);
    new 
name[MAX_PLAYER_NAME];
    
GetPlayerName(playerid,name,sizeof(name));
    if(
fexist(Path(playerid)))
    {
        
INI_ParseFile(Path(playerid),"loadaccount_%s", .bExtra true, .extra playerid);
        
ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login","Welcome back to "COL_LRED""SERVER_NAME" "SERVER_VERSION""COL_WHITE". This account is registered. \nInsert your password to login to your account","Login","Quit");
    }
    else 
    {
        
ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_PASSWORD,"Register","Welcome to "COL_LRED""SERVER_NAME" "SERVER_VERSION""COL_WHITE"! This account is not registered.\nEnter your own password to create a new account.","Register","Quit");
        return 
1;
      }
    return 
1;

PHP код:
public OnPlayerDisconnect(playeridreason)
{
    if(
INI_Exists(Path(playerid)))
    {
        
SaveStats(playerid);
        return 
1;
    }
    for(new 
i=0i<MAX_PLAYER_ATTACHED_OBJECTSi++)
     {
        if(
IsPlayerAttachedObjectSlotUsed(playeridi)) RemovePlayerAttachedObject(playeridi);
    }
    return 
1;

PHP код:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    switch(
dialogid)
    {
        case 
DIALOG_REGISTER:
        {
            if(!
response)
            {
                
SendClientMessage(playeridCOLOR_LIGHTRED"You need to be registered to play at "COL_LRED""SERVER_NAME" "SERVER_VERSION"");
                 
Kick(playerid);
            }
            else if(
response)
            {
                if(!
strlen(inputtext))
                {
                       
ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_PASSWORD,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.\nPlease enter the password!","Register","Quit");
                    return 
1;
                }
                new 
hashpass[129];
                
WP_Hash(hashpass,sizeof(hashpass),inputtext);
                new 
INI:File INI_Open(Path(playerid));
                
INI_SetTag(File,"Player's Data");
                
INI_WriteString(File,"Password",hashpass);
                
INI_WriteInt(File,"Cash",0);
                
INI_WriteInt(File,"AdminLevel",0);
                
INI_WriteInt(File,"ZombiesKilled",0);
                
INI_WriteInt(File,"HumansKilled",0);
                
INI_WriteInt(File,"HumanDeaths",0);
                
INI_WriteInt(File,"ZombieDeaths",0);
                
INI_WriteInt(File,"Premium",0);
                
INI_WriteFloat(File,"Pos_X",0.0);
                
INI_WriteFloat(File,"Pos_Y",0.0);
                
INI_WriteFloat(File,"Pos_Z",0.0);
                
INI_WriteInt(File,"PM",0);
                
INI_WriteInt(File,"Hours",0);
                
INI_WriteInt(File,"Seconds",0);
                
INI_WriteInt(File,"Minutes",0);
                
INI_WriteInt(File,"Muted",0);
                
INI_WriteInt(File,"Warnings",0);
                
INI_WriteBool(File,"Logged",true);
                
INI_WriteInt(File,"NewbieMute",0);
                
INI_WriteInt(File,"TotalNMute",0);
                
INI_WriteInt(File,"Banned",0);
                
INI_WriteInt(File,"Vote",0);
                
INI_WriteInt(File,"VotedPlayer",0);
                
INI_WriteInt(File,"Mask",0);
                
INI_WriteInt(File,"MaskOn",0);
                
INI_WriteInt(File,"Cookies",0);
                
INI_Close(File);
                
GivePlayerMoney(playerid10000);
                
SaveStats(playerid);
                
SendClientMessage(playerid,-1,"You have been successfully registered");
                
SpawnPlayer(playerid);
                return 
1;
            }
        }
        case 
DIALOG_LOGIN:
        {
            if(!
response)
            {
                
SendClientMessage(playeridCOLOR_LIGHTRED"You need to be registered to play at "COL_LRED""SERVER_NAME" "SERVER_VERSION"");
                 
Kick(playerid);
            }
              else if(
response)
            {
                new 
hashpass[129];
                
WP_Hash(hashpass,sizeof(hashpass),inputtext);
                if(!
strcmp(hashpasspInfo[playerid][Password], false))
                {
                    
INI_ParseFile(Path(playerid),"loadaccount_%s",.bExtra true, .extra playerid);
                    
SetPlayerScore(playerid,pInfo[playerid][ZombiesKilled]);
                    
GivePlayerMoney(playerid,pInfo[playerid][zMoney]);
                    
SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");
                    
pInfo[playerid][pLogged] = true;
                    
SaveStats(playerid);
                }
                else
                {
                    
ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Login","Welcome back to "COL_LRED""SERVER_NAME" "SERVER_VERSION""COL_WHITE". 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;
                }
            }
        }
    }

PHP код:
forward loadaccount_user(playeridname[], value[]);
public 
loadaccount_user(playeridname[], value[])
{
    
INI_String("Password"pInfo[playerid][Password],129);
    
INI_Int("zMoney",pInfo[playerid][zMoney]);
    
INI_Int("AdminLevel",pInfo[playerid][pAdminLevel]);
    
INI_Int("ZombiesKilled",pInfo[playerid][ZombiesKilled]);
    
INI_Int("HumansKilled",pInfo[playerid][HumansKilled]);
    
INI_Int("HumanDeaths",pInfo[playerid][HumanDeaths]);
    
INI_Int("ZombieDeaths",pInfo[playerid][ZombieDeaths]);
    
INI_Int("Premium",pInfo[playerid][pPremium]);
    
INI_Float("Pos_X",pInfo[playerid][pX]);
    
INI_Float("Pos_Y",pInfo[playerid][pY]);
    
INI_Float("Pos_Z",pInfo[playerid][pZ]);
    
INI_Int("PM",pInfo[playerid][pPM]);
    
INI_Int("Hours",pInfo[playerid][pHour]);
    
INI_Int("Seconds",pInfo[playerid][pSec]);
    
INI_Int("Minutes",pInfo[playerid][pMin]);
    
INI_Int("Muted",pInfo[playerid][Muted]);
    
INI_Int("Warnings",pInfo[playerid][Warnings]);
    
INI_Bool("Logged",pInfo[playerid][pLogged]);
    
INI_Int("NewbieMute",pInfo[playerid][pNMute]);
    
INI_Int("TotalNMute",pInfo[playerid][pNMuteTotal]);
    
INI_Int("Banned",pInfo[playerid][pBanned]);
    
INI_Int("Vote",pInfo[playerid][pVote]);
    
INI_Int("VotedPlayer",pInfo[playerid][VotedPlayer]);
    
INI_Int("Mask",pInfo[playerid][pMask]);
    
INI_Int("MaskOn",pInfo[playerid][pMaskOn]);
    
INI_Int("Cookies",pInfo[playerid][pCookies]);
    
INI_Int("Jailed",pInfo[playerid][pJailed]);
    
INI_Int("JailTime",pInfo[playerid][pJailTime]);
    
INI_Int("FirstPS",pInfo[playerid][FirstPS]);
    return 
1;
}
forward SaveStats(playerid);
public 
SaveStats(playerid)
{
    
GetPlayerPosplayeridpInfo[playerid][pX], pInfo[playerid][pY], pInfo[playerid][pZ] );
    
pInfo[playerid][zMoney] = GetPlayerMoney(playerid);
    new 
INI:File INI_Open(Path(playerid));
    
INI_SetTag(File,"PlayerData");
    
INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    
INI_WriteInt(File,"AdminLevel",pInfo[playerid][pAdminLevel]);
    
INI_WriteInt(File,"ZombiesKilled",pInfo[playerid][ZombiesKilled]);
    
INI_WriteInt(File,"HumansKilled",pInfo[playerid][HumansKilled]);
    
INI_WriteInt(File,"HumanDeaths",pInfo[playerid][HumanDeaths]);
    
INI_WriteInt(File,"ZombieDeaths",pInfo[playerid][ZombieDeaths]);
    
INI_WriteInt(File,"Premium",pInfo[playerid][pPremium]);
    
INI_WriteFloat(File,"Pos_X",pInfo[playerid][pX]);
    
INI_WriteFloat(File,"Pos_Y",pInfo[playerid][pY]);
    
INI_WriteFloat(File,"Pos_Z",pInfo[playerid][pZ]);
    
INI_WriteInt(File,"PM",pInfo[playerid][pPM]);
    
INI_WriteInt(File,"Hours",pInfo[playerid][pHour]);
    
INI_WriteInt(File,"Seconds",pInfo[playerid][pSec]);
    
INI_WriteInt(File,"Minutes",pInfo[playerid][pMin]);
    
INI_WriteInt(File,"Muted",pInfo[playerid][Muted]);
    
INI_WriteInt(File,"Warnings",pInfo[playerid][Warnings]);
    
INI_WriteBool(File,"Logged",true);
    
INI_WriteInt(File,"NewbieMute",pInfo[playerid][pNMute]);
    
INI_WriteInt(File,"TotalNMute",pInfo[playerid][pNMuteTotal]);
    
INI_WriteInt(File,"Banned",pInfo[playerid][pBanned]);
    
INI_WriteInt(File,"Vote",pInfo[playerid][pVote]);
    
INI_WriteInt(File,"VotedPlayer",pInfo[playerid][VotedPlayer]);
    
INI_WriteInt(File,"Mask",pInfo[playerid][pMask]);
    
INI_WriteInt(File,"MaskOn",pInfo[playerid][pMaskOn]);
    
INI_WriteInt(File,"Cookies",pInfo[playerid][pCookies]);
    
INI_WriteInt(File,"Jailed",pInfo[playerid][pJailed]);
    
INI_WriteInt(File,"JailTime",pInfo[playerid][pJailTime]);
    
INI_WriteInt(File,"FirstPS",pInfo[playerid][FirstPS]);
    
INI_Close(File);
    return 
1;

Reply
#2

~remove~
Reply
#3

Well, it now saves, but everytime I login it doesn't load.
Reply
#4

The file's tag has to have the same name as the second part of your loading function's name:
PHP код:
function_THISPARTOFTHEFUNCTIONNAME(playeridname[], value[]) 
The problem with your tag is that it has a space and an apostrophe in it. You can do two things:
  • Rename the function and the tag:
    PHP код:
    INI_SetTag(File"userdata"); 
    PHP код:
    forward loadaccount_userdata(playeridname[], value[]); 
    public 
    loadaccount_userdata(playeridname[], value[]) 
  • Rename the tag and keep the function's name:
    PHP код:
    INI_SetTag(File"user"); 
    PHP код:
    forward loadaccount_user(playeridname[], value[]); 
    public 
    loadaccount_user(playeridname[], value[]) 
From my tutorial:
Quote:
Originally Posted by AndySedeyn
Посмотреть сообщение
FAQ

I am able to log on with any password!
Change:
PHP код:
INI_ParseFile(UserPath(playerid), "LoadPlayerData_%s", .bExtra true, .extra playerid); 
To
PHP код:
INI_ParseFile(UserPath(playerid), "LoadPlayerData_PlayerData", .bExtra true, .extra playerid); 
The data which the placeholder '%s' is replacing, is the name of the file's tag. A huge thanks to Misiur: http://forum.sa-mp.com/showpost.php?...2&postcount=13
EDIT: I just noticed you have a function call to INI_SetTag with the tag 'PlayerData' and one with 'Player's Data'. They should be the same.
Reply
#5

Quote:
Originally Posted by AndySedeyn
Посмотреть сообщение
EDIT: I just noticed you have a function call to INI_SetTag with the tag 'PlayerData' and one with 'Player's Data'. They should be the same.
Yeah. I just noticed that a few hours ago. Changed it. That's why I replied that it's solved but then there's another problem. After reading your reply, I did what you instructed me to.
PHP код:
forward loadaccount_PlayerData(playeridname[], value[]);
public 
loadaccount_PlayerData(playeridname[], value[]) 
The next problem is that it won't load the password everytime I attempt to login
Reply
#6

It doesn't seem logical to load all the data under OnPlayerConnect and then load it all again when the player successfully logged in. A more logical way would be to load only the password under OPC and the rest when the player logged in.
Reply
#7

Here's my new OPC
PHP код:
public OnPlayerConnect(playerid)
{
    if(!
IsPlayerNPC(playerid))
    {
        
GangZoneShowForPlayer(playeridBlackRadar0x000000FF);

        
pInfo[playerid][zMoney] = 0;
        
pInfo[playerid][pAdminLevel] = 0;
        
pInfo[playerid][ZombiesKilled] = 0;
        
pInfo[playerid][HumansKilled] = 0;
        
pInfo[playerid][HumanDeaths] = 0;
        
pInfo[playerid][ZombieDeaths] = 0;
        
pInfo[playerid][pPremium] = 0;
        
pInfo[playerid][pX] = 0.0;
        
pInfo[playerid][pY] = 0.0;
        
pInfo[playerid][pZ] = 0.0;
        
pInfo[playerid][pPM] = 0;
        
pInfo[playerid][pHour] = 0;
        
pInfo[playerid][pSec] = 0;
        
pInfo[playerid][pMin] = 0;
        
pInfo[playerid][Muted] = 0;
        
pInfo[playerid][Warnings] = 0;
        
pInfo[playerid][pLogged] = false;
        
pInfo[playerid][pNMute] = 0;
        
pInfo[playerid][pNMuteTotal] = 0;
          
pInfo[playerid][pBanned] = 0;
        
pInfo[playerid][pVote] = 0;
        
pInfo[playerid][VotedPlayer] = 0;
        
pInfo[playerid][pMask] = 0;
        
pInfo[playerid][pMaskOn] = 0;
        
pInfo[playerid][pCookies] = 0;
        
pInfo[playerid][pJailed] = 0;
        
pInfo[playerid][pJailTime] = 0;
        
pInfo[playerid][FirstPS] = 0;

        new 
name[MAX_PLAYER_NAME];
        
GetPlayerName(playerid,name,sizeof(name));
        if(
fexist(Path(playerid)))
        {
            
INI_String("Password"pInfo[playerid][Password],129);
            
ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login","Welcome back to "COL_LRED""SERVER_NAME" "SERVER_VERSION""COL_WHITE". This account is registered. \nInsert your password to login to your account","Login","Quit");
        }
        else
        {
            
ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_PASSWORD,"Register","Welcome to "COL_LRED""SERVER_NAME" "SERVER_VERSION""COL_WHITE"! This account is not registered.\nEnter your own password to create a new account.","Register","Quit");
            return 
1;
          }
    }
    return 
1;

Did I do it correctly?
Reply
#8

Did something wrong

PHP код:
INI_String("Password"pInfo[playerid][Password],129); 
to
PHP код:
INI_ParseFile(Path(playerid),"loadpass_PlayerData", .bExtra true, .extra playerid); 
right?
Reply
#9

Yes.
Reply
#10

Forgot something.
PHP код:
forward loadpass_PlayerData(playeridname[], value[]);
public 
loadpass_PlayerData(playeridname[], value[])
{
    
INI_String("Password"pInfo[playerid][Password],129);
    return 
1;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)