31.07.2011, 09:10
I am trying to save stats but OnPlayerDisconnect every thing changes in numbers etc not saving last information correct here is my code
pawn Code:
#include <a_samp>
#include <SII> // Include SII.inc
enum pInfo
{
pName,
pPass,
pLevel,
pMoney,
pAdmin,
}
new PlayerInfo[MAX_PLAYERS][pInfo];
new Player_Name[MAX_PLAYERS][MAX_PLAYER_NAME];
new bool: player_loggedin[MAX_PLAYERS];
// dialouge defines
#define DIALOG_REGISTER 2000
#define DIALOG_LOGIN 2001
// colors define for login
#define WHITE "{FFFFFF}"
#define RED "{F81414}"
#define GREEN "{00FF22}"
#define LIGHTBLUE "{00CED1}"
stock getINI(playerid)
{
new account[64];
format(account,30,"Users/%s.ini",Player_Name[playerid]);
return account;
}
main()
{
}
public OnGameModeInit()
{
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
return 1;
}
public OnPlayerConnect(playerid)
{
GetPlayerName(playerid, Player_Name[playerid], MAX_PLAYER_NAME);
if (fexist(getINI(playerid)))
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""WHITE"Login",""WHITE"Type your password below to login.","Login","Quit");
}
else
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""WHITE"Registering...",""WHITE"Type your password below to register a new account.","Register","Quit");
}
return 1;
}
public OnPlayerDisconnect(playerid)
{
if(INI_Open(getINI(playerid))) {
player_loggedin[playerid] = false;
INI_WriteInt("Name",PlayerInfo[playerid][pName]);
INI_WriteInt("Password",PlayerInfo[playerid][pPass]);
INI_WriteInt("Level",PlayerInfo[playerid][pLevel]);
INI_WriteInt("Money",PlayerInfo[playerid][pMoney]);
INI_WriteInt("Admin",PlayerInfo[playerid][pAdmin]);
INI_Save();
INI_Close();
}
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch( dialogid )
{
case DIALOG_REGISTER:
{
if (!response) return Kick(playerid);
if (response)
{
if(!strlen(inputtext)) {
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""WHITE"Registering...",""RED"You have entered an invalid password.\n"WHITE"Type your password below to register a new account.","Register","Quit");
}
if(INI_Open(getINI(playerid))) {
INI_WriteString("Name", Player_Name[playerid]);
INI_WriteString("Password",inputtext);
INI_WriteInt("Level",1);
INI_WriteInt("Money",5000);
INI_WriteInt("Admin",0);
INI_Save();
INI_Close();
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""WHITE"Login",""WHITE"Type your password below to login.","Login","Quit");
}
}
}
case DIALOG_LOGIN:
{
if ( !response ) return Kick ( playerid );
if( response )
{
if(!strlen(inputtext)) {
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""WHITE"Login",""RED"You have entered an invalid password.\n"WHITE"Type your password below to login.","Login","Quit");
}
if(INI_Open(getINI(playerid))) {
INI_ReadString(PlayerInfo[playerid][pPass],"Password",20);
if(strcmp(inputtext,PlayerInfo[playerid][pPass],false)) {
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""WHITE"Login",""RED"You have entered an incorrect password.\n"WHITE"Type your password below to login.","Login","Quit");
}
player_loggedin[playerid] = true;
SetPlayerScore( playerid, INI_ReadInt("Level" ) );
ResetPlayerMoney( playerid );
GivePlayerMoney( playerid, INI_ReadInt( "Money" ) );
PlayerInfo[playerid][pAdmin] = INI_ReadInt("Admin");
INI_Close();
}
}
}
}
return 1;
}