SA-MP Forums Archive
[Tutorial] How to create an Admin Filterscript w/ commands ! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] How to create an Admin Filterscript w/ commands ! (/showthread.php?tid=253481)

Pages: 1 2


How to create an Admin Filterscript w/ commands ! - Hipflop - 06.05.2011

Hi all!

I decided to edit the whole tutorial, because I made a new server. In this tutorial were a few bugs so here is the new one!

Supplies
For this tutorial you need 2 includes. Click on the names for the download link.
Dini
Dutils

When you downloaded the includes, put them in the pawno/include folder. If you don't know where that is, read further.

Tutorial
Ok, when you download your server from the http://www.sa-mp.com/download.php page, you got a zip file. Unzip it and place it anywhere you want.

In the root folder is a map called pawno, open it and open pawno.exe. This is the program that we're going to use to make our own server.

If you opened pawno, you press Control + N, or click File > New. When you did, you see a lot of codes. As we're making a filterscript, we are not going to use them all, so select them all (Control + A) and delete them. Now we have a clean sheet to begin with.

First of all, you need functions. Those functions are included in a file called a_samp. So we need to include that file into our script. We are doing this with the following code:

pawn Code:
#include <a_samp>
#include <dini>
#include <dutils>
As you see, i also added the 2 includes we just downloaded before.

To see if we got any errors or warnings, we compile this. Hit the F5 button or press the button left of the blue arrow. When you did, we see that we got 1 warning. To get rid of the warning we use the next code.

pawn Code:
#pragma unused ret_memcpy
If you compile it again, it gives no warning anymore.

As we make a filterscript, we need to say that to the script. We do that with the code:

pawn Code:
#define FILTERSCRIPT
#if defined FILTERSCRIPT
We say to the server that this is a filterscript. The second line tells the server that if this script is a filterscript then we do this ... But this will come next.

In this tutorial, I also make some example commands with DCMD. It's a faster way to use commands then the strcmp functions. The code for this is:

pawn Code:
#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
I don't exactly know what it does, but it works so we don't edit it.
We put this code underneath the #if defi.... line.

Then we are going to define some colors. As I use all the colors we have in my script, I'm also going to post them all, so here they are:

