Skin saving MySQL
#1

how could i save skin so the player the next time he logins doesnt need to choose skin but he will be spawned immediately after login dialog?
Reply
#2

NOTICE: The below code is using R39-2
Which can be found here: https://github.com/pBlueG/SA-MP-MySQL/releases

pawn Code:
// Top of Script
enum PlayerStats // Add the below to your enumerator that stores player data.
{
    pID, // Unique SQL ID - Change this to match your script.
    pSkin // Player Skin
};
new P_Info[MAX_PLAYERS][PlayerStats];// Used to read from PlayerStats - Rename to your Global variable.
pawn Code:
// OnPlayerConnect
P_Info[playerid][pSkin] = 0;// Sets their skin to 0 when they connect, to avoid bugs later.
pawn Code:
// OnPlayerDisconnect
P_Info[playerid][pSkin] = GetPlayerSkin(playerid);

// Change WHERE `ID`=%d to whatever your script uses.
mysql_format(mysql, query, sizeof(query),"UPDATE `players` SET `Score`=%d WHERE `ID`=%d", P_Info[playerid][dPlate], P_Info[playerid][pID]);// Updates the Database with their skin ID.
mysql_tquery(mysql, query, "", "");
pawn Code:
// OnPlayerSpawn
SetPlayerSkin(playerid, P_Info[playerid][pSkin]);// For registered users use this. Registered users by defualt is 0 so use this accordingly in your script.
pawn Code:
// Under your User Account Load function. Usually called when they log in.
P_Info[playerid][pSkin] = cache_get_field_content_int(0, "Skin");
Reply
#3

Quote:
Originally Posted by Lynn
View Post
NOTICE: The below code is using R39-2
Which can be found here: https://github.com/pBlueG/SA-MP-MySQL/releases

pawn Code:
// Top of Script
enum PlayerStats // Add the below to your enumerator that stores player data.
{
    pID, // Unique SQL ID - Change this to match your script.
    pSkin // Player Skin
};
new P_Info[MAX_PLAYERS][PlayerStats];// Used to read from PlayerStats - Rename to your Global variable.
pawn Code:
// OnPlayerConnect
P_Info[playerid][pSkin] = 0;// Sets their skin to 0 when they connect, to avoid bugs later.
pawn Code:
// OnPlayerDisconnect
P_Info[playerid][pSkin] = GetPlayerSkin(playerid);

// Change WHERE `ID`=%d to whatever your script uses.
mysql_format(mysql, query, sizeof(query),"UPDATE `players` SET `Score`=%d WHERE `ID`=%d", P_Info[playerid][dPlate], P_Info[playerid][pID]);// Updates the Database with their skin ID.
mysql_tquery(mysql, query, "", "");
pawn Code:
// OnPlayerSpawn
SetPlayerSkin(playerid, P_Info[playerid][pSkin]);// For registered users use this. Registered users by defualt is 0 so use this accordingly in your script.
pawn Code:
// Under your User Account Load function. Usually called when they log in.
P_Info[playerid][pSkin] = cache_get_field_content_int(0, "Skin");
I got it but to my script when a player logs in he goes to class selection i want to avoid that.. where i should put spawnplayer or something related so i could avoid class selection for players who are already registered?
Reply
#4

If you are using a AccountLoad Function(Called under OnDialogResponse, Login Dialog)
The place SpawnPlayer(playerid); Under that function as the last thing(Right above the return value.)
Otherwise, place it under DIALOG_LOGIN.
Reply
#5

How do you save the accounts? Which MySQL version do you use?
Reply
#6

Quote:
Originally Posted by biker122
View Post
How do you save the accounts? Which MySQL version do you use?
Lynn helped me totally i actually use a load function. I use r39-2
Anyway yes Lynn i use OnAccountLoad function here it is:
pawn Code:
function OnPlayerLogin2( playerid, arg1[] )    // arg1 = Password passed
{
    new
        Hash[ 151 ],
        a[ 2 ] = "a",
        pname[ MAX_PLAYER_NAME ];
    GetPlayerName( playerid, pname, sizeof( pname ) );
    WP_Hash( Hash, sizeof( Hash ), arg1 );
    format( arg1, 2, "%s", a );

    if( strcmp( Hash, pinfo[ playerid ][ Pass ] ) != 0 )
    {
        ShowPlayerDialog( playerid, dialog_login, DIALOG_STYLE_PASSWORD, "Login", "Please enter your password.", "Enter", "Exit" );
        return 1;
    }
   
    mysql_format( MySQLTunnel, Hash, sizeof( Hash ), "SELECT * FROM `accounts` WHERE `pname` = '%e'", pname );
    mysql_pquery( MySQLTunnel, Hash, "OnAccountLoad", "d", playerid );
   
    return 1;
}

