EDIT
You have to create a variable that checks if the player is logged in or if the player is registering.
Like so:
This is our variable. It should only return 0 or 1 (False or true) and therefor it's a boolean.
pawn Код:
new bool:gRegistering[MAX_PLAYERS];
We assign a value to the variable. If the player is already registered then we say that gRegistering[playerid] = false.
If the player is not registered yet we assign it to a true value.
pawn Код:
public OnPlayerConnect(playerid)
{
if(fexist(UserPath(playerid)))
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_WHITE"Type your password below to login.","Login","Quit");
gRegistering[playerid] = false;
}
else
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""COL_WHITE"Registering...",""COL_WHITE"Type your password below to register a new account.","Register","Quit");
gRegistering[playerid] = true;
}
return 1;
}
When the player disconnects (by a kick or by a manual /q) we check if the player is registered. If not: We don't save his data. Thus, we avoid having a file created.
pawn Код:
public OnPlayerDisconnect(playerid)
{
if(!gRegistering[playerid])
{
//Save the user's data.
}
return 1;
}
When the player registers, we reset the gRegistering variable to false. Otherwise his data will not save upon disconnect.
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch( dialogid )
{
case DIALOG_REGISTER:
{
if(!response)
{
if(fexist(UserPath(playerid)))
{
fremove(UserPath(playerid));
return SetTimerEx("KickDelay", 100, false, "i", playerid);
}
}
if(response)
{
if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""COL_WHITE"Register",COL_RED"Invalid Password","Register","Close");
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Password",udb_hash(inputtext));
INI_WriteInt(File,"Cash",0);
INI_WriteInt(File,"Admin",0);
INI_WriteInt(File,"Kills",0);
INI_WriteInt(File,"Deaths",0);
INI_Close(File);
ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success",""COL_GREEN"El hamd ll allah :D","Kois !","");
gRegistering[playerid] = false;
}
}
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);
GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success",""COL_GREEN"El hamd ll allah :D","Kois !","");
}
else
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login"COL_RED"Invalid Paswword","Login","Close");
}
}
}
}
return 0;
}
Our delayed kick.
pawn Код:
forward KickDelay(playerid);
public KickDelay(playerid)
{
Kick(playerid);
}