pawn Code:
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_ACTIVEBORDER 0xB4B4B4FF
#define COLOR_ACTIVECAPTION 0x99B4D1FF
#define COLOR_ACTIVECAPTIONTEXT 0x000000FF
#define COLOR_ALICEBLUE 0xF0F8FFFF
#define COLOR_ANTIQUEWHITE 0xFAEBD7FF
#define COLOR_APPWORKSPACE 0xABABABFF
#define COLOR_AQUA 0x00FFFFFF
#define COLOR_AQUAMARINE 0x7FFFD4FF
#define COLOR_AZURE 0xF0FFFFFF
#define COLOR_BEIGE 0xF5F5DCFF
#define COLOR_BISQUE 0xFFE4C4FF
#define COLOR_BLACK 0x000000FF
#define COLOR_BLANCHEDALMOND 0xFFEBCDFF
#define COLOR_BLUE 0x0000FFFF
#define COLOR_BLUEVIOLET 0x8A2BE2FF
#define COLOR_BROWN 0xA52A2AFF
#define COLOR_BURLYWOOD 0xDEB887FF
#define COLOR_BUTTONFACE 0xF0F0F0FF
#define COLOR_BUTTONHIGHLIGHT 0xFFFFFFFF
#define COLOR_BUTTONSHADOW 0xA0A0A0FF
#define COLOR_CADETBLUE 0x5F9EA0FF
#define COLOR_CHARTREUSE 0x7FFF00FF
#define COLOR_CHOCOLATE 0xD2691EFF
#define COLOR_CONTROL 0xF0F0F0FF
#define COLOR_CONTROLDARK 0xA0A0A0FF
#define COLOR_CONTROLDARKDARK 0x696969FF
#define COLOR_CONTROLLIGHT 0xE3E3E3FF
#define COLOR_CONTROLLIGHTLIGHT 0xFFFFFFFF
#define COLOR_CONTROLTEXT 0x000000FF
#define COLOR_CORAL 0xFF7F50FF
#define COLOR_CORNFLOWERBLUE 0x6495EDFF
#define COLOR_CORNSILK 0xFFF8DCFF
#define COLOR_CRIMSON 0xDC143CFF
#define COLOR_CYAN 0x00FFFFFF
#define COLOR_DARKBLUE 0x00008BFF
#define COLOR_DARKCYAN 0x008B8BFF
#define COLOR_DARKGOLDENROD 0xB8860BFF
#define COLOR_DARKGRAY 0xA9A9A9FF
#define COLOR_DARKGREEN 0x006400FF
#define COLOR_DARKKHAKI 0xBDB76BFF
#define COLOR_DARKMAGENTA 0x8B008BFF
#define COLOR_DARKOLIVEGREEN 0x556B2FFF
#define COLOR_DARKORANGE 0xFF8C00FF
#define COLOR_DARKORCHID 0x9932CCFF
#define COLOR_DARKRED 0x8B0000FF
#define COLOR_DARKSALMON 0xE9967AFF
#define COLOR_DARKSEAGREEN 0x8FBC8BFF
#define COLOR_DARKSLATEBLUE 0x483D8BFF
#define COLOR_DARKSLATEGRAY 0x2F4F4FFF
#define COLOR_DARKTURQUOISE 0x00CED1FF
#define COLOR_DARKVIOLET 0x9400D3FF
#define COLOR_DEEPPINK 0xFF1493FF
#define COLOR_DEEPSKYBLUE 0x00BFFFFF
#define COLOR_DESKTOP 0x000000FF
#define COLOR_DIMGRAY 0x696969FF
#define COLOR_DODGERBLUE 0x1E90FFFF
#define COLOR_FIREBRICK 0xB22222FF
#define COLOR_FLORALWHITE 0xFFFAF0FF
#define COLOR_FORESTGREEN 0x228B22FF
#define COLOR_FUCHSIA 0xFF00FFFF
#define COLOR_GAINSBORO 0xDCDCDCFF
#define COLOR_GHOSTWHITE 0xF8F8FFFF
#define COLOR_GOLD 0xFFD700FF
#define COLOR_GOLDENROD 0xDAA520FF
#define COLOR_GRADIENTACTIVECAPTION 0xB9D1EAFF
#define COLOR_GRADIENTINACTIVECAPTION 0xD7E4F2FF
#define COLOR_GRAY 0x808080FF
#define COLOR_GRAYTEXT 0x808080FF
#define COLOR_GREEN 0x008000FF
#define COLOR_GREENYELLOW 0xADFF2FFF
#define COLOR_HIGHLIGHT 0x3399FFFF
#define COLOR_HIGHLIGHTTEXT 0xFFFFFFFF
#define COLOR_HONEYDEW 0xF0FFF0FF
#define COLOR_HOTPINK 0xFF69B4FF
#define COLOR_HOTTRACK 0x0066CCFF
#define COLOR_INACTIVEBORDER 0xF4F7FCFF
#define COLOR_INACTIVECAPTION 0xBFCDDBFF
#define COLOR_INACTIVECAPTIONTEXT 0x434E54FF
#define COLOR_INDIANRED 0xCD5C5CFF
#define COLOR_INDIGO 0x4B0082FF
#define COLOR_INFO 0xFFFFE1FF
#define COLOR_INFOTEXT 0x000000FF
#define COLOR_IVORY 0xFFFFF0FF
#define COLOR_KHAKI 0xF0E68CFF
#define COLOR_LAVENDER 0xE6E6FAFF
#define COLOR_LAVENDERBLUSH 0xFFF0F5FF
#define COLOR_LAWNGREEN 0x7CFC00FF
#define COLOR_LEMONCHIFFON 0xFFFACDFF
#define COLOR_LIGHTBLUE 0xADD8E6FF
#define COLOR_LIGHTCORAL 0xF08080FF
#define COLOR_LIGHTCYAN 0xE0FFFFFF
#define COLOR_LIGHTGOLDENRODYELLOW 0xFAFAD2FF
#define COLOR_LIGHTGRAY 0xD3D3D3FF
#define COLOR_LIGHTGREEN 0x90EE90FF
#define COLOR_LIGHTPINK 0xFFB6C1FF
#define COLOR_LIGHTSALMON 0xFFA07AFF
#define COLOR_LIGHTSEAGREEN 0x20B2AAFF
#define COLOR_LIGHTSKYBLUE 0x87CEFAFF
#define COLOR_LIGHTSLATEGRAY 0x778899FF
#define COLOR_LIGHTSTEELBLUE 0xB0C4DEFF
#define COLOR_LIGHTYELLOW 0xFFFFE0FF
#define COLOR_LIME 0x00FF00FF
#define COLOR_LIMEGREEN 0x32CD32FF
#define COLOR_LINEN 0xFAF0E6FF
#define COLOR_MAGENTA 0xFF00FFFF
#define COLOR_MAROON 0x800000FF
#define COLOR_MEDIUMAQUAMARINE 0x66CDAAFF
#define COLOR_MEDIUMBLUE 0x0000CDFF
#define COLOR_MEDIUMORCHID 0xBA55D3FF
#define COLOR_MEDIUMPURPLE 0x9370DBFF
#define COLOR_MEDIUMSEAGREEN 0x3CB371FF
#define COLOR_MEDIUMSLATEBLUE 0x7B68EEFF
#define COLOR_MEDIUMSPRINGGREEN 0x00FA9AFF
#define COLOR_MEDIUMTURQUOISE 0x48D1CCFF
#define COLOR_MEDIUMVIOLETRED 0xC71585FF
#define COLOR_MENU 0xF0F0F0FF
#define COLOR_MENUBAR 0xF0F0F0FF
#define COLOR_MENUHIGHLIGHT 0x3399FFFF
#define COLOR_MENUTEXT 0x000000FF
#define COLOR_MIDNIGHTBLUE 0x191970FF
#define COLOR_MINTCREAM 0xF5FFFAFF
#define COLOR_MISTYROSE 0xFFE4E1FF
#define COLOR_MOCCASIN 0xFFE4B5FF
#define COLOR_NAVAJOWHITE 0xFFDEADFF
#define COLOR_NAVY 0x000080FF
#define COLOR_OLDLACE 0xFDF5E6FF
#define COLOR_OLIVE 0x808000FF
#define COLOR_OLIVEDRAB 0x6B8E23FF
#define COLOR_ORANGE 0xFFA500FF
#define COLOR_ORANGERED 0xFF4500FF
#define COLOR_ORCHID 0xDA70D6FF
#define COLOR_PALEGOLDENROD 0xEEE8AAFF
#define COLOR_PALEGREEN 0x98FB98FF
#define COLOR_PALETURQUOISE 0xAFEEEEFF
#define COLOR_PALEVIOLETRED 0xDB7093FF
#define COLOR_PAPAYAWHIP 0xFFEFD5FF
#define COLOR_PEACHPUFF 0xFFDAB9FF
#define COLOR_PERU 0xCD853FFF
#define COLOR_PINK 0xFFC0CBFF
#define COLOR_PLUM 0xDDA0DDFF
#define COLOR_POWDERBLUE 0xB0E0E6FF
#define COLOR_PURPLE 0x800080FF
#define COLOR_RED 0xFF0000FF
#define COLOR_ROSYBROWN 0xBC8F8FFF
#define COLOR_ROYALBLUE 0x4169E1FF
#define COLOR_SADDLEBROWN 0x8B4513FF
#define COLOR_SALMON 0xFA8072FF
#define COLOR_SANDYBROWN 0xF4A460FF
#define COLOR_SCROLLBAR 0xC8C8C8FF
#define COLOR_SEAGREEN 0x2E8B57FF
#define COLOR_SEASHELL 0xFFF5EEFF
#define COLOR_SIENNA 0xA0522DFF
#define COLOR_SILVER 0xC0C0C0FF
#define COLOR_SKYBLUE 0x87CEEBFF
#define COLOR_SLATEBLUE 0x6A5ACDFF
#define COLOR_SLATEGRAY 0x708090FF
#define COLOR_SNOW 0xFFFAFAFF
#define COLOR_SPRINGGREEN 0x00FF7FFF
#define COLOR_STEELBLUE 0x4682B4FF
#define COLOR_TAN 0xD2B48CFF
#define COLOR_TEAL 0x008080FF
#define COLOR_THISTLE 0xD8BFD8FF
#define COLOR_TOMATO 0xFF6347FF
#define COLOR_TRANSPARENT 0xFFFFFF00
#define COLOR_TURQUOISE 0x40E0D0FF
#define COLOR_VIOLET 0xEE82EEFF
#define COLOR_WHEAT 0xF5DEB3FF
#define COLOR_WHITE 0xFFFFFFFF
#define COLOR_WHITESMOKE 0xF5F5F5FF
#define COLOR_WINDOW 0xFFFFFFFF
#define COLOR_WINDOWFRAME 0x646464FF
#define COLOR_WINDOWTEXT 0x000000FF
#define COLOR_YELLOW 0xFFFF00FF
#define COLOR_YELLOWGREEN 0x9ACD32FF
#define STEALTH_ORANGE 0xFF880000
#define STEALTH_OLIVE 0x66660000
#define STEALTH_GREEN 0x33DD1100
#define STEALTH_PINK 0xFF22EE00
#define STEALTH_BLUE 0x0077BB00
Then last but not least, the PlayerFile define. This is very important because we are going to store playerdata in this file. When we don't want to type the path over and over again, we use the next define:

