30.11.2011, 08:33
Simple zcmd and sscanf Tutorial [Explained]
Made by: GAMER_PS2
Made by: GAMER_PS2
Requirements before doing Tutorial:
You will need the following to do this tutorial:
Download Zeex's ZCMD include. You can download here >>> https://sampforum.blast.hk/showthread.php?tid=91354
Download ******(Alex)'s sscanf include. You can download here >>> https://sampforum.blast.hk/showthread.php?tid=120356
Step 1:
- Open your game mode or start a new one by clicking File >>> New
Next add this on your top of script (dont remove the a_samp)
pawn Код:
#include <zcmd>
#include <sscanf2> //if your using new version it should be like this
Thanks Markx For this
Код:
Specifier(s) Name Example values i, d Integer 1, 42, -10 c Character a, o, * l Logical true, false b Binary 01001, 0b1100 h, x Hex 1A, 0x23 o Octal 045 12 n Number 42, 0b010, 0xAC, 045 f Float 0.7, -99.5 g IEEE Float 0.7, -99.5, INFINITY, -INFINITY, NAN, NAN_E u User name/id (bots and players) ******, 0 q Bot name/id ShopBot, 27 r Player name/id ******, 42
Making the command
- You can choose any style of ZCMD command here we go:
pawn Код:
command(mycommand, playerid, params[])
pawn Код:
cmd(mycommand, playerid, params[])
pawn Код:
COMMAND:mycommand(playerid, params[])
pawn Код:
CMD:mycommand(playerid, params[])
Explain Time!
- Params, is the paramters string, playerid is an ID of player who sent this command.
for example:
pawn Код:
if(sscanf(params,"i", skin)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /setskin <0 - 299>");
//Inside that line the "i" defines that the first parameter in in the command is going to be a integer. sscanf will detect it very fast :D
Remember:
You must put them in the bottom not in OnPlayerCommandText
- Lets start making a command the example for this tutorial is me command
pawn Код:
CMD:me(playerid, params[])
{
new string[128],msg[128],pname[MAX_PLAYER_NAME];
GetPlayerName(playerid,pname,sizeof(pname));
if(sscanf(params,"sz",msg)) return SendClientMessage(playerid,COLOR_RED, "USAGE: /me <text>");
format(string,sizeof(string),"*%s %s",pname,msg);
SendClientMessageToAll(COLOR_GREY,string);
return 1;
}
pawn Код:
new string[128],msg[128],pname[MAX_PLAYER_NAME];
pawn Код:
GetPlayerName(playerid,pname,sizeof(pname));
pawn Код:
if(sscanf(params,"sz",msg)) return SendClientMessage(playerid,COLOR_RED, "USAGE: /me <text>");
pawn Код:
format(string,sizeof(string),"*%s %s",pname,msg);
string/pname and msg is used here.
pawn Код:
SendClientMessageToAll(COLOR_GREY,string);
pawn Код:
return 1;
}
Finish!
Now you can try it yourself just remember use ZCMD in right way. Hope you understand now how to use ZCMD and sscanf. good luck making ZCMD command