SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 18/06/2019, 10:27 AM   #1
TechLunatic
Little Clucker
 
TechLunatic's Avatar
 
Join Date: Jun 2019
Location: Bangladesh
Posts: 10
Reputation: 0
Default [HELP] Player skin not saving

I am a beginner scripter.

The problem is that when a player register's and disconnects and when he log's in again, CJ's skin appears instead of the skin that player had before. There is another bug which is when a player dies he spawns in the air. How do i fix it?

Here's the script:
PHP Code:
#include <a_samp>
#include <YSI/y_ini>
#include <zcmd>
#include <sscanf2>
#include <streamer>
#include <audio>
#include "../gamemodes/others/colors.pwn"

native WP_Hash(buffer[], len, const str[]);


enum pInfo
{
    
pPass,
    
pCash,
    
pAdmin,
    
pSex,
    
pAge,
    
Float:pPos_x,
    
Float:pPos_y,
    
Float:pPos_z,
    
pSkin,
    
pKills,
    
pDeaths
}

new 
PlayerInfo[MAX_PLAYERS][pInfo];

// Variables

new LoggedMAX_PLAYERS ];

// Booleans

new bool:pNewlyRegged[MAX_PLAYERS];

public 
OnGameModeInit()
{
    
SetGameModeText(SCRIPT_VERSION);
    
UsePlayerPedAnims();
    
SetTimer("SaveAccounts"SECONDS(13), 1);
    return 
1;
}

public 
OnPlayerRequestClass(playeridclassid)
{
    return 
1;
}

public 
OnPlayerConnect(playerid)
{
    if(
fexist(UserPath(playerid))) 
    {
        
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra true, .extra playerid);
        
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_PASSWORD,"Login","Type your password below in order to login.","Login","Quit");
    }
    else
    {
        
ShowPlayerDialog(playeridDIALOG_REGISTERDIALOG_STYLE_PASSWORD,"Register","Type your password below in order to register a new account.","Register","Quit");
    }

    return 
1;
}

public 
OnPlayerDisconnect(playeridreason)
{
    
SaveAccountStats(playerid);
    return 
1;
}

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("Sex",PlayerInfo[playerid][pSex]);
    
INI_Int("Age",PlayerInfo[playerid][pAge]);
    
INI_Float("Pos_x",PlayerInfo[playerid][pPos_x]);
    
INI_Float("Pos_y",PlayerInfo[playerid][pPos_y]);
    
INI_Float("Pos_z",PlayerInfo[playerid][pPos_z]);
    
INI_Int("Skin",PlayerInfo[playerid][pSkin]);
    
INI_Int("Kills",PlayerInfo[playerid][pKills]);
    
INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
    return 
1;
}


forward SpectateFix(playerid);
public 
SpectateFix(playerid)
{
    
SpawnPlayer(playerid);
    return 
true;
}

public 
OnPlayerSpawn(playerid)
{
    if(
pNewlyRegged[playerid])
    {
       
SetPlayerPos(playerid1562.86475, -2286.08960334.84576);
        
GivePlayerWeapon(playerid4610000);
        
SetPlayerSkin(playeridPlayerInfo[playerid][pSkin]);
    }

    if(
PlayerInfo[playerid][pPos_x] == && PlayerInfo[playerid][pPos_y] == 0
    {
        
Logged[playerid] = 1;
    }
    else
    {
        
SetPlayerPos(playeridPlayerInfo[playerid][pPos_x], PlayerInfo[playerid][pPos_y], PlayerInfo[playerid][pPos_z]);
        
Logged[playerid] = 1;
    }
    return 
1;
}

public 
OnPlayerDeathplayeridkilleridreason )
{
    
PlayerInfo[playerid][pDeaths] ++;
    if( 
killerid != INVALID_PLAYER_ID )
    {
        
PlayerInfo[killerid][pKills] ++;
    }
    return 
1;
}