pawn Code:
#define PlayerFile "Admin/Users/%s.ini"
#define CommandFile "Admin/Settings/Commands.ini"
In your root folder of your server is a map called scriptfiles. There we make a map called 'Admin' and in that map we make a map called 'Users'. And for the other file we do the same. In that file we are going to store the minimum level the player has to be to use that command.

Then, we say to the script that we are done with the #if defined FILTERSCRIPT thingy, we put this underneath the last define

pawn Code:
#endif
Now we are actually beginning to script!

The first function we are making is an enum. This function stores more variables into one variable.
As I said earlier we are going to store userdata. The enum is a good function for this.

What we are going to do is making an enum called PLAYER_MAIN. In that enum we store information like, name, ip address, password, level and money.
The code is going to look like this:

pawn Code:
enum PLAYER_MAIN {
    PLAYER_NAME[MAX_PLAYER_NAME],
    PLAYER_IP[16],
    PLAYER_REGGED,
    PLAYER_PASS,
    PLAYER_LEVEL,
    PLAYER_MONEY,
}
new gPlayerInfo[MAX_PLAYERS][PLAYER_MAIN];
new gPlayerLogged[MAX_PLAYERS];

enum COMMANDS_MAIN {
    KICK,
    BAN
}
new gCommands[COMMANDS_MAIN];
I also made a new variable called gPlayerInfo. We are going to need this to compare some other variables. The MAX_PLAYERS stands for the max players we can use. In this case it is 500. The PLAYER_MAIN stands for the enum above. And we make a variable to check if the player is logged or not. Now i'm doing exactly the same with the commands.

Next we see our first callback. This is called OnFilterScriptInit(). It tells the server what to do when this script is loading.

