[Tutorial] Simple zcmd and sscanf Tutorial [Explained]
#1

Simple zcmd and sscanf Tutorial [Explained]
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
SSCANF:

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
Step 2:
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[])
- All of styles are the same

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
COMMANDS
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;
}
Explain Time!

pawn Код:
new string[128],msg[128],pname[MAX_PLAYER_NAME];
- This will make string/msg/ and PNAME in MAX_PLAYER_NAME variable

pawn Код:
GetPlayerName(playerid,pname,sizeof(pname));
- remember the new pname[MAX_PLAYER_NAME];? well we will use it. This will define and gets the username of the user using the command of me command.

pawn Код:
if(sscanf(params,"sz",msg)) return SendClientMessage(playerid,COLOR_RED, "USAGE: /me <text>");
- Inside that line the "s" defines that the first parameter in, in the command is going to be a string, second inside that line the "z" defines that the first parameter in, in the command is going to be a optional string. sscanf will detect and does all that for you.

pawn Код:
format(string,sizeof(string),"*%s %s",pname,msg);
- This is the important part because this function will send your msg to all players example: /me is hungry
string/pname and msg is used here.

pawn Код:
SendClientMessageToAll(COLOR_GREY,string);
- This will be sent to everyone online player

pawn Код:
return 1;
}
So we wanna close the Brackets‎ and return it to true (1 = true, 0 = false) that will make the command work.

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
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)