function OnAccountLoad( playerid )
{
    if( cache_get_row_count( MySQLTunnel ) )
    {
        pinfo[ playerid ][ pMySQLID ]                   =       cache_get_field_content_int( 0, "pid", MySQLTunnel );
        pinfo[ playerid ][ Admin ]                      =       cache_get_field_content_int( 0, "padmin", MySQLTunnel );
        pinfo[ playerid ][ VIP ]                        =       cache_get_field_content_int( 0, "pvip", MySQLTunnel );
        pinfo[ playerid ][ Score ]                      =       cache_get_field_content_int( 0, "pscore", MySQLTunnel );
        pinfo[ playerid ][ Money ]                      =       cache_get_field_content_int( 0, "pmoney", MySQLTunnel );
        pinfo[ playerid ][ Kills ]                      =       cache_get_field_content_int( 0, "pkills", MySQLTunnel );
        pinfo[ playerid ][ Deaths ]                     =       cache_get_field_content_int( 0, "pdeaths", MySQLTunnel );
        pinfo[ playerid ][ Banned ]                     =       cache_get_field_content_int( 0, "pbanned", MySQLTunnel );
        pinfo[ playerid ][ Hours ]                      =       cache_get_field_content_int( 0, "phours", MySQLTunnel );
        pinfo[ playerid ][ Minutes ]                    =       cache_get_field_content_int( 0, "pminutes", MySQLTunnel );
        pinfo[ playerid ][ Terskill ]                   =       cache_get_field_content_int( 0, "pterskill", MySQLTunnel );
        pinfo[ playerid ][ Robskill ]                   =       cache_get_field_content_int( 0, "probskill", MySQLTunnel );
        pinfo[ playerid ][ Hitmanskill ]                =       cache_get_field_content_int( 0, "phitmanskill", MySQLTunnel );
        pinfo[ playerid ][ WantedLevel ]                =       cache_get_field_content_int( 0, "pwantedlevel", MySQLTunnel );
        pinfo[ playerid ][ Muted ]                      =       cache_get_field_content_int( 0, "pmuted", MySQLTunnel );
        pinfo[ playerid ][ TotalRobs ]                  =       cache_get_field_content_int( 0, "ptotalrobs", MySQLTunnel );
        pinfo[ playerid ][ Freezed ]                    =       cache_get_field_content_int( 0, "pfreezed", MySQLTunnel );
        pinfo[ playerid ][ Jailed ]                     =       cache_get_field_content_int( 0, "pjailed", MySQLTunnel );
        pinfo[ playerid ][ JailTime ]                   =       cache_get_field_content_int( 0, "pjailtime", MySQLTunnel );
        pinfo[ playerid ][ Cuffed ]                     =       cache_get_field_content_int( 0, "pcuffed", MySQLTunnel );


        pinfo[ playerid ][ pLogged ]                    = 1;
        SetPlayerScore(playerid,pinfo[playerid][Score]);
        GivePlayerMoney(playerid,pinfo[playerid][Money]);
        SetPlayerWantedLevel(playerid,pinfo[playerid][WantedLevel]);

    }
    return 1;
}
Reply
#7

Okay. Can you just show me how you save the accounts?
Reply
#8

Under;
SetPlayerWantedLevel(playerid,pinfo[playerid][WantedLevel]);
Do the SpawnPlayer(playerid);

That should work.
You can do the same thing under the Register Account function(Unless you want them to select skin on Register.)

Quote:
Originally Posted by biker122
View Post
Okay. Can you just show me how you save the accounts?
MySQL Threaded Queries - SQL R7.(BlueG Plugin, R39-2 On Github.)
https://sampforum.blast.hk/showthread.php?tid=485633
Reply
#9

Quote:
Originally Posted by Lynn
View Post
Under;
SetPlayerWantedLevel(playerid,pinfo[playerid][WantedLevel]);
Do the SpawnPlayer(playerid);

That should work.
You can do the same thing under the Register Account function(Unless you want them to select skin on Register.)
No that won't work perfectly. He first has to check if the player has saved a skin, if the player has saved his own skin, the script should auto-spawn him.

