17.01.2015, 01:55
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?
// 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.
// OnPlayerConnect
P_Info[playerid][pSkin] = 0;// Sets their skin to 0 when they connect, to avoid bugs later.
// 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, "", "");
// 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.
// Under your User Account Load function. Usually called when they log in.
P_Info[playerid][pSkin] = cache_get_field_content_int(0, "Skin");
NOTICE: The below code is using R39-2
Which can be found here: https://github.com/pBlueG/SA-MP-MySQL/releases pawn Code:
pawn Code:
pawn Code:
pawn Code:
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;
}
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.) |
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;
}