pawn Code:
public loadaccount_user(playerid, name[], value[])
{
INI_String("Ppassword", PlayerInfo[playerid][Ppassword],24);
INI_Int("Padmin",PlayerInfo[playerid][Padmin]);/*We will use INI_Int to load user's admin level. INI_Int stands for INI_Integer. This load an admin level. */
INI_Int("Pvip",PlayerInfo[playerid][Pvip]);//As explained above
INI_Int("Pmoney",PlayerInfo[playerid][Pmoney]); //As explained above
INI_Int("Pscore",PlayerInfo[playerid][Pscore]);//As explained above
INI_Int("Pbank",PlayerInfo[playerid][Pbank]);
INI_Int("Pstat",PlayerInfo[playerid][Pstat]);
INI_Int("Parmy",PlayerInfo[playerid][Parmy]);
INI_Int("Pswat",PlayerInfo[playerid][Pswat]);
INI_Int("Pcop",PlayerInfo[playerid][Pcop]);
INI_Int("Pregdate",PlayerInfo[playerid][Pregdate]);
INI_Int("Preg",PlayerInfo[playerid][Preg]);
INI_Int("Pprison",PlayerInfo[playerid][Pprison]);
INI_Int("Phelper",PlayerInfo[playerid][Phelper]);
INI_Int("Pscore",PlayerInfo[playerid][Pscore]);
INI_String("Pemail", PlayerInfo[playerid][Pemail],255);
INI_Int("Ptime",PlayerInfo[playerid][Ptime]);
INI_Int("Parrest",PlayerInfo[playerid][Parrest]);
INI_Int("Psurender",PlayerInfo[playerid][Psurender]);
INI_Int("Prob",PlayerInfo[playerid][Prob]);
INI_Int("Prape",PlayerInfo[playerid][Prape]);
INI_Int("Pheal",PlayerInfo[playerid][Pheal]);
INI_Int("Phitman",PlayerInfo[playerid][Phitman]);
INI_Int("Psales",PlayerInfo[playerid][Psales]);
INI_Int("Pwep",PlayerInfo[playerid][Pwep]);
INI_Int("Ptruck",PlayerInfo[playerid][Ptruck]);
return 1;
}
new name[MAX_PLAYER_NAME]; //Making a new variable called 'name'. name[MAX_PLAYER_NAME] is created so we can use it to get player's name.
GetPlayerName(playerid,name,sizeof(name)); //Get player's name
if(fexist(Path(playerid))) /* Check if the connected user is registered or not. fexist stands for file exist. So if file exist in the files(Path(playerid)),*/
{// then
INI_ParseFile(Path(playerid),"loadaccount_user", .bExtra = true, .extra = playerid); //Will load user's data using INI_Parsefile.
ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_PASSWORD,"Login","Welcome back. This account is registered. \nInsert your password to login to your account","Login","Quit");/*A dialog with input style will appear so you can insert your password to login.*/
}
else //If the connected user is not registered,
{//then we will 'force' him to register :)
ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.","Register","Quit");
return 1;
}
if(fexist(Path(playerid)))//Will check if the file is exit or not inside of User's folder that we have created.
{
new INI:file = INI_Open(Path(playerid)); //will open their file
INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
INI_WriteInt(file,"Padmin",PlayerInfo[playerid][Padmin]); //If you've set his/her admin level, then his/her admin level will be saved inside of his/her account
INI_WriteInt(file,"Pvip",PlayerInfo[playerid][Pvip]);//As explained above
INI_WriteInt(file,"Pmoney",GetPlayerMoney(playerid));//We will save his money inside of his account
INI_WriteInt(file,"Pscore",GetPlayerScore(playerid));//We will save his score inside of his account
INI_Close(file);//Now after we've done saving their data, we now need to close the file
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == dregister)
{
if(!response) return Kick(playerid);
if(response)
{
if(!strlen(inputtext))
{
ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.\nPlease enter the password!","Register","Quit");
return 1;
}
new hashpass[129];
new nothing[129];
WP_Hash(hashpass,sizeof(hashpass),inputtext);
new INI:file = INI_Open(Path(playerid));
INI_SetTag(file,"Player's Data");
INI_WriteString(file,"Ppassword",hashpass);
INI_WriteInt(file,"Padmin",0);
INI_WriteInt(file,"Pvip",0);
INI_WriteInt(file,"Pmoney",0);
INI_WriteInt(file,"Pscore",0);
INI_WriteInt(file,"Pbank",0);
INI_WriteInt(file,"Pstat",0);
INI_WriteInt(file,"Parmy",0);
INI_WriteInt(file,"Pswat",0);
INI_WriteInt(file,"Pcop",0);
INI_WriteInt(file,"Pregdate",0);
INI_WriteInt(file,"Preg",1);
INI_WriteInt(file,"Pprison",0);
INI_WriteInt(file,"Phelper",0);
INI_WriteInt(file,"Pscore",0);
INI_WriteString(file,"Pemail",nothing);
INI_WriteInt(file,"Ptime",0);
INI_WriteInt(file,"Parrest",0);
INI_WriteInt(file,"Psurender",0);
INI_WriteInt(file,"Prob",0);
INI_WriteInt(file,"Prape",0);
INI_WriteInt(file,"Pheal",0);
INI_WriteInt(file,"Phitman",0);
INI_WriteInt(file,"Psales",0);
INI_WriteInt(file,"Pwep",0);
INI_WriteInt(file,"Ptruck",0);
INI_Close(file);
SendClientMessage(playerid,-1,"You have been successfully registered");
}
}
if(dialogid == dlogin)
{
if(response)
{
new hashpass[129];
WP_Hash(hashpass,sizeof(hashpass),inputtext);
if(!strcmp(hashpass,PlayerInfo[playerid][Ppassword]))
{
INI_ParseFile(Path(playerid),"loadaccount_user",.bExtra = true, .extra = playerid);
SetPlayerScore(playerid,PlayerInfo[playerid][Pscore]);
GivePlayerMoney(playerid,PlayerInfo[playerid][Pmoney]);
SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");
}
else
{
ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_PASSWORD,"Login","Welcome back. This account is registered. \nInsert your password to login to your account.\nIncorrect password!","Login","Quit");//We will tell to them that they've entered an incorrect password
return 1;
}
}
}
return 1;
}