[Tutorial] Make basic admin mode (dfile functions)
#1

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;
Let's start scripting! »

• 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];
You can add the variable to your enum if you want, beacuse it's just one variable I set him with new!
Now we create the public OnPlayerConnect If you have one dont create!
Код:
public OnPlayerConnect(playerid)
{
    return 1;
}
Now we create a three functions (Name & AFile & GetValue):
Код:
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;
}
If you have this functions you don't need create him, You can write the admin level In the main user file!
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 didn't have a user in the Admins folder he not admin!
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();
If the user of player In the Admins folder, the server open that and take the level and set him on AdminLevel variable.
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;
}
After we check if the player have a user file In the admins folder, and put the AdminLevel value to line "Admin_Level" like that:
Код:
if(fexist(AFile(playerid)))
{
    dfile_Open(AFile(playerid));
    dfile_WriteInt("Admin_Level",AdminLevel[playerid]);
    dfile_SaveFile(),dfile_CloseFile();
}
Ok you have some basic admin mode yaaay!
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;
}
• If you want set a new admin just open user file for him In "Admins" folder and put the AdminLevel=number?

Pastebin Finish Guide »

- Pastebin: http://pastebin.com/mhHi2n9g

- THE END -
Reply
#2

What is ti for?
Reply
#3

Quote:
Originally Posted by Lauder
Посмотреть сообщение
What is ti for?
What?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)