19.07.2014, 05:43
Hi guys I am back :P... Today I will show you all How to make a basic admin/register System With your own commands ...
This Tutorial Will Teach You :-
How to make Admin System
How to make Register/Login System
How to make Command From that
How to make a Xp System ... [This is extra i added You can read it if you want its at the bottom ]
Let's get started :-
So for this you will need the following :-
So first you will need to include those files Like this so That Our Script reads it
So now We Have to make a admin system So We will need enums To store Player Data.. We Will store it in a Folder In Scriptfiles...
For the Register Login System We will Need Dialogs So let's First Define Them...
Now Lets Define The Saving Folder Path And Some Colors.. But Please Note These Colors Which I am Defining Now cant be used as SendClientMessage,playerid, COLOR ----- It cannot be used like this I will show you how it will be used So here :-
Okay so NOW before continuing PLEASE MAKE A FOLDER IN SCRIPTFILES CALLED MyAdmin OR WHATEVER YOU CHANGED THE PATH TO
Ok so lets continue Now I will define SCM That is SendClientMessage So that we can make it short This is not necessary But Do it Because It doesn't Waste Anytime :P So here
So so the main part Read Carefully :P
Now we will make a enum of playerinfo Like this
Okay So This all Should Be Out Of All Callbacks that is top of the script Now just Add this below The Enum :-
Now we will make some functions That are One is our UserPath And second Password Hash to hash Passwords :P
Here :-
We will make some Forwards And Callbacks now ...
One will be to load the user's Data And second Will be AutoSave
Here :-
For Autosave to work You will need To Set this timer In OnFilterscriptInt Or GamemodeInt
now register Login System In OnPlayerConnect Add this :-
Okay so You must have seen In Both Dialogs I have used Something Odd Like this
These are the colors Which i defined They Have to be used like this "Hii "GREEN"I am a fool " So this message will be as Hii I am A fool LoL So this can be used in strings,SendClientMessage,SendClientMessageToAll,D ialogs
Now in OnPlayerDisconnect We will add the same as AutoSave right If you are saying this you are Right :P But we will not add SCMTA And if(fexist(UserPath(playerid))) Because it has to save everyone's Account :P :-
Time for DIALOG ... Well Im really bored now so lets Crack A Joke :P
Had A laugh ? Maybe Not Lets continue Time for OnDialogResponse
So we will add this there :-
We Are done with the register/login System Congratulations !
Now we will make Admin System I will just make not make any Command to show you how to do it But I will Show you how to do it So that You can learn it ... I will only show a /makeadmin Command
Here Read it carefully :P
Sorry For A less explanation here LoL It was understandable But the main stuff Here is how to make more admin commands ? Here it is
THE XP SYSTEM :-
Basically i have just commented XP System Everywhere You can uncomment it if you want To add a player's XP just use PlayerInfo[playerid][pXp] ++ Or to show PlayerInfo[playerid][pXp] This ...
Thanks To ALL for reading I hope I may have helped you not a lot But At least A Little : ) If you find any difficulties you can post it here Thanks!
This Tutorial Will Teach You :-
How to make Admin System
How to make Register/Login System
How to make Command From that
How to make a Xp System ... [This is extra i added You can read it if you want its at the bottom ]
Let's get started :-
So for this you will need the following :-
- y_ini:- Credits To ******:- https://sampforum.blast.hk/showthread.php?tid=175565
- zcmd:- Credits To Zeex :- https://sampforum.blast.hk/showthread.php?tid=91354
- sscanf:- Credits To ******:- https://sampforum.blast.hk/showthread.php?tid=120356
So first you will need to include those files Like this so That Our Script reads it
Код:
#include <a_samp> #include <YSI\y_ini> #include <sscanf2> #include <zcmd>
For the Register Login System We will Need Dialogs So let's First Define Them...
Код:
#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}"
Ok so lets continue Now I will define SCM That is SendClientMessage So that we can make it short This is not necessary But Do it Because It doesn't Waste Anytime :P So here
Код:
#define SCM SendClientMessage #define SCMTA SendClientMessageToAll // I ALSO DEFINED SENDCLIENTMESSAGETOALL :)
Now we will make a enum of playerinfo Like this
Код:
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 :)
Here :-
Код:
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; }
One will be to load the user's Data And second Will be AutoSave
Here :-
Код:
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
Now in OnPlayerDisconnect We will add the same as AutoSave right If you are saying this you are Right :P But we will not add SCMTA And if(fexist(UserPath(playerid))) Because it has to save everyone's Account :P :-
Код:
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
So we will add this there :-
Код:
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 :) }
Now we will make Admin System I will just make not make any Command to show you how to do it But I will Show you how to do it So that You can learn it ... I will only show a /makeadmin Command
Here Read it carefully :P
Код:
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 !
Basically i have just commented XP System Everywhere You can uncomment it if you want To add a player's XP just use PlayerInfo[playerid][pXp] ++ Or to show PlayerInfo[playerid][pXp] This ...
Thanks To ALL for reading I hope I may have helped you not a lot But At least A Little : ) If you find any difficulties you can post it here Thanks!