SA-MP Forums Archive
[Tutorial] Using Zcmd and Sscanf - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Using Zcmd and Sscanf (/showthread.php?tid=244841)

Pages: 1 2


Using Zcmd and Sscanf - Markx - 28.03.2011

Using Zcmd and Sscanf
By: Markx
1. Step

-First of all you will need Zeex's Zcmd include. You can download it from here.
-You will need ******'s Sscanf include too! Download it here.

2. Step

-When you download the include, put it in YourServer/pawno/inculdes.

3. Step

-Now open up your gamemode, or start a new one by clicking "File" Then "New".
-Now do like this:

pawn Код:
#include <a_samp>
#include <Zcmd>
#include <sscanf>
-a_samp is the SAMP include.
-Zcmd is Zeex's include, that will include zcmd so we can use it in pawno.
-Sscanf is ******'s include, we must include it to be able to use sscanf.

Sscanf:
Код:
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
3. Step
Making simple commands

-You can chose what kind of "style" you want to use.
-Here are all:

pawn Код:
command(mycommand, playerid, params[])
pawn Код:
cmd(mycommand, playerid, params[])
pawn Код:
COMMAND:mycommand(playerid, params[])
pawn Код:
CMD:mycommand(playerid, params[])
-Its all the same.

Lets explain

-Here "params" is the parameters string, playerid is an ID of the player who send this command.

Commands

#Note
You must put those commands (Zcmd) on the bottom of your script!

-Lets start by making a /heal command for RCON admin

