[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
#2

nice tutorial m8.
Reply
#3

Quote:
Originally Posted by GAMER_PS2
Посмотреть сообщение
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.
Could you please further explain this to me in a PM? Thank you .
~Soldier9221
Reply
#4

wtf my server cant read from zcmd.inc and sscanf2.inc... wtf should i do :/
Reply
#5

Quote:
Originally Posted by Subwoofer
Посмотреть сообщение
wtf my server cant read from zcmd.inc and sscanf2.inc... wtf should i do :/
1. download them. the links are on the top of the first post.
2. put them inside the "pawno/includes" folder where your server is located.
3. make sure you open the same pawno in which you put the includes and there is no other pawno in your pc (to avoid collusion)
Reply
#6

Quote:
Originally Posted by Soldier9221
Посмотреть сообщение
Could you please further explain this to me in a PM? Thank you .
~Soldier9221
first %s is pname', second %s is 'msg'
Reply
#7

Quote:
Originally Posted by emokidx111
Посмотреть сообщение
1. download them. the links are on the top of the first post.
2. put them inside the "pawno/includes" folder where your server is located.
3. make sure you open the same pawno in which you put the includes and there is no other pawno in your pc (to avoid collusion)
i done it before too but still its bugged, even filterscripts cant load from sscanf and zcmd and with other new includes like dini....

PHP код:
C:\Users\Windows7\Desktop\Asjad\SAMP\SAMP Server 3\filterscripts\cali-houses.pwn(12) : fatal error 100cannot read from file"dini"
Compilation aborted.Pawn compiler 3.2.3664              Copyright (c1997-2006ITB CompuPhase
1 Error

Reply
#8

Quote:
Originally Posted by Subwoofer
Посмотреть сообщение
i done it before too but still its bugged, even filterscripts cant load from sscanf and zcmd and with other new includes like dini....

PHP код:
C:\Users\Windows7\Desktop\Asjad\SAMP\SAMP Server 3\filterscripts\cali-houses.pwn(12) : fatal error 100cannot read from file"dini"
Compilation aborted.Pawn compiler 3.2.3664              Copyright (c1997-2006ITB CompuPhase
1 Error

Get dini from dracoblue's site !
Reply
#9

Quote:
Originally Posted by Xtreme_playa
Посмотреть сообщение
Get dini from dracoblue's site !
i downloaded it, put into right place but still get error :/. i think the pawno is f****d up itself...
Reply
#10

Sometimes its happening to me if you get that problem.

remove all inc files inside the include folder then put it outside of the server folder compile your script.
put your inc files back inside the include folder compile it done its fix. just keep repeating those if you keep getting those problem.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)