03.01.2011, 11:55
(
Последний раз редактировалось Kaylux; 07.01.2011 в 16:07.
)
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
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:
“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:
"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.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>
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[])
“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;
}
"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.
The
pawn Код:
if(IsPlayerAdmin(playerid))
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.
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.