[Tutorial] Using zcmd && sscanf
#1

Using zcmd && sscanf


To start a using zcmd. You have to download the include file located here.

Once you have downloaded this file, place it into your “pawno>include” folder within your SAMP directory.

Then collect ******'s sscanf v2 plugin, and create a folder called "plugins" and place it into there and then place the include file into the folder with the zcmd include. You will also need to go into your server.cfg and add a line to the bottom called "plugins" and place "sscanf2" on the list.

Next, on the top of your script place
pawn Код:
#include <zcmd>
#include <sscanf2>
This tells pawno that you are about to use functions located inside the “zcmd” and "sscanf2" include.




Next step, creating commands in zcmd.

To create a comand you start by doing this:
pawn Код:
COMMAND:yourcommandhere(playerid, params[])
or
command:yourcommandhere(playerid, params[])
“COMMAND” defines that you are about to use zcmd's command system.

“yourcommandhere” is where you would place the name of the command you wish to use.

“playerid” is the return of the player who typed the command.

“params[]” is the parameters of the command.



Now for creating an actual command:


pawn Код:
COMMAND:kick(playerid, params[])
{
    new giveplayerid, reason[24], string[125], name[24], name2[24];
    if(IsPlayerAdmin(playerid))
    {
        if(sscanf(params, "is[24]", giveplayerid, reason)) return SendClientMessage(playerid,WHITE,"[ERROR]Usage: /kick [playerid] [reason]");
        else if(giveplayerid == INVALID_PLAYER_ID) return SendClientMessage(playerid,WHITE,"[ERROR] Player Is Not Connected");
        else
        {
            GetPlayerName(giveplayerid, name, sizeof(name));
            GetPlayerName(playerid, name2, sizeof(name2));
            format(string, sizeof(string), "<< ADM KICK >> Admin %s kicked %s(%d) | Reason: %s", name2, name, giveplayerid, reason);
            SendClientMessageToAll(YELLOW, string);
            Kick(giveplayerid);

        }
    }
    else return SendClientMessage(playerid, WHITE, "SERVER: Unknown Command");
    return 1;
}
"giveplayerid" is the whats going to be in the params of the command.
"reason" is also going to be in the params.
"string" is creating a string to be used later in the command.
"name" is also creating a string to use later on.
Remember: With zcmd, there is no need to use the "OnPlayerCommandText" native. Just use this as you would with a separate function.

The
pawn Код:
if(IsPlayerAdmin(playerid))
is checking if they player typing the command is a RCON admin. This would be adapted for your own script ofcourse.

Next Line Is
pawn Код:
if(sscanf(params, "us[24]", giveplayerid, reason)) return SendClientMessage(playerid,WHITE,"[ERROR]Usage: /kick [playerid] [reason]");
In this case. We use sscanf to extract the params from the command typed. Inside that line the "u" defines that the first parameter in in the command is going to be a playerid or a playername, sscanf detects and does all that for you. Next is the "s" this tells us that the next param is going to be a string. After that part, you can see that we assign those to strings/variables that we defined beforehand. Once the sscanf is done we use "return", this is what get returned if sscanf returns false. AKA those params weren't given.

Once that is done you can carry on using regular SAMP functions inside the brackets.
If you have any questions, Feel free to ask them.
Reply
#2

Thanks man.
Reply
#3

Quote:
Originally Posted by Kaylux
Посмотреть сообщение
pawn Код:
COMMAND:kick(playerid, params[])
{
    new giveplayerid, reason[24], string[125], name[24];
    if(IsPlayerAdmin(playerid))
    {
        if(sscanf(params, "is", giveplayerid, reason)) return SendClientMessage(playerid,WHITE,"[ERROR]Usage: /kick [playerid] [reason]");
        else if(giveplayerid == INVALID_PLAYER_ID) return SendClientMessage(playerid,WHITE,"[ERROR] Player Is Not Connected");
        else
        {
            GetPlayerName(giveplayerid, name, sizeof(name));
            format(string, sizeof(string), "<< ADM KICK >> Admin %s kicked %s(%d) | Reason: %s", name, GetPlayerNameEx(giveplayerid), giveplayerid, reason);
            SendClientMessageToAll(YELLOW, string);
            Kick(giveplayerid);

        }
    }
    else return SendClientMessage(playerid, WHITE, "SERVER: Unknown Command");
    return 1;
}
If you are using newest version of 'sscanf' here, you need to add string lenght in sscanf parameters.

pawn Код:
if(sscanf(params, "is[24]", giveplayerid, reason)) return SendClientMessage(playerid,WHITE,"[ERROR]Usage: /kick [playerid] [reason]");
If you don't do this, it will print warning to server console.

Even if this isn't much of a problem, you could still edit your post and hopefully make it "better".
Reply
#4

Ahh yea. I haven't updated yet and didn't know that changed. Thanks
Reply
#5

also it's
pawn Код:
#include <zcmd>
not
pawn Код:
#include<zcmd>
(You forgot a space).

Also, use 'u' instead of 'i' for getting the user, so you can also use playernames. You also forgot to include the function 'GetPlayerNameEx'.

Cheers,
[03]Garsino.
Reply
#6

Nice tutorial... You can also learn here if you are a total Noob with samp: [ame]http://www.youtube.com/watch?v=j3i82Q9ZE5o[/ame]
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)