25.01.2013, 18:26
Basic Admin mode!
Introduction »- Today I will show you how make a basic admin mode.
- It's very easy, we work with dfile functions and variables.
- Enjoy and good luck, sorry of my English
Type of Use »
The Type of Use this basic admin mode is:
* Player was admin level 0 connect to server.
* The rcon admin set him admin level 3.
* The admin level didn't write In the user file, he Is In variable.
* The new admin disconnected from the server, and the admin level write In the user file.
- The player connect again to the server and the server read the admin level from the file and Set the value In the variable.
- I can check if the player admin like that:
Код:
if(AdminLevel[playerid] < 1) return false;
• First we are open a new file In the pawn [Ctrl+N].
After we are open the new file, we need the setting variables of the admin mode just one variable:
Код:
new AdminLevel[MAX_PLAYERS];
Now we create the public OnPlayerConnect If you have one dont create!
Код:
public OnPlayerConnect(playerid) { return 1; }
Код:
stock Name(playerid) { new PlayerName[MAX_PLAYER_NAME]; GetPlayerName(playerid,PlayerName,sizeof(PlayerName)); return PlayerName; }
Код:
stock AFile(playerid) { new PlayerFile[15+MAX_PLAYER_NAME]; format(PlayerFile,sizeof(PlayerFile),"Admins/%s.ini",Name(playerid)); return PlayerFile; }
Ok, we back to OnPlayerConnect event, now check if the player have a user file In: "Admins" folder:
Код:
if(!fexist(AFile(playerid))) { //didn't have. } else { //have. }
If the player did have a user in the admins folder he have admin and the server read the level and put him on the variable AdminLevel like that:
Код:
dfile_Open(AFile(playerid)); AdminLevel[playerid] = dfile_ReadInt("Admin_Level"); dfile_Close();
Now we dont need open file and close again and again just using with the variable
Ok, so whats happens if the player disconnected from the server?
First we create public OnPlayerDisconnect like that:
Код:
public OnPlayerDisconnect(playerid,reason) { return 1; }
Код:
if(fexist(AFile(playerid))) { dfile_Open(AFile(playerid)); dfile_WriteInt("Admin_Level",AdminLevel[playerid]); dfile_SaveFile(),dfile_CloseFile(); }
If you want create command for level three In the admin, just check if him admin like this:
Код:
if(!strcmp(cmdtext,"/Say",true)) { if(AdminLevel[playerid] < 3) return SendClientMessage(playerid,color,"[ERROR]: You need Admin level #3!"); //Command, whats happend If player admin?. return 1; }
Pastebin Finish Guide »
- Pastebin: http://pastebin.com/mhHi2n9g
- THE END -