[Player Account] Password = 306643852 Cash = 35061 Scores = 5 Admin Level = 0 VIP Level = 0 Kills = 0 Deaths = 0 Admin Level = 0 VIP Level = 0 |
public OnPlayerDisconnect(playerid, reason)
{
new INI:File = INI_Open(UserPath(playerid));
new sztring[3000];
format(sztring,sizeof(sztring),"%s Account",PlayerName(playerid));
INI_SetTag(File, sztring);
INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
INI_WriteInt(File,"Scores",GetPlayerScore(playerid));
INI_WriteInt(File,"Admin Level",pInfo[playerid][pLevel]);
INI_WriteInt(File,"VIP Level",pInfo[playerid][pVIP]);
INI_WriteInt(File,"Kills",pInfo[playerid][pKills]);
INI_WriteInt(File,"Deaths",pInfo[playerid][pDeaths]);
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))
{
new sztring[3000];
format(sztring,sizeof(sztring),""COL_YELLOW"Hello {FF0000}%s"COL_YELLOW", welcome to the server!\n\n"COL_YELLOW"Please type your password to register to the server and continue\n{FF0000}NOTE: "COL_YELLOW"Don't give your password to other players even server administrators.",PlayerName(playerid));
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,"Account Register", sztring,"Register","Quit");
}
new INI:File = INI_Open(UserPath(playerid));
new sztring[3000];
format(sztring,sizeof(sztring),"%s Account",PlayerName(playerid));
INI_SetTag(File,sztring);
INI_WriteInt(File,"Password",udb_hash(inputtext));
INI_WriteInt(File,"Cash",0);
INI_WriteInt(File,"Scores",0);
INI_WriteInt(File,"Admin Level",0);
INI_WriteInt(File,"VIP Level",0);
INI_WriteInt(File,"Kills",0);
INI_WriteInt(File,"Deaths",0);
INI_Close(File);
new stzring[3000];
format(stzring,sizeof(stzring),""COL_YELLOW"Hello {FF0000}%s\n"COL_YELLOW"You have succesuflly registered your account.\n\nWelcome to Call of Duty - Battlefield Server !", PlayerName(playerid));
ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,"Account Info", stzring,"Ok","");
}
}
case DIALOG_LOGIN:
{
if ( !response ) return Kick ( playerid );
if( response )
{
if(udb_hash(inputtext) == pInfo[playerid][pPass])
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
GivePlayerMoney(playerid, pInfo[playerid][pMoney]);
SetPlayerScore(playerid, pInfo[playerid][pScores]);
new stzring[3000];
format(stzring,sizeof(stzring),""COL_YELLOW"Hello {FF0000}%s\n"COL_YELLOW"You have succesuflly login to your account.\n\n"COL_YELLOW"Admin Level: "COL_LIGHTBLUE"%d\n"COL_YELLOW"VIP Level: "COL_LIGHTBLUE"%d\n\n"COL_YELLOW"For more status, please type /stats command.", PlayerName(playerid), pInfo[playerid][pLevel], pInfo[playerid][pVIP]);
ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,"Account Info", stzring,"Ok","");
}
else
{
new sztring[3000];
format(sztring,sizeof(sztring),""COL_YELLOW"Hello {FF0000}%s"COL_YELLOW", welcome back to the server!\n\n"COL_YELLOW"Please type your password to login to the server and continue\n"COL_YELLOW"If you are not owner of this account please click {FF0000}'Quit' "COL_YELLOW"and choose a new name.\n"COL_RED"You have typed an incorrect password.",PlayerName(playerid));
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Authenticate", sztring,"Login","Quit");
}
return 1;
}
}
}
return true;
}
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
INI_Int("Password", pInfo[playerid][pPass]);
INI_Int("Cash", pInfo[playerid][pMoney]);
INI_Int("Scores", pInfo[playerid][pScores]);
INI_Int("Admin Level", pInfo[playerid][pLevel]);
INI_Int("VIP Level", pInfo[playerid][pVIP]);
INI_Int("Kills", pInfo[playerid][pKills]);
INI_Int("Deaths", pInfo[playerid][pDeaths]);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
new INI:File = INI_Open(UserPath(playerid));
new sztring[3000];
format(sztring,sizeof(sztring),"%s Account",PlayerName(playerid));
INI_SetTag(File, sztring);
INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
INI_WriteInt(File,"Scores",GetPlayerScore(playerid));
INI_WriteInt(File,"Admin Level",pInfo[playerid][pLevel]);
INI_WriteInt(File,"VIP Level",pInfo[playerid][pVIP]);
INI_WriteInt(File,"Kills",pInfo[playerid][pKills]);
INI_WriteInt(File,"Deaths",pInfo[playerid][pDeaths]);
INI_Close(File);
return 1;
}
if(fexist(UserPath(playerid)))
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
new sztring[3000];
GetPlayerName(playerid,pname,sizeof(pname));
format(sztring,sizeof(sztring),""COL_YELLOW"Hello {FF0000}%s"COL_YELLOW", welcome back to the server!\n\n"COL_YELLOW"Please type your password to login to the server and continue\n"COL_YELLOW"If you are not the owner of this account, please click {FF0000}'Quit'"COL_YELLOW" and use a new name.",PlayerName(playerid));
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Authenticate", sztring,"Login","Quit");
}
else
{
new sztring[3000];
GetPlayerName(playerid,pname,sizeof(pname));
format(sztring,sizeof(sztring),""COL_YELLOW"Hello {FF0000}%s"COL_YELLOW", welcome to the server!\n\n"COL_YELLOW"Please type your password to register to the server and continue\n{FF0000}NOTE: "COL_YELLOW"Don't give your password to other players even server administrators.",PlayerName(playerid));
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,"Account Register", sztring,"Register","Quit");
}
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;
}
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
INI_Int("Password", pInfo[playerid][pPass]);
INI_Int("Cash", pInfo[playerid][pMoney]);
INI_Int("Scores", pInfo[playerid][pScores]);
INI_Int("Admin Level", pInfo[playerid][pLevel]);
INI_Int("VIP Level", pInfo[playerid][pVIP]);
INI_Int("Kills", pInfo[playerid][pKills]);
INI_Int("Deaths", pInfo[playerid][pDeaths]);
return 1;
}
#define PATH "Folder/Users/%s.ini"
When it's set to [3000], it's set to store 3000 characters (it's actually more technical than that afaik, but the reasoning is roughly the same). If you're not using up that 3000 character limit, it's very inefficient and can slow your script down. "%s Account" is only going to be a maximum of 32 characters long, so it only need to be set to [32]. If [32] giving you errors, then just change it to [33].
|