pawn Code:
public OnFilterScriptInit()
{
    print("\n************************************");
    print("*                                  *");
    print("* Admin Filterscript by Hipflop    *");
    print("*                                  *");
    print("************************************\n");

    // Level 0 = Noob
    // Level 1 = Trusted Player
    // Level 2 = Member
    // Level 3 = Moderator
    // Level 4 = Administrator
    // Level 5 = Server owner

    if(!fexist(CommandFile))
    {
        dini_Create(CommandFile);
        dini_IntSet(CommandFile, "Kick", 2);
        dini_IntSet(CommandFile, "Ban", 3);
    }
   
    gCommands[KICK] = dini_Int(CommandFile, "Kick");
    gCommands[BAN] = dini_Int(CommandFile, "Ban");
    return 1;
}
In this callback we see the print function. It prints the text into the server.
The next thing we see is //. You can use that to comment a line. If you want to comment more lines use /* and */.

Then we got the fexist function. Note the ! in front of it. A ! means no. So it stands for: If the file CommandFile (Look at the define!)does not exist, then perform this action. Then we see the functions dini_.... Now we see your first include who we downloaded. With dini we can make, store, and call information from a file.
Now, if the file CommandFile does not exist we create it with the dini_Create(); command. And we IntSet (IntegerSet) the names Kick with the integer 2 and the name Ban with the integer 3. This is our minimum level the player needs to be to perform that command. When he did that check, he gives the gCommands variable the variable from the file with the dini_Int function. If we did that we return 1; the file to tell him the actions worked.

We then made our first callback. But now it's going to get a little harder.
First we need to check what the server will do when a player connects and disconnects. We do this with the callbacks OnPlayerConnect(playerid) and OnPlayerDisconnect(playerid, reason). First I put the code OnPlayerConnect and I'll explain afterwards.

pawn Code:
public OnPlayerConnect(playerid)
{
    new file[100], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), PlayerFile, name);
    if(!fexist(file))
    {
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Register", "Please fill in your username as a password.", "Register", "Exit");
    }
    else if(fexist(file))
    {
        ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Logon", "Please fill in your password.", "Logon", "Exit");
    }
    return 1;
}
Here we go!
When the player connects we make 2 new variables called file[100] and name[MAX_PLAYER_NAME]. The file can be 100 characters long. We get the name of the player with the function GetPlayerName(playerid, name, sizeof(name)). We store the name of the player in the variable 'name' with this function. That's why we made the variable name. Then we got a weird function called format. This functions formats a variable into another. In this case we format the PlayerFile into his name. So the PlayerFile is the name of the player.
Then we check with the function fexist(file) if the PlayerFile with the name of the player exist. (Note the !).
If the file doesn't exist we show the register dialog, and if the file exist we show the login dialog.

Next thing is what to do if the player disconnects. The code is:

pawn Code:
public OnPlayerDisconnect(playerid, reason)
{
    new file[100];
    format(file, sizeof(file), PlayerFile, gPlayerInfo[playerid][PLAYER_NAME]);
    dini_Set(file, "Name", gPlayerInfo[playerid][PLAYER_NAME]);
    dini_Set(file, "Ip", gPlayerInfo[playerid][PLAYER_IP]);
    dini_IntSet(file, "Registered", gPlayerInfo[playerid][PLAYER_REGGED]);
    dini_IntSet(file, "Password", gPlayerInfo[playerid][PLAYER_PASS]);
    dini_IntSet(file, "Level", gPlayerInfo[playerid][PLAYER_LEVEL]);
    dini_IntSet(file, "Money", GetPlayerMoney(playerid));
    gPlayerLogged[playerid] = 0;
    return 1;
}
The first 2 lines are the name, but in this case we don't need to get the Player's name with the GetPlayerName() function, because we stored it when it logs in (this comes later on). When the player disconnects, we set the variable of the player. When it is text, we use dini_Set. When it is an integer we use dini_IntSet. And last we say that the player is not logged.

Now comes the scripting for the dialogs we got when the player connects.