So, this is how it should look like:
pawn Code:
enum player_data
{
    Skin
};
new pinfo[ MAX_PLAYERS ][ player_data ];

public OnPlayerDisconnect( playerid, reason )
{
    new pname[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, sizeof pname);
    mysql_format(MySQLTunnel, Query1, "UPDATE `accounts` SET `pskin` = '%i' WHERE `pname` = '%e'", GetPlayerSkin(playerid), pname);
    mysql_tquery(MySQLTunnel, Query1, "", "");
    return 1;
}

function OnAccountLoad( playerid )
{
    if( cache_get_row_count( MySQLTunnel ) )
    {
        pinfo[ playerid ][ pMySQLID ]                   =       cache_get_field_content_int( 0, "pid", MySQLTunnel );
        pinfo[ playerid ][ Admin ]                      =       cache_get_field_content_int( 0, "padmin", MySQLTunnel );
        pinfo[ playerid ][ VIP ]                        =       cache_get_field_content_int( 0, "pvip", MySQLTunnel );
        pinfo[ playerid ][ Score ]                      =       cache_get_field_content_int( 0, "pscore", MySQLTunnel );
        pinfo[ playerid ][ Money ]                      =       cache_get_field_content_int( 0, "pmoney", MySQLTunnel );
        pinfo[ playerid ][ Kills ]                      =       cache_get_field_content_int( 0, "pkills", MySQLTunnel );
        pinfo[ playerid ][ Deaths ]                     =       cache_get_field_content_int( 0, "pdeaths", MySQLTunnel );
        pinfo[ playerid ][ Banned ]                     =       cache_get_field_content_int( 0, "pbanned", MySQLTunnel );
        pinfo[ playerid ][ Hours ]                      =       cache_get_field_content_int( 0, "phours", MySQLTunnel );
        pinfo[ playerid ][ Minutes ]                    =       cache_get_field_content_int( 0, "pminutes", MySQLTunnel );
        pinfo[ playerid ][ Terskill ]                   =       cache_get_field_content_int( 0, "pterskill", MySQLTunnel );
        pinfo[ playerid ][ Robskill ]                   =       cache_get_field_content_int( 0, "probskill", MySQLTunnel );
        pinfo[ playerid ][ Hitmanskill ]                =       cache_get_field_content_int( 0, "phitmanskill", MySQLTunnel );
        pinfo[ playerid ][ WantedLevel ]                =       cache_get_field_content_int( 0, "pwantedlevel", MySQLTunnel );
        pinfo[ playerid ][ Muted ]                      =       cache_get_field_content_int( 0, "pmuted", MySQLTunnel );
        pinfo[ playerid ][ TotalRobs ]                  =       cache_get_field_content_int( 0, "ptotalrobs", MySQLTunnel );
        pinfo[ playerid ][ Freezed ]                    =       cache_get_field_content_int( 0, "pfreezed", MySQLTunnel );
        pinfo[ playerid ][ Jailed ]                     =       cache_get_field_content_int( 0, "pjailed", MySQLTunnel );
        pinfo[ playerid ][ JailTime ]                   =       cache_get_field_content_int( 0, "pjailtime", MySQLTunnel );
        pinfo[ playerid ][ Cuffed ]                     =       cache_get_field_content_int( 0, "pcuffed", MySQLTunnel );
    pinfo[ playerid ][ Skin ]           =   cache_get_field_content_int( 0, "pskin", MySQLTunnel );


        pinfo[ playerid ][ pLogged ]                    = 1;
        SetPlayerScore(playerid,pinfo[playerid][Score]);
        GivePlayerMoney(playerid,pinfo[playerid][Money]);
        SetPlayerWantedLevel(playerid,pinfo[playerid][WantedLevel]);
    if( pinfo[ playerid ][ Skin ] != -1) SpawnPlayer(playerid);
    }
    return 1;
}
For this to work, you need to reset the value of pinfo[playerid][Skin] to -1 when the player connects/disconnects.
Reply
#10

Quote:
Originally Posted by biker122
View Post
----
The value is stored on log out, and can't equal anything other then 0-299.
The function is only called when the player logs in, and the Skin is autoset to 0 on Connect.
So even if a value isn't stored in the database, it's still 0 which is a valid skin ID.

However, he will have to add the Skin variable to his AccountLoad Function but I'm sure he already knows that
If he's able to write other functions in MySQL. It seemed useless to inform him of knowledge he already knows.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)