SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 17/01/2015, 01:55 AM   #1
vassilis
High-roller
 
vassilis's Avatar
 
Join Date: Nov 2009
Location: Greece,Athens
Posts: 1,679
Reputation: 362
Default Skin saving MySQL

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?
vassilis is offline   Reply With Quote
Old 17/01/2015, 02:48 AM   #2
Lynn
Gangsta
 
Lynn's Avatar
 
Join Date: Jan 2010
Location: Detroit, Michigan USA
Posts: 937
Reputation: 108
Default Re: Skin saving MySQL

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");
__________________
Former developer at Next Generation Gaming
Lynn is offline   Reply With Quote
Old 17/01/2015, 03:18 AM   #3
vassilis
High-roller
 
vassilis's Avatar
 
Join Date: Nov 2009
Location: Greece,Athens
Posts: 1,679
Reputation: 362
Default Re: Skin saving MySQL

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?
vassilis is offline   Reply With Quote
Old 17/01/2015, 03:23 AM   #4
Lynn
Gangsta
 
Lynn's Avatar
 
Join Date: Jan 2010
Location: Detroit, Michigan USA
Posts: 937
Reputation: 108
Default Re: Skin saving MySQL

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.
__________________
Former developer at Next Generation Gaming
Lynn is offline   Reply With Quote
Old 17/01/2015, 03:29 AM   #5
biker122
Gangsta
 
Join Date: Feb 2014
Posts: 766
Reputation: 59
Default Re: Skin saving MySQL

How do you save the accounts? Which MySQL version do you use?
__________________
k
biker122 is offline   Reply With Quote
Old 17/01/2015, 03:33 AM   #6
vassilis
High-roller
 
vassilis's Avatar
 
Join Date: Nov 2009
Location: Greece,Athens
Posts: 1,679
Reputation: 362
Default Re: Skin saving MySQL

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;
}
vassilis is offline   Reply With Quote
Old 17/01/2015, 03:44 AM   #7
biker122
Gangsta
 
Join Date: Feb 2014
Posts: 766
Reputation: 59
Default Re: Skin saving MySQL

Okay. Can you just show me how you save the accounts?
__________________
k
biker122 is offline   Reply With Quote
Old 17/01/2015, 03:49 AM   #8
Lynn
Gangsta
 
Lynn's Avatar
 
Join Date: Jan 2010
Location: Detroit, Michigan USA
Posts: 937
Reputation: 108
Default Re: Skin saving MySQL

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.)
http://forum.sa-mp.com/showthread.php?t=485633
__________________
Former developer at Next Generation Gaming
Lynn is offline   Reply With Quote
Old 17/01/2015, 03:53 AM   #9
biker122
Gangsta
 
Join Date: Feb 2014
Posts: 766
Reputation: 59
Default Re: Skin saving MySQL

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.
__________________
k
biker122 is offline   Reply With Quote
Old 17/01/2015, 04:03 AM   #10
Lynn
Gangsta
 
Lynn's Avatar
 
Join Date: Jan 2010
Location: Detroit, Michigan USA
Posts: 937
Reputation: 108
Default Re: Skin saving MySQL

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.
__________________
Former developer at Next Generation Gaming
Lynn 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 skin an pos Mwowwtittybang Scripting Help 3 04/12/2012 08:48 AM
[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
loading/saving skin from mysql swredder Help Archive 2 05/06/2010 06:33 PM
Skin saving? dirkblok Help Archive 2 12/10/2009 09:56 AM


All times are GMT. The time now is 08:04 AM.


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