public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    if(
dialogid == DIALOG_AGE)
    {
        
TogglePlayerSpectating(playeridfalse);

        if(!
response)
        {
            
Kick(playerid);
        }
        else
        {
            if(
strlen(inputtext))
            {
                new 
age strval(inputtext);
                if(
age 50 || age 18)
                {
                    
ShowPlayerDialog(playeridDIALOG_AGEDIALOG_STYLE_INPUT"Age","How old is your character?\nYour character's age must be between 18 and 50.","Proceed","Quit");
                }
                else
                {
                    
PlayerInfo[playerid][pAge] = age;
                    new
                        
string64 ]
                    ;
                    
format(stringsizeof(string), "{FFFFFF}You are %d years old!",age);
                    
SendClientMessage(playerid, -1string);
                    
GivePlayerCash(playerid1000);
                    
SaveAccountStats(playerid);
                    
SpawnPlayer(playerid);
                    
SetTimer("SpectateFix"350false);
                }
            }
            else
            {
                return 
0;
            }
        }
    }
    if(
dialogid == DIALOG_SEX)
    {
        if(
response)
        {
            
PlayerInfo[playerid][pSex] = 1// Male = 1
            
SetPlayerSkin(playerid250);
            
PlayerInfo[playerid][pSkin] = 250;
            
SendClientMessage(playerid, -1"{FFFFFF}You have set your character's gender. You are a male!");
            
ShowPlayerDialog(playeridDIALOG_AGEDIALOG_STYLE_INPUT"Age","How old is your character?\nYour character's age must be between 18 and 50.","Proceed","Quit");
        }
        else
        {
            
PlayerInfo[playerid][pSex] = 2//Female =  2
            
SetPlayerSkin(playerid191);
            
PlayerInfo[playerid][pSkin] = 191;
            
SendClientMessage(playerid, -1"{FFFFFF}You have set your character's gender. You are a female!");
            
ShowPlayerDialog(playeridDIALOG_AGEDIALOG_STYLE_INPUT"Age","How old is your character?\nYour character's age must be between 18 and 50.","Proceed","Quit");
        }
    }
    switch( 
dialogid )
    {
        case 
DIALOG_REGISTER:
        {
            if (!
response) return Kick(playerid);
            if(
response)
            {
                if(!
strlen(inputtext)) return ShowPlayerDialog(playeridDIALOG_REGISTERDIALOG_STYLE_INPUT"Registering","You have entered an invalid password.\nType your password below to register a new account.","Register","Quit");
                new 
buf[129];
                new 
INI:File INI_Open(UserPath(playerid));
                
INI_SetTag(File,"data");
                
WP_Hash(bufsizeof(buf), inputtext);
                
INI_WriteString(File,"Password"buf);
                
INI_WriteInt(File,"Cash",0);
                
INI_WriteInt(File,"Skin",0);
                
INI_WriteInt(File,"Sex",0);
                
INI_WriteInt(File,"Age",0);
                
INI_WriteFloat(File,"Pos_x",0);
                
INI_WriteFloat(File,"Pos_y",0);
                
INI_WriteFloat(File,"Pos_z",0);
                
INI_WriteInt(File,"Deaths",0);
                
INI_WriteInt(File,"Kills",0);
                
INI_Close(File);

                
pNewlyRegged[playerid] = true;

                
ShowPlayerDialog(playeridDIALOG_SEXDIALOG_STYLE_MSGBOX"Sex","What is the gender of your character?","Male","Female");
            }
        }
        case 
DIALOG_LOGIN:
        {
            if ( !
response ) return Kick playerid );
            if( 
response )
            {
                new 
hashpass[129];
                
WP_Hash(hashpass,sizeof(hashpass),inputtext);
                if(!
strcmp(hashpassPlayerInfo[playerid][pPass], false))
                {
                    
INI_ParseFile(UserPath(playerid), "LoadUser_data", .bExtra true, .extra playerid);
                    
SetPlayerSkin(playeridPlayerInfo[playerid][pSkin]);
                    
GivePlayerMoney(playeridPlayerInfo[playerid][pCash]);
                       
SendClientMessage(playeridCOLOR_WHITE2"You have successfully logged in, enjoy your stay!");
                }
                else
                {
                    
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_INPUT,"Login","You have entered an incorrect password.\nType your password below to login.","Login","Quit");
                }
                return 
1;
            }
        }
    }
    return 
1;
}



function:
SaveAccountStats(playerid)
{
    if(
Logged[playerid] == 1)
    {
    new
        
INI:File INI_Open(UserPath(playerid))
    ;
    
INI_SetTag(File,"data");

    
PlayerInfo[playerid][pSkin] = GetPlayerSkin(playerid);
    
PlayerInfo[playerid][pCash] = GetPlayerCash(playerid);
    new
        
Float:x,
        
Float:y,
        
Float:z
    
;
    
GetPlayerPos(playerid,x,y,z);
    
PlayerInfo[playerid][pPos_x] = x;
    
PlayerInfo[playerid][pPos_y] = y;
    
PlayerInfo[playerid][pPos_z] = z;

    
INI_WriteInt(File,"Cash",PlayerInfo[playerid][pCash]);
    
INI_WriteInt(File,"Age",PlayerInfo[playerid][pAge]);
    
INI_WriteInt(File,"Sex",PlayerInfo[playerid][pSex]);
    
INI_WriteInt(File,"Skin",PlayerInfo[playerid][pSkin]);
    
INI_WriteFloat(File,"Pos_x",PlayerInfo[playerid][pPos_x]);
    
INI_WriteFloat(File,"Pos_y",PlayerInfo[playerid][pPos_y]);
    
INI_WriteFloat(File,"Pos_z",PlayerInfo[playerid][pPos_z]);
    
INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    
INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);

    
INI_Close(File);
    }
    return 
