[This is extra i added You can read it if you want its at the bottom
]
#include <a_samp> #include <YSI\y_ini> #include <sscanf2> #include <zcmd>
#define DIALOG_REGISTER 1 //This is the dialog which will be shown if the player isn't registered #define DIALOG_LOGIN 2 // This will be shown if he is registered
#define PATH "/MyAdmin/%s.ini"// This is the saving path Means All the Player Data Will be saved inside the scriptfiles folder in MyAdmin Folder You can change that to whatever folder you want
//COLORS :-
#define WHITE "{FFFFFF}"
#define GREEN "{00F700}"
#define BLUE "{00A3FF}"
#define RED "{E10000}"
#define ORANGE "{FF7E19}"
#define YELLOW "{FF9E00}"
#define DBLUE "{3300CC}"
#define SCM SendClientMessage #define SCMTA SendClientMessageToAll // I ALSO DEFINED SENDCLIENTMESSAGETOALL :)
enum pInfo
{
pPass,// This will be the player's Password
pCash,//The Player's Money Will also Be stored
pAdmin,//This is main the admin level of the player
pScore,//The Player's Score
// pXP,// I have commented this .. This will be the player's XP.. If you wanna use it just uncomment it :P
}
new PlayerInfo[MAX_PLAYERS][pInfo];// this will be used later :)
to hash Passwords :P stock UserPath(playerid)
{
new string[128],playername[MAX_PLAYER_NAME];// Here We will get the player's name and format the file to his name
GetPlayerName(playerid,playername,sizeof(playername));//Like If I connect to your server In your scriptfiles Folder There will be a file like Rockhopper in MyAdmin folder
format(string,sizeof(string),PATH,playername);
return string;
}
stock udb_hash(buf[]) {
new length=strlen(buf);//Here we will shuffle the player's password So that its prevented from Being rob :P
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[]);
forward AutoSave (playerid);
//The Callbacks
public LoadUser_data(playerid,name[],value[])
{
INI_Int("Password",PlayerInfo[playerid][pPass]);//The player's Pass
INI_Int("Cash",PlayerInfo[playerid][pCash]);// CAsh
INI_Int("Admin",PlayerInfo[playerid][pAdmin]);//Admin Level
INI_Int("Score",PlayerInfo[playerid][pScore]);//Score
// INI_Int("XP",PlayerInfo[playerid][pXP]);//Again I have Commented This Uncomment if you are using It
return 1;
}
public AutoSave(playerid)
{
if(fexist(UserPath(playerid)))// We will check if the Player is Registered If yes we will continue
{
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));//Money
INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);//Admin level
INI_WriteInt(File,"Score",GetPlayerScore(playerid));//Score
INI_WriteInt(File,"XP",PlayerInfo[playerid][pXP]);//Uncomment if you are using
INI_Close(File);
SCMTA(COLOR_GREEN, "Server has saved all logged in accounts ");
SCMTA(COLOR_GREEN, "Server has saved all logged in accounts ");// This we will send message to all That Server Has saved All Account
}
SetTimer("AutoSave", 300000, true); // 5 Minutes :P
if(fexist(UserPath(playerid)))//If the file exists Player will get login dialog
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""WHITE"Login",""WHITE"Type your password below to login.","Login","Quit");//Please Read This Below
}
else//If Not Register :P
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""WHITE"Registering...",""WHITE"Type your password below to register a new account.","Register","Quit");//This too :)
}
""WHITE"Login",""WHITE"Type your password
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));//Money
INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);//Admin level
INI_WriteInt(File,"Score",GetPlayerScore(playerid));//Score
INI_WriteInt(File,"XP",PlayerInfo[playerid][pXP]);//Uncomment if you are using
INI_Close(File);
Two boys were arguing when the teacher entered the room. The teacher says, "Why are you arguing?" One boy answers, "We found a ten dollor bill and decided to give it to whoever tells the biggest lie." "You should be ashamed of yourselves," said the teacher, "When I was your age I didn't even know what a lie was." The boys gave the ten dollars to the teacher. xD
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch( dialogid )// We will Switch dialog ids
{
case DIALOG_REGISTER://If it is the register Dialog then we will continue
{
if (!response) return Kick(playerid);// if the player Selects The Second Option in dialog that is Quit He will be kick :P
if(response)// If he presses register
{
if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");// Here if the player leaves the password blank Like A Dick We will show him the dialog Again ... LoL
new INI:File = INI_Open(UserPath(playerid));// If he is done with registering we will make a new file
INI_SetTag(File,"data");
INI_WriteInt(File,"Password",udb_hash(inputtext));// Here we will write his pass but it will be hashed
INI_WriteInt(File,"Cash",0);// We will set the player's money to 0 Lol
INI_WriteInt(File,"Admin",0);// Admin level to 0
INI_WriteInt(File,"Score",0);//Score to 0
// INI_WriteInt(File,"XP",0);//XP to 0 . Uncomment if you are using it
INI_Close(File);// We will close the file
// Here if you want you can send client message that the player is registered
}
}
case DIALOG_LOGIN:// If the Dialog is Of login
{
if ( !response ) return Kick ( playerid );// same as of Registering quit = Kick xD
if( response )//If he presses Login
{
if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])// If the saved Pass Is the same What The player typed In Other Words If if types the correct pass
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);// We will load the user's Account Through our Callback We made Before :P
GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);//We will give the player's Money to him :P
}
else// Else if he types the wrong pass
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Quit");// We will show him incorrect pass dialog and ask him to type his pass again
}
return 1;
}
}
}
return 0;// I have returned 0 So that dialogs In other Script Work Do it :)
}
Congratulations ! CMD:makeadmin(playerid, params[])
{
if(IsPlayerAdmin(playerid) || PlayerInfo[playerid][pAdmin] >= 6)// If the player is rcon admin or Level 6 + Admin it will continue
{
new targetid,integ;
if(sscanf(params,"ui", targetid,integ)) return SendClientMessage(playerid,COLOR_WHITE,""WHITE"Usage: "GREEN"/Makeadmin "WHITE"[playerid] [AdminLevel]");// if the player type /makeadmin this will show him the right usage :P
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid,COLOR_WHITE,"Invalide Player ID"RED"(Player Is Not Connected)!");//If the player isn't Connected It will give the message :)
new INI:File = INI_Open(UserPath(targetid));//It will open the target's File
{
INI_WriteInt(File,"Admin",PlayerInfo[targetid][pAdmin] = integ);// Will set the Admin level the player gave him
INI_Close(File);// Will close the file :P
}
new pname[MAX_PLAYER_NAME],tname[MAX_PLAYER_NAME],str[128],str2[128];//All the names And Strings :)
GetPlayerName(playerid,pname,sizeof(pname));//Get the player's name
GetPlayerName(targetid,tname,sizeof(tname));//Taget's name
format(str,sizeof(str),"ADMIN %s Has Given Player %s Admin Level %d...Congratulations %s",pname,tname,integ,tname);//The string
format(str2,sizeof(str2),"ADMIN %s Has give You Admin Level %d",pname,integ);//Second String
SCMTA(COLOR_GREEN,str);//Message To all
SCM(targetid,COLOR_GREEN,str2);Message To Target
}
return 1;
}
if(PlayerInfo[playerid][pAdmin] >= 1) THIS IS VERY MAIN You just can make cmds like this This Cmd above is for Level 1 And up admins If You dont want level 1 Admins to use it you can Change it to 2 Or 3 Or whatever you want !
To add a player's XP just use PlayerInfo[playerid][pXp] ++ Or to show PlayerInfo[playerid][pXp] This ...
Thanks!
|
Thanks I didn't Know about that Thanks But then too I just wanted to give players an idea of making it Thanks
![]() |