pawn Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 1)
    {
        if(response)
        {
            if(strlen(inputtext))
            {
                new file[100], name[MAX_PLAYER_NAME], ip[16], string[128];
                GetPlayerName(playerid, name, sizeof(name));
                GetPlayerIp(playerid, ip, sizeof(ip));
                format(file, sizeof(file), PlayerFile, name);
                dini_Create(file);
                dini_Set(file, "Name", name);
                dini_Set(file, "Ip", ip);
                dini_IntSet(file, "Registered", 1);
                dini_IntSet(file, "Password", num_hash(inputtext));
                dini_IntSet(file, "Level", 0);
                dini_IntSet(file, "Money", 50);
                format(string, sizeof(string), "[SYSTEM] You succesfully registered the player %s.", name);
                SendClientMessage(playerid, COLOR_LIGHTGREEN, string);
                strcat(gPlayerInfo[playerid][PLAYER_NAME], dini_Get(file, "Name"));
                strcat(gPlayerInfo[playerid][PLAYER_IP], dini_Get(file, "Ip"));
                gPlayerInfo[playerid][PLAYER_PASS] = dini_Int(file, "Password");
                gPlayerInfo[playerid][PLAYER_LEVEL] = dini_Int(file, "Level");
                GivePlayerMoney(playerid, dini_Int(file, "Money"));
                gPlayerLogged[playerid] = 1;
            }
            else if(!strlen(inputtext))
            {
                SendClientMessage(playerid, COLOR_RED, "[SYSTEM] You must fill in a password!");
                ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Register", "Please fill in your username as a password.", "Register", "Exit");
            }
        }
        else if(!response)
        {
            SendClientMessage(playerid, COLOR_RED, "[SYSTEM] You need to register in order to play!");
            Kick(playerid);
        }
    }
   
    if(dialogid == 2)
    {
        if(response)
        {
            if(strlen(inputtext))
            {
                new file[100], name[MAX_PLAYER_NAME], string[128];
                GetPlayerName(playerid, name, sizeof(name));
                format(file, sizeof(file), PlayerFile, name);
                if(num_hash(inputtext) == dini_Int(file, "Password"))
                {
                    strcat(gPlayerInfo[playerid][PLAYER_NAME], dini_Get(file, "Name"));
                    strcat(gPlayerInfo[playerid][PLAYER_IP], dini_Get(file, "Ip"));
                    gPlayerInfo[playerid][PLAYER_PASS] = dini_Int(file, "Password");
                    gPlayerInfo[playerid][PLAYER_LEVEL] = dini_Int(file, "Level");
                    GivePlayerMoney(playerid, dini_Int(file, "Money"));
                    gPlayerLogged[playerid] = 1;
                    format(string, sizeof(string), "[SYSTEM] Welcome back, %s", name);
                    SendClientMessage(playerid, COLOR_LIGHTGREEN, string);
                }
                else if(num_hash(inputtext) != dini_Int(file, "Password"))
                {
                    SendClientMessage(playerid, COLOR_RED, "[SYSTEM] Wrong password!");
                    ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Logon", "Please fill in your password.", "Logon", "Exit");
                }
            }
            else if(!strlen(inputtext))
            {
                SendClientMessage(playerid, COLOR_RED, "[SYSTEM] You must fill in your password!");
                ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Logon", "Please fill in your password.", "Logon", "Exit");
            }
        }
        else if(!response)
        {
            SendClientMessage(playerid, COLOR_RED, "[SYSTEM] You need to logon in order to play!");
            Kick(playerid);
        }
    }
    return 1;
}
The first thing we got is if(dialogid == 1). The number 1 is looking to the number we typed at the ShowPlayerDialog() function. In this case the 1 is for the registering.
The next is the check if the player responsed to the dialog yes or no. Then we check if they filled something in. If so, we again make the variable file and name. This time we also make the variables ip and string. Ip goes exactly the same way as name, so I don't explain. With a string we can type some text with some variables in it. More later.
Next is the script making the file for the player. The password is num_hash. This means that it can't be seen by the server owner. It's been seen as integers. Then the string. It says welcome back %s. With the %s we can use the player's name. We do that with the format() function. As you can see we use the variable name to store it in the %s. Then we send the player a message with the color lightgreen that it is been succesfully registered. Then we get the variables from the file so that we can use it in-game. And at last we say that the player is logged.

Then we got the else. It tells that if the player hasn't filled anything in. We say to the player that he must fill in something and shows the dialog again.
If the player didn't respond to the dialog, we kick the player from the server.


Then the login dialog. It's actually based on the same thing, the only extra is that we check if the password the player fills in is the same as in the file.


As I got more requests on how to make some commands. I'll explain this in the next section of the tutorial.

Commands
First of all, we need to say to the server that there are some commands active. We do this in the OnPlayerCommandText(playerid, cmdtext[]) callback.

pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(kick, 4, cmdtext);
    dcmd(ban, 3, cmdtext);
    return 0;
}
You remember the define that I don't know what it does? It stands for the dcmd commands. As you can see I made to commands: Kick and Ban. The next is the length of the command. As you can see is kick 4 characters long and ban 3 characters. And last is to make sure it's a cmd.

Now we begin with the kick command. It's a lot of scripting so I put the code first, then I'll explain.