1;
}


function:
SaveAccounts()
{
    for(new 
0MAX_PLAYERSi++)
    {
        if(
IsPlayerConnected(i))
        {
            
SaveAccountStats(i);
        }
    }

TechLunatic is offline   Reply With Quote
Old 18/06/2019, 10:58 AM   #2
Koreadars
Big Clucker
 
Join Date: Mar 2019
Location: Czech Republic, Prdelákov.
Posts: 128
Reputation: 6
Default Re: [HELP] Player skin not saving

pawn Code:
INI_WriteInt(File,"Skin", GetPlayerSkin(playerid));
Koreadars is offline   Reply With Quote
Old 18/06/2019, 03:12 PM   #3
TechLunatic
Little Clucker
 
TechLunatic's Avatar
 
Join Date: Jun 2019
Location: Bangladesh
Posts: 10
Reputation: 0
Default Re: [HELP] Player skin not saving

Quote:
Originally Posted by Koreadars View Post
pawn Code:
INI_WriteInt(File,"Skin", GetPlayerSkin(playerid));
I tried it before. Still not working
TechLunatic is offline   Reply With Quote
Old 18/06/2019, 06:10 PM   #4
Fuzzy
Little Clucker
 
Join Date: May 2019
Posts: 30
Reputation: 0
Default Re: [HELP] Player skin not saving

Quote:
public OnPlayerDisconnect(playerid, reason)
{
new Float:Xlog, Float:Ylog, Float:Zlog;
GetPlayerPos(playerid, Xlog, Ylog, Zlog); // Getting the player position on disconnect.
PlayerInfo[playerid][Xpos] = Xlog;
PlayerInfo[playerid][Ypos] = Ylog;
PlayerInfo[playerid][Zpos] = Zlog;
new playerskin = GetPlayerSkin(playerid); // getting the player skin on disconnect.
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Money",GetPlayerMoney(playerid) );
INI_WriteInt(File,"Admin",PlayerInfo[playerid][Admin]);
INI_WriteInt(File,"Deaths",PlayerInfo[playerid][Deaths]);
INI_WriteInt(File,"Skin",playerskin); // his skin.
INI_WriteFloat(File,"Xpos",PlayerInfo[playerid][Xpos]); // Making sure we save it as a FLOAT
INI_WriteFloat(File,"Ypos",PlayerInfo[playerid][Ypos]); // Making sure we save it as a FLOAT
INI_WriteFloat(File,"Zpos",PlayerInfo[playerid][Zpos]); // Making sure we save it as a FLOAT
INI_WriteInt(File,"NewReg",0); // When he disconnects he is no longer a new registrator.
INI_Close(File);
return 1;
}
Better way to save things. just edit it to your script
Fuzzy is offline   Reply With Quote
Old 18/06/2019, 11:51 PM   #5
TechLunatic
Little Clucker
 
TechLunatic's Avatar
 
Join Date: Jun 2019
Location: Bangladesh
Posts: 10
Reputation: 0
Default Re: [HELP] Player skin not saving

Quote:
Originally Posted by Fuzzy View Post
Better way to save things. just edit it to your script
Still CJ skin appearing
TechLunatic is offline   Reply With Quote
Old 19/06/2019, 02:43 AM   #6
RogueDrifter
High-roller
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 1,192
Reputation: 386
Default Re: [HELP] Player skin not saving

1- I do not support using a file system as a login/register system

I did this before and i was stuck with 9999 files when you get a high player base.

2- Did you ever think that maybe your loading/saving is correct but your actual setting of a skin is messed up?

Can you please print the value of the skin variable and the file skin value and check the console? Its easy just use printf("%d", SKIN_VARIABLE); and replace SKIN_VARIABLE with your actual skin variable.
__________________
Quote:
Originally Posted by Andy
I offer paid scripting services, I can do anything except mapping because fuck mapping.

[Github]:Link [Gists]:Link [Forum]:Link [Server]:Link [Discord]:Link


RogueDrifter is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving player skin onduty/offduty jasperschellekens Scripting Help 6 09/04/2017 07:39 PM
[HELP] Skin Saving / Position Saving. andershh Help Archive 3 13/07/2010 10:20 AM
[HELP] Skin Changing and Skin Saving Varna Help Archive 3 07/06/2010 01:48 PM
Skin saving bartje01 Help Archive 3 03/02/2010 03:11 PM
saving player's spawn/skin tommy5933 Help Archive 14 05/07/2009 11:22 AM


All times are GMT. The time now is 07:03 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.