[Tutorial] How to make commands using ZCMD + SSCANF
#1

So, first of all, this is my first tutorial, but ill try to give my best.

You will need:
- zcmd plugin by its creator (Zeex?)
- sscanf plugin by ******

So let's start.

First of all, on the top of the script lets make these lines:
pawn Код:
#include <zcmd>
#include <sscanf>
Explanation: These add the functions such as COMMAND:help(playerid, params[]) into the script, so it wouldnt make us any errors.

Now, lets go somewhere down, and lets make a simple /help command:
pawn Код:
COMMAND:help(playerid, params[])
{
      SendClientMessage(playerid, 0xFFFFFFF,"This is your text!");
      return 1;
}
Explanation:

COMMAND:help(playerid, params[]) makes the command into our script
Brackets
Sending our message to the player, SendClientMessage(playerid, colour(in our case its white), and the text is what it sends us.
return 1; makes it fix the problem that it will not show SERVER:Unknown Command, it means it returns it.
Brackets end.

Now if you compile and go ingame, you will get the message: This is your text! In white.

Lets make a /kick command, using sscanf and zcmd, for RCON admins only.

Command what are we going to make:
pawn Код:
COMMAND:kick(playerid, params[])
{
    new name[MAX_PLAYER_NAME];
    new giveplayerid;
    new result[128]; // makes a new function, so we wouldnt get any errors
    GetPlayerName(playerid, name, sizeof(name)); // pretty self-explanatory
    if(IsPlayerAdmin(playerid)) { // Checks if the player is a RCON admin
        if (!sscanf(params, "is", giveplayerid, (result))) { // sscanf checking, if its in the right format
            if(giveplayerid != INVALID_PLAYER_ID) { // if the player is online
                new string[128];
                GetPlayerName(playerid, name, sizeof(name));
                format(string,sizeof(string),"%s has been kicked by %s, Reason: %s ",giveplayerid,playerid,reason);
                SendClientMessageToAll(0xFFFFFFF,string);
                return Kick(playerid); // returns the command to kick the player
            }
            else {// else if the player is offline/wrong ID
                SendClientMessage(playerid, COLOR_GREY, "[ERROR:] Invalid ID.");
            }
        }
        else { // else if is the wrong usage
            SendClientMessage(playerid, COLOR_GREY, "[ERROR:] Please use the correct usage!");
        }
    }
    else { // else if the player isnt a RCON admin
        SendClientMessage(playerid, COLOR_GREY, "[ERROR:] You are not an admin!");
    }
    return 1; // returns the whole command
}
That's it! Now you can go ingame and type /kick when logged in as an admin, /kick 0 Cheating: 0 is the ID, Cheating is the reason.

If you get any errors/warning, let me know, I just wrote it and im not really sure it will work .
Reply
#2

You never explained why you need to include sscanf/zcmd, what they do, and where to get them!

You can't make new functions (?)
pawn Код:
new result[128]; // makes a new function, so we wouldnt get any errors
I don't think novices will understand what you mean:
pawn Код:
if (!sscanf(params, "is", giveplayerid, (result))) {// sscanf checking, if its in the right format
this doesn't make much sense either
pawn Код:
return Kick(playerid); // returns the command to kick the player
Sorry, but there are just too many tutorials like this one with pretty much only faulty information. If you're going to write a tutorial, you should know exactly what you're making it about.
Reply
#3

I agree with Slice, although it's nice to see you have made an effort.
Reply
#4

What is "IS" ?
Its ID and STRING?
Reply
#5

You're using sscanf bad, you've to put the string lenght after "s", example:

Код:
is
is[128]
Reply
#6

@MrDeath537.. ye I was going to say that.. I've experienced bugs and a small annoying problem it printed a warning in RCON console and in 1 day it took alot of server.log space so it's a important thing to know
Reply
#7

hey! thanx! now i finally understand scanf!
Reply
#8

Thanks I'll take the kick cmd and remind myself about making other stuff from it such as ban/healplayer/killplayer etc!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)