pawn Code:
dcmd_kick(playerid, params[])
{
    if(gPlayerInfo[playerid][PLAYER_LEVEL] < gCommands[KICK])
    {
        new string[128];
        format(string, sizeof(string), "You must be a level %d administrator to use that command!", gCommands[KICK]);
        SendClientMessage(playerid, COLOR_ORANGE, string);
    }
    else
    {
        new tmp[256], tmp2[256], index, id;
        tmp = strtok(params, index);
        tmp2 = strtok(params, index);
       
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_ORANGE, "[KICK] Usage: /kick [ID] [REASON]");
        }
        else if(!strlen(tmp2))
        {
            SendClientMessage(playerid, COLOR_ORANGE, "[KICK] Usage: /kick [ID] [REASON]");
        }
        else
        {
            id = strval(tmp);
            if(!IsPlayerConnected(id))
            {
                SendClientMessage(playerid, COLOR_ORANGE, "[KICK] That player is not connected.");
            }
            else if(id == playerid)
            {
                SendClientMessage(playerid, COLOR_ORANGE, "[KICK] You can't kick yourself.");
            }
            else if(gPlayerInfo[id][PLAYER_LEVEL] > gPlayerInfo[playerid][PLAYER_LEVEL])
            {
                SendClientMessage(playerid, COLOR_ORANGE, "[KICK] That player has a higher level than you.");
            }
            else
            {
                new string[256], name[MAX_PLAYER_NAME];
                GetPlayerName(id, name, sizeof(name));
                if(id >= 0 && id <= 9)
                {
                    format(string, sizeof(string), "[KICK] You have been kicked. Reason: %s.", params[2]);
                    SendClientMessage(id, COLOR_ORANGE, string);
                    Kick(id);
                    format(string, sizeof(string), "[KICK] Player %s has been kicked. Reason: %s.", name, params[2]);
                    SendClientMessageToAll(COLOR_ORANGE, string);
                }
                else if(id >= 10 && id <= 99)
                {
                    format(string, sizeof(string), "[KICK] You have been kicked. Reason: %s.", params[3]);
                    SendClientMessage(id, COLOR_ORANGE, string);
                    Kick(id);
                    format(string, sizeof(string), "[KICK] Player %s has been kicked. Reason: %s.", name, params[3]);
                    SendClientMessageToAll(COLOR_ORANGE, string);
                }
            }
        }
    }
    return 1;
}
The first thing we do, is to check if the player's level is high enough to use the command. If it isn't we tell it with a string. We put the level you need in the message with format. Then we send the message to the player.
If the player's level is high enough, then we go on. Now a tricky part.

We make 4 new variables: tmp, tmp2, index and id.
then we say that tmp is strtok(params, index).
The strtok function checks if there is a value behind a space. In this case, behind the /kick.
We do the same for the second space (reason).
Then we check if there is something filled in behind the /kick. We do this with the strlen function. If not, it gives a message on how to use the command.
If all is ok, then it converts the tmp into the id variable with the function strval. Now is the id the first integer that is filled in behind /kick. Then we got several checks. First we check if the player's id is online, then we check if it is not you and last it checks if the player has a higher level than you. If not it gives a message that you can't use it. If all is ok, we make a string and a variable called name. We format the name into the string and display it to the player who has been kicked. The reason is being seen too. We do this with the params[]. The params is the inputtext behind the official command. /kick in this case. The params[2] begins with the second character behind the /kick. Example: /kick 0 Hacks. You kick the player with id 0 for the reason Hacks. With params[2] We start at the Hacks. It doesn't read the 0 because it starts from the second character.
Then we say a message to all the players that the player has been kicked. If the id of the player has got 2 characters (10, 11, 12...) We need to start with params[3], so we made the check if the filled in id is between 0 and 9 or between 10 and 99. (You can get another check if you want more than 99 players on your server. Just make it between 100 and 999).
Now we got our kick command.

The ban command is exactly the same, only the command BanEx has been used in stead of Kick.

I hope I helped you guys a lot! You can download the whole script underneath.

Pastebin.com


Re: How to create an Admin Filterscript w/ commands ! - Wesley221 - 08.05.2011

Nice tutorial

I'm just getting 3 warnings while compiling:

Code:
C:\Users\wesley.PC_van_Kelsey\Desktop\SAMP_Flight\filterscripts\AdminSystem.pwn(63) : warning 217: loose indentation
C:\Users\wesley.PC_van_Kelsey\Desktop\SAMP_Flight\filterscripts\AdminSystem.pwn(158) : warning 217: loose indentation
C:\Users\wesley.PC_van_Kelsey\Desktop\SAMP_Flight\filterscripts\AdminSystem.pwn(309) : warning 217: loose indentation
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


3 Warnings.
pawn Code:
if(!fexist(CommandFile)) //<-- line 63
strcat(gPlayerInfo[playerid][PLAYER_IP], dini_Get(file, "Ip")); // <-- line 158
SendClientMessage(playerid, COLOR_ORANGE, string); // <-- line 309



Re: How to create an Admin Filterscript w/ commands ! - Hipflop - 08.05.2011

Looks like there is nothing wrong...
The pastebin file is 100% correct, maybe you should look over there


Re: How to create an Admin Filterscript w/ commands ! - Wesley221 - 08.05.2011

Ah i know whats wrong

I tried the pastebin one, and there were 2 errors
Just had to add some tabs, and then it was fixed; might be the problem on my last try aswell

Thanks


Re: How to create an Admin Filterscript w/ commands ! - Wesley221 - 08.05.2011

Hmm i keep spamming here.. haha

When i add the admin thing to the filterscript line, and start up te server; it closes when it comes to the filterscript..

SERVER LOG
Code:
SA-MP Dedicated Server
----------------------
v0.3c R2, ©2005-2011 SA-MP Team

[19:57:29] 
[19:57:29] Server Plugins
[19:57:29] --------------
[19:57:29]  Loading plugin: Whirlpool
[19:57:29]  
[19:57:29]  ==================
[19:57:29]  
[19:57:29]   Whirlpool loaded
[19:57:29]  
[19:57:29]  ==================
[19:57:29]  
[19:57:29]   Loaded.
[19:57:29]  Loading plugin: streamer
[19:57:29] 