pawn Код:
CMD:heal(playerid, params[])
{
    new Player;
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: You are not a RCON Admin!");
    else if (sscanf(params, "u", Player)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /heal [PlayerID]");
    else if (Player == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFF0000AA, "Player not found");
    else
    {
        SetPlayerHealth(Player, 100.0);
        SendClientMessage(Player, 0x00FF00AA, "You have been healed");
        SendClientMessage(playerid, 0x00FF00AA, "Player healed");
    }
    return 1;
}
Lets Explain

pawn Код:
new Player;
-This will create a new variable.

pawn Код:
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: You are not a RCON Admin!");
-That will check if the Player is a RCON Administrator, if not he wont be able to use the command, and a message will be sent to him: "ERROR: You are not a RCON Admin!", you can change that, also "0xFF0000AA" is a color code, you can change that to your colors.

pawn Код:
if (sscanf(params, "u", Player)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /heal [PlayerID]");
-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.
-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. So we send him a Message how to use it right.

pawn Код:
else if (Player == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFF0000AA, "Player not found");
-That will check if you entered a wrong ID (User is not connected or wrong ID), and we will send hima message that the player isnt found so he can enter a vaild ID.

Now we wanna set his health to full, right? so will will add this:
pawn Код:
SetPlayerHealth(Player, 100.0);
-That will set the Health of the player ID that you entered to 100, full health.

pawn Код:
SendClientMessage(Player, 0x00FF00AA, "You have been healed");
-This will sent the player a message that he has been healed.

pawn Код:
SendClientMessage(playerid, 0x00FF00AA, "Player healed");
-This will send a command to the RCON Admin that is healing a player, after the player is healed, a player will be sent to the RCON Admin.

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

Done!
Now you can learn from that command, try using sscanf, zcmd, and learn to use search before asking something! Hope this helped you to understand more about Zcmd and Sscanf.
- Markx



Re: Using Zcmd and Sscanf - Mikkel_Pedersen - 28.03.2011

pawn Код:
if(IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: You are not a RCON Admin!");
You're sending them a message if they are rcon admins.


Re: Using Zcmd and Sscanf - Markx - 28.03.2011

Quote:
Originally Posted by Mikkel_Pedersen
Посмотреть сообщение
pawn Код:
if(IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: You are not a RCON Admin!");
You're sending them a message if they are rcon admins.
Nope, if he isnt Rcon admin it will send him that message. Am i right?

EDIT: Fail xD


Re: Using Zcmd and Sscanf - Mikkel_Pedersen - 28.03.2011

Wouldn't you use ! then?

pawn Код:
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: You are not a RCON Admin!");



Re: Using Zcmd and Sscanf - Markx - 28.03.2011

Quote:
Originally Posted by Mikkel_Pedersen
Посмотреть сообщение
Wouldn't you use ! then?

pawn Код:
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: You are not a RCON Admin!");
Oh yeah i see now, thanks.
Fixed.


Re: Using Zcmd and Sscanf - gamer931215 - 29.03.2011

Nice tutorial, saves me explaining this all to a classm8


Re: Using Zcmd and Sscanf - Markx - 29.03.2011

Quote:
Originally Posted by gamer931215
Посмотреть сообщение
Nice tutorial, saves me explaining this all to a classm8
Thanks ^^


Re: Using Zcmd and Sscanf - Mr_Scripter - 29.03.2011

pawn Код:
SendClientMessage(Player, 0x00FF00AA, "You have been healed");
-This will sent the player a message that he has been healed.

pawn Code:

SendClientMessage(playerid, 0x00FF00AA, "Player healed");[/pawn]


-This will send a command to the RCON Admin that is healing a player, after the player is healed, a player will be sent to the RCON Admin.
///////////////////////////////////////////////////////////////////
I Don't Understand This "player,color,"You Have Been Healed"); will send message to player
"playerid,color,"Player Heal"); This will send to Rcon? i don't understand why? it's playerid (Rcon?) player(playerid)?



Re: Using Zcmd and Sscanf - Markx - 29.03.2011

Look, "Player" is the one you heal, so the message will be sent to the one you healed, not to you. And playerid, is you.


Re: Using Zcmd and Sscanf - Mr_Scripter - 29.03.2011

ok thanks in strcmp it's only playerid so i don't understand it now i know thanks


Re: Using Zcmd and Sscanf - Markx - 29.03.2011

Quote:
Originally Posted by Mr_Scripter
View Post
ok thanks in strcmp it's only playerid so i don't understand it now i know thanks
No, you can use "Player" in strcmp too, like i sayd, you have to make a new variable (new Player, you can make that on strcmp too, but zcmd and sscanf is faster.


Re: Using Zcmd and Sscanf - bake_pg - 29.03.2011

ZCMD is much more easier than strcmp. It took me only about half an hour to know how to work with it


Re: Using Zcmd and Sscanf - Ironboy - 29.03.2011

Nice tutorial


Re: Using Zcmd and Sscanf - gamer931215 - 30.03.2011

btw
pawn Code:
#include <sscanf>
should be
pawn Code:
#include <sscanf2>



Re: Using Zcmd and Sscanf - alpha500delta - 30.03.2011

ZCMD does not have to be at the bottom of your script. Just not in a callback.


Re: Using Zcmd and Sscanf - Markx - 30.03.2011

Thanks all.


Re: Using Zcmd and Sscanf - sabreman - 02.04.2011

i made a command for give money, it compiles correctly but gives a warning for givemoney is never used. Can anyone help me?


Re: Using Zcmd and Sscanf - Markx - 02.04.2011

Quote:
Originally Posted by sabreman
View Post
i made a command for give money, it compiles correctly but gives a warning for givemoney is never used. Can anyone help me?
Dont post that here..


Re: Using Zcmd and Sscanf - sabreman - 02.04.2011

Quote:
Originally Posted by Markx
View Post
Dont post that here..
Okay, sorry. But nvm that I fixed it.


Re: Using Zcmd and Sscanf - PinkFloydLover - 03.04.2011

I still wonder why people tend to use sscanf for one parameter commands when you can just params.

pawn Code:
CMD:test(playerid, params[])
{
    new str[128];
    format(str,sizeof(str),"%s",params);
    SendClientMessage(playerid,color,str);
    return 1;
}
Will work just effectively as using sscanf, same can be applied to the command you used.