[Tutorial] Making /BAN, /KICK [RCON]
#1

Hi guys, today i will show you a tutorial of how to make: /BAN & /KICK For RCON only

Start:

First we will include ZCMD at the top:

pawn Code:
#include ZCMD // Thanks to: ZeeX
Now we will also include SScanf2:

pawn Code:
#include sscanf2 // Thanks to: Y_Less [(a.k.a): Alex Cole]
Now at the end of your script or where your ZCMD commands are, add the commands there which i will show you.

Now lets begin

How to make a zcmd cmd?

pawn Code:
COMMAND:/*Your Command Name Here*/(playerid, params[])
{   // this is the Bracket  from which the code starts
    //code here.
    return 1; // you must return 1
}  // & ends here
Tips:

* You can replace "COMMAND:" with "CMD:".

* You can move the bracket up, i will give you a example.

pawn Code:
CMD:/*Your Command Name Here*/(playerid, params[]) /*>>*/ { /*<<*/  
 
    //code here.
    return 1;//here also you must.
}  // end of the cmd
Now lets start:

The /BAN cmd.

pawn Code:
COMMAND:ban(playerid,params[])
{
    if(IsPlayerAdmin(playerid)) // This will check if the player is admin. (The code [if] checks IF something is true.
    {
        new Target; // This is the target we will ban.
        new Reason[100]; // This will be
        if(!sscanf(params, "us", Target, Reason)) // this will check the string ([u] is for a integer & [s] is for a string.
        {
            if(Target == playerid) return SendClientMessage(playerid, 0xFFBBCC, "You will ban your self D:"); // this will check [if] the player is trying to ban him self. (Commands are performed by the player (playerid)
            if(IsPlayerAdmin(Target)) return SendClientMessage(playerid, 0xFFBBCC, "You cant ban a RCON admin!"); // Checks [if] the Target is Rcon & another Rcon it trying to ban him.
            new string[128]; // This is the out put which will be used to send the ban message to all
            new name[MAX_PLAYER_NAME]; // getting the admin's name
            new tname[MAX_PLAYER_NAME]; // getting the Target's name
            GetPlayerName(playerid, name, sizeof(name)); // no need to enter a string (The banner is the player (playerid)
            GetPlayerName(Target, tname, sizeof(tname)); // & the ban we are going to give is Target (which we made up | new Target; |
            format(string, sizeof(string), "*Admin %s banned %s due to %s", name, tname, Reason); // this makes a format
            SendClientMessageToAll(0xFFBBCC, string); // This will send the client message to all. (no need for string, we will add the output without "
            new str[128]; // another output (oh i forget: new str[128] {[128]} is the number of chars (cells) it should not be higher than 999 or when you will test it in-game, you will disconnect for no reason.
            format(str, sizeof(str), "*Banned by: %s | Ban reason: %s | Press F8 to take a screen shot & make a unban appeal on our forum", name, Reason);
            SendClientMessage(Target, 0xFFBBCC, str); // sending the string of the output.
            BanEx(Target, Reason); // it will ban the target with a reason & the ban will be saved in SAMP.BAN
        }
        else SendClientMessage(playerid, 0xFFBBCC, "USAGE: /ban <Target> <reason>"); // if he entered it wrong
    }
    else SendClientMessage(playerid, 0xFFBBCC, "umm, this wrong cmd, try /help xd."); // returning a err msg that he is not admin :L.
    return 1; // you must i said it
}
That is all :d.

& /KICK cmd

pawn Code:
COMMAND:kick(playerid,params[])
{
    if(IsPlayerAdmin(playerid)) // This will check if the player is admin. (The code [if] checks IF something is true.
    {
        new Target; // This is the target we will kick.
        new Reason[100]; // This will be
        if(!sscanf(params, "us", Target, Reason)) // this will check the string ([u] is for a integer & [s] is for a string.
        {
            if(Target == playerid) return SendClientMessage(playerid, 0xFFBBCC, "You will Kick your self D:"); // this will check [if] the player is trying to kick him self. (Commands are performed by the player (playerid)
            if(IsPlayerAdmin(Target)) return SendClientMessage(playerid, 0xFFBBCC, "You can Kick a RCON admin!"); // Checks [if] the Target is Rcon & another Rcon it trying to kick him.
            new string[128]; // This is the out put which will be used to send the kick message to all
            new name[MAX_PLAYER_NAME]; // getting the admin's name
            new tname[MAX_PLAYER_NAME]; // getting the Target's name
            GetPlayerName(playerid, name, sizeof(name)); // no need to enter a string (The kicker is the player (playerid)
            GetPlayerName(Target, tname, sizeof(tname)); // & the kick we are going to give is Target (which we made up | new Target; |
            format(string, sizeof(string), "*Admin %s Kicked %s due to %s", name, tname, Reason); // this makes a format
            SendClientMessageToAll(0xFFBBCC, string); // This will send the client message to all. (no need for string, we will add the output without "
            new str[128]; // another output (oh i forget: new str[128] {[128]} is the number of chars (cells) it should not be higher than 999 or when you will test it in-game, you will disconnect for no reason.
            format(str, sizeof(str), "*Kicked by: %s | Kick reason: %s ", name, Reason);
            SendClientMessage(Target, 0xFFBBCC, str); // sending the string of the output.
            Kick(Target); // it will kick the target with a reason.
        }
        else SendClientMessage(playerid, 0xFFBBCC, "USAGE: /Kick <Target> <reason>"); // if he entered it wrong
    }
    else SendClientMessage(playerid, 0xFFBBCC, "umm, this wrong cmd, try /help xd."); // returning a err msg that he is not admin :L.
    return 1; // you must i said it
}
Reply
#2

Good explanations! And where are the goto, and slap commands you promised !
Reply
#3

@ Rajat_Pawar:

I dont break my promise so i will pm you when i will make the /slap , /goto , /get & /warn !!
Reply
#4

In your code you say that 'u' in sscanf is an integer. This is wrong.
Reply
#5

@ jonrb:

'u' is used for some thing like player id (the id we enter is integer)
Reply
#6

No, 'u' would probably be short for something like 'user'. With the 'u' parameter specified, you can use player IDs or parts of names.

Read the documentation.
Reply
#7

Strings in sscanf need to have a length specified. Example:

s[64]
Reply
#8

Quote:
Originally Posted by SuperViper
View Post
Strings in sscanf need to have a length specified. Example:

s[64]
IIRC if you just put 's' at the end, all of the remaining text gets dumped into that string, if it fits.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)