*** Streamer Plugin v2.5.2 by Incognito loaded ***

[19:57:29]   Loaded.
[19:57:29]  Loading plugin: sscanf
[19:57:29] 

[19:57:29]  ===============================

[19:57:29]       sscanf plugin loaded.     

[19:57:29]    © 2009 Alex "Y_Less" Cole

[19:57:29]  ===============================

[19:57:29]   Loaded.
[19:57:29]  Loaded 3 plugins.

[19:57:29] 
[19:57:29] Filter Scripts
[19:57:29] ---------------
[19:57:29]   Loading filter script 'AdminSystem1.amx'...
[19:57:29] 
************************************
[19:57:29] *                                  *
[19:57:29] * Admin Filterscript by Hipflop    *
[19:57:29] *                                  *
[19:57:29] ************************************
CRASH LOG
Code:
SA-MP Server: 0.3c R2



Exception At Address: 0x004A319B



Registers:

EAX: 0x0018FC54	EBX: 0x02DAD2B0	ECX: 0x00000000	EDX: 0x00405910

ESI: 0x00000000	EDI: 0x0228CBD0	EBP: 0x0018FC64	ESP: 0x0018FC3C

EFLAGS: 0x00010286



Stack:

+0000: 0x0228CBD0   0x0228CBD0   0x02DAD2B0   0xFFFFFFFF

+0010: 0x0018FC3C   0x0018F810   0x0018FE24   0x004A6FE4

+0020: 0x004C22A8   0xFFFFFFFF   0x02DAE1A8   0x0040591D

+0030: 0x00000000   0x00401096   0x0228CBD0   0x02DCDAFC

+0040: 0x02DB13EC   0x00402BB3   0x0228CBD0   0x00000005

+0050: 0x0018FCA4   0x02DCDAFC   0x00000000   0x0228CBD0

+0060: 0x0228CC38   0x022DEE48   0x00000000   0x0001C70C

+0070: 0x0001C710   0x0001C738   0x0001873C   0x0001C71C

+0080: 0x0001873C   0x02DAD2B0   0x02DB13EC   0x00000000

+0090: 0x02DACFD0   0x0000413C   0x004807F8   0x0228CBD0

+00A0: 0x0018FCF4   0x00000001   0x021F0C50   0x002C8C60

+00B0: 0xFFFFFFFF   0x00000000   0x00000001   0x746C6966

+00C0: 0x63737265   0x74706972   0x64412F73   0x536E696D

+00D0: 0x65747379   0x612E316D   0x0000786D   0x00000000

+00E0: 0x00000000   0x00000000   0x00000000   0x00000000

+00F0: 0x00000000   0x00000000   0x00000000   0x00000000

+0100: 0x00000000   0x00000000   0x00000000   0x00000000

+0110: 0x00000000   0x00000000   0x00000000   0x00000000

+0120: 0x00000000   0x00000000   0x00000000   0x00000000

+0130: 0x00000000   0x00000000   0x00000000   0x00000000
U know what to do? =S.. (Copied the filterscript from pastebin)


Re: How to create an Admin Filterscript w/ commands ! - Hipflop - 13.05.2011

I don't know ...
It don't gives any errors when I load it...

Maybe ask in Discussion topic..

Greetz,
Hipflop


Re: How to create an Admin Filterscript w/ commands ! - BASITJALIL - 27.05.2011

Nice work


Re: How to create an Admin Filterscript w/ commands ! - Mean - 27.05.2011

For all of you with thoose warnings, read this:
https://sampforum.blast.hk/showthread.php?tid=256961


Re: How to create an Admin Filterscript w/ commands ! - IvancheBG - 08.06.2011

I have a problem when i tried to start my sever and put the fs in the filterscript line it says

Loading filter script [FS]Admin.amx
Unable to load filter script [FS]Admin.amx
Loading filter script Script.amx
Unable to load filter script Script.amx


Re: How to create an Admin Filterscript w/ commands ! - alpha500delta - 08.06.2011

Please do not define so much colors... you don't even use half of them


Re: How to create an Admin Filterscript w/ commands ! - Hipflop - 12.06.2011

Quote:
Originally Posted by alpha500delta
View Post
Please do not define so much colors... you don't even use half of them
That's right, but if the players want to add new commands or other colors, they are already there!

Greetz,
Hipflop


Re: How to create an Admin Filterscript w/ commands ! - noder51 - 18.11.2011

cool very helped me
but how do i make more commands? i keep trying and failing


Re: How to create an Admin Filterscript w/ commands ! - noder51 - 26.11.2011

help?


Re: How to create an Admin Filterscript w/ commands ! - Jagofr - 23.12.2011

Quote:
Originally Posted by Wesley221
View Post
Hmm i keep spamming here.. haha

When i add the admin thing to the filterscript line, and start up te server; it closes when it comes to the filterscript..

SERVER LOG
Code:
SA-MP Dedicated Server
----------------------
v0.3c R2, ©2005-2011 SA-MP Team

