PHP код:
enum pInfo
{
pPass,
pCash,
pAdmin,
pKills,
pDeaths,
pSkin,
pBan,
pScore,
pPolice,
pGender
}
new PlayerInfo[MAX_PLAYERS][pInfo];
PHP код:
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
INI_Int("Password",PlayerInfo[playerid][pPass]);
INI_Int("Cash",PlayerInfo[playerid][pCash]);
INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
INI_Int("Kills",PlayerInfo[playerid][pKills]);
INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
INI_Int("Skin",PlayerInfo[playerid][pSkin]);
INI_Int("Ban",PlayerInfo[playerid][pBan]);
INI_Int("Score",PlayerInfo[playerid][pScore]);
INI_Int("Police",PlayerInfo[playerid][pPolice]);
INI_Int("Gender",PlayerInfo[playerid][pGender]);
return 1;
}
PHP код:
stock UserPath(playerid)
{
new string[128],playername[MAX_PLAYER_NAME];
GetPlayerName(playerid,playername,sizeof(playername));
format(string,sizeof(string),PATH,playername);
return string;
}
PHP код:
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;
}
PHP код:
public OnPlayerConnect(playerid)
{
if(PlayerInfo[playerid][pBan] != 0)
{
SendClientMessage(playerid, COLOR_BLUE, "You are banned from the server");
SendClientMessage(playerid, COLOR_BLUE, "Try to contact one from our admins");
SetTimerEx("KickDelay", 3000, false, "i", playerid);
}
else
{
new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
format(string, sizeof(string), "%s has joined the server.", name);
SendClientMessageToAll(COLOR_GRAY, string);
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");
}
else
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""COL_WHITE"Register",""COL_WHITE"Type your password below to register a new account.","Register","Quit");
}
}
SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
return 1;
}
PHP код:
public OnPlayerDisconnect(playerid, reason)
{
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
INI_WriteInt(File,"Skin",GetPlayerSkin(playerid));
INI_WriteInt(File,"Ban",PlayerInfo[playerid][pBan]);
INI_WriteInt(File,"Score",GetPlayerScore(playerid));
INI_WriteInt(File,"Police",PlayerInfo[playerid][pPolice]);
INI_WriteInt(File,"Gender",PlayerInfo[playerid][pGender]);
INI_Close(File);
return 1;
}
PHP код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch( dialogid )
{
case DIALOG_REGISTER:
{
if(!response)
{
Kick(playerid);
if(fexist(UserPath(playerid)))
{
fremove(UserPath(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",10000);
INI_WriteInt(File,"Admin",0);
INI_WriteInt(File,"Kills",0);
INI_WriteInt(File,"Deaths",0);
INI_WriteInt(File,"Skin",0);
INI_WriteInt(File,"Ban",0);
INI_WriteInt(File,"Score",0);
INI_WriteInt(File,"Police",0);
INI_WriteInt(File,"Gender",0);
INI_Close(File);
ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success",""COL_GREEN"You have registerd successfully","Start","");
}
}
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"You have logged in successfully","Start","");
}
else
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",COL_RED"Invalid Paswword","Login","Close");
}
}
}
case DIALOG_GENDER:
{
if(!response)
{
Kick(playerid);
if(fexist(UserPath(playerid)))
{
fremove(UserPath(playerid));
}
}
if(response)
{
new randommale = maleSkins[random(sizeof(maleSkins))];
new randomfemale = femaleSkins[random(sizeof(femaleSkins))];
switch(listitem)
{
case 0:
{
SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
SetPlayerSkin(playerid, randommale);
ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success",""COL_GREEN"You have registered successfully","Start","");
GivePlayerMoney(playerid, 10000);
PlayerInfo[playerid][pGender] = 1;
}
case 1:
{
SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
SetPlayerSkin(playerid, randomfemale);
ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success",""COL_GREEN"You have registered successfully","Start","");
GivePlayerMoney(playerid, 10000);
PlayerInfo[playerid][pGender] = 2;
}
}
}
}
}
return 1;
}
PHP код:
CMD:mpolice(playerid, params[])
{
new targetid;
new level;
new malepoliceskin = policeskin[random(sizeof(policeskin))];
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_RED, "This player is not connected");
if(PlayerInfo[playerid][pAdmin] < 1) return SendClientMessage(playerid, COLOR_RED, "You can't use this command");
if(sscanf(params,"ui", targetid, level)) return SendClientMessage(playerid, COLOR_WHITE,"Usage: /mpolice [id] [Level]");
PlayerInfo[playerid][pPolice] = level;
if(PlayerInfo[targetid][pGender] = 1)
{
SetPlayerSkin(targetid, malepoliceskin);
}
else
{
SetPlayerSkin(targetid, 93);
}
new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
format(string, sizeof(string), "%s's police level has changed", name);
SendClientMessageToAll(COLOR_GREEN, string);
return 1;
}