#include <a_samp> #include <YSI\y_ini> #define DIALOG_REGISTER 1 #define DIALOG_LOGIN 2 #define PATH "/Users/%s.ini" enum pInfo { pPass, pSkin } new PlayerInfo[MAX_PLAYERS][pInfo]; forward LoadUser_data(playerid,name[],value[]); public LoadUser_data(playerid,name[],value[]) { INI_Int("Pass",PlayerInfo[playerid][pPass]); INI_Int("Skin",PlayerInfo[playerid][pSkin]); return 1; } stock UserPath(playerid) { new string[128],playername[MAX_PLAYER_NAME]; GetPlayerName(playerid,playername,sizeof(playername)); format(string,sizeof(string),PATH,playername); return string; } stock udb_hash(buf[]) { new length=strlen(buf); new s1 = 1; new s2 = 0; new n; for (n=0; n<length; n++) { s1 = (s1 + buf[n]) % 65521; s2 = (s2 + s1) % 65521; } return (s2 << 16) + s1; } public OnPlayerConnect(playerid) { if(fexist(UserPath(playerid))) { INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid); ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Inicio de sesiуn.","Escribe tu contraseсa para iniciar la sesiуn.","Iniciar","Cancelar"); } else { ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,"Registrando al jugador.","Escribe tu contraseсa para crear una nueva cuenta.","Registrar","Cancelar"); } return 1; } public OnPlayerDisconnect(playerid, reason) { new INI:File = INI_Open(UserPath(playerid)); INI_SetTag(File,"data"); INI_WriteInt(File,"Skin",GetPlayerSkin(playerid)); INI_Close(File); return 1; } public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) { switch( dialogid ) { case DIALOG_REGISTER: { if (!response) return Kick(playerid); if(response) { if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registrando al jugador.","Has introducido una clave invбlida.\nEscribe tu clave para registrar una nueva cuenta.","Registrar","Cancelar"); new INI:File = INI_Open(UserPath(playerid)); INI_SetTag(File,"data"); INI_WriteInt(File,"Pass",udb_hash(inputtext)); INI_WriteInt(File,"Skin",1); INI_Close(File); AddPlayerClass(PlayerInfo[playerid][pSkin], 1958.33, 1343.12, 15.36, 269.15, 26, 36, 28, 150, 0, 0); } } case DIALOG_LOGIN: { if ( !response ) return Kick ( playerid ); if( response ) { if(udb_hash(inputtext) == PlayerInfo[playerid][pPass]) { INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid); AddPlayerClass(PlayerInfo[playerid][pSkin], 1958.33, 1343.12, 15.36, 269.15, 26, 36, 28, 150, 0, 0); } else { ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Inicio de sesiуn.","Has introducido una clave invбlida.\nEscribe tu clave para iniciar la sesiуn.","Iniciar","Cancelar"); } return 1; } } } return 1; }
Use GetPlayerSkin and add it to the PlayerInfo[playerid][pSkin] variable on OnPlayerDisconnect or on your saving function.
|
PlayerInfo[playerid][pSkin] = GetPlayerSkin(playerid);
case DIALOG_REGISTER:
{
if (!response) return Kick(playerid);
if(response)
{
if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registrando al jugador.","Has introducido una clave invбlida.\nEscribe tu clave para registrar una nueva cuenta.","Registrar","Cancelar");
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Pass",udb_hash(inputtext));
INI_WriteInt(File,"Skin",1); // You don't have to set this value as it'll set itself later when the player disconnects
INI_Close(File);
AddPlayerClass(PlayerInfo[playerid][pSkin], 1958.33, 1343.12, 15.36, 269.15, 26, 36, 28, 150, 0, 0); // there's no PlayerInfo[playerid][pSkin] value yet as you have not written anything to it in this part of the script
}
}
if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid); // This is useless here as you've loaded the player's data under OnPlayerConnect
AddPlayerClass(PlayerInfo[playerid][pSkin], 1958.33, 1343.12, 15.36, 269.15, 26, 36, 28, 150, 0, 0); // Should be changed for SetSpawnInfo
}
Here:
Код:
PlayerInfo[playerid][pSkin] = GetPlayerSkin(playerid); |
You're doing few things wrong:
PHP код:
PHP код:
|