[19:57:29] 
[19:57:29] Server Plugins
[19:57:29] --------------
[19:57:29]  Loading plugin: Whirlpool
[19:57:29]  
[19:57:29]  ==================
[19:57:29]  
[19:57:29]   Whirlpool loaded
[19:57:29]  
[19:57:29]  ==================
[19:57:29]  
[19:57:29]   Loaded.
[19:57:29]  Loading plugin: streamer
[19:57:29] 

*** Streamer Plugin v2.5.2 by Incognito loaded ***

[19:57:29]   Loaded.
[19:57:29]  Loading plugin: sscanf
[19:57:29] 

[19:57:29]  ===============================

[19:57:29]       sscanf plugin loaded.     

[19:57:29]    © 2009 Alex "Y_Less" Cole

[19:57:29]  ===============================

[19:57:29]   Loaded.
[19:57:29]  Loaded 3 plugins.

[19:57:29] 
[19:57:29] Filter Scripts
[19:57:29] ---------------
[19:57:29]   Loading filter script 'AdminSystem1.amx'...
[19:57:29] 
************************************
[19:57:29] *                                  *
[19:57:29] * Admin Filterscript by Hipflop    *
[19:57:29] *                                  *
[19:57:29] ************************************
CRASH LOG
Code:
SA-MP Server: 0.3c R2



Exception At Address: 0x004A319B



Registers:

EAX: 0x0018FC54	EBX: 0x02DAD2B0	ECX: 0x00000000	EDX: 0x00405910

ESI: 0x00000000	EDI: 0x0228CBD0	EBP: 0x0018FC64	ESP: 0x0018FC3C

EFLAGS: 0x00010286



Stack:

+0000: 0x0228CBD0   0x0228CBD0   0x02DAD2B0   0xFFFFFFFF

+0010: 0x0018FC3C   0x0018F810   0x0018FE24   0x004A6FE4

+0020: 0x004C22A8   0xFFFFFFFF   0x02DAE1A8   0x0040591D

+0030: 0x00000000   0x00401096   0x0228CBD0   0x02DCDAFC

+0040: 0x02DB13EC   0x00402BB3   0x0228CBD0   0x00000005

+0050: 0x0018FCA4   0x02DCDAFC   0x00000000   0x0228CBD0

+0060: 0x0228CC38   0x022DEE48   0x00000000   0x0001C70C

+0070: 0x0001C710   0x0001C738   0x0001873C   0x0001C71C

+0080: 0x0001873C   0x02DAD2B0   0x02DB13EC   0x00000000

+0090: 0x02DACFD0   0x0000413C   0x004807F8   0x0228CBD0

+00A0: 0x0018FCF4   0x00000001   0x021F0C50   0x002C8C60

+00B0: 0xFFFFFFFF   0x00000000   0x00000001   0x746C6966

+00C0: 0x63737265   0x74706972   0x64412F73   0x536E696D

+00D0: 0x65747379   0x612E316D   0x0000786D   0x00000000

+00E0: 0x00000000   0x00000000   0x00000000   0x00000000

+00F0: 0x00000000   0x00000000   0x00000000   0x00000000

+0100: 0x00000000   0x00000000   0x00000000   0x00000000

+0110: 0x00000000   0x00000000   0x00000000   0x00000000

+0120: 0x00000000   0x00000000   0x00000000   0x00000000

+0130: 0x00000000   0x00000000   0x00000000   0x00000000
U know what to do? =S.. (Copied the filterscript from pastebin)
I had the same probleem. Just create the folders that is Defined. You know Admin/Users and Admin/Settings
The script runs fine


Re: How to create an Admin Filterscript w/ commands ! - Jagofr - 23.12.2011

Quote:
Originally Posted by noder51
View Post
help?
https://sampforum.blast.hk/showthread.php?tid=48239


Re: How to create an Admin Filterscript w/ commands ! - Littlehelper - 26.12.2011

Cool tutorial, Cheers.


Re: How to create an Admin Filterscript w/ commands ! - Wickeed - 04.01.2012

Why i cant spawn? and i join server...i do /register but "Server Unknow command"? What is wrong?


Re: How to create an Admin Filterscript w/ commands ! - James Coral - 05.01.2012

Quote:
Originally Posted by Wickeed
View Post
Why i cant spawn? and i join server...i do /register but "Server Unknow command"? What is wrong?
@WICKEED: Its Somekind of old Tutorial :P

INTOPIC: How i make /makeadmin command And What i need do use do make admin commands
like LuxAdmin have:

pawn Code:
if(AccInfo[playerid][Level] >= 5 || IsPlayerAdmin(playerid))



Re: How to create an Admin Filterscript w/ commands ! - James Coral - 05.01.2012

Quote:
Originally Posted by Wickeed
View Post
Why i cant spawn? and i join server...i do /register but "Server Unknow command"? What is wrong?
Btw do you have scriptfiles/Admin/Users ?


Re: How to create an Admin Filterscript w/ commands ! - Wickeed - 05.01.2012

Quote:
Originally Posted by James Coral
View Post
Btw do you have scriptfiles/Admin/Users ?
Yeah i have but i cant spawn
I start "new" server...Can someone know where is "good" adminstor filterscript [TuT] Please?