[Tutorial] Using Zcmd and Sscanf
#1

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
Reply


Messages In This Thread
Using Zcmd and Sscanf - by Markx - 28.03.2011, 19:43
Re: Using Zcmd and Sscanf - by Mikkel_Pedersen - 28.03.2011, 19:55
Re: Using Zcmd and Sscanf - by Markx - 28.03.2011, 19:58
Re: Using Zcmd and Sscanf - by Mikkel_Pedersen - 28.03.2011, 20:00
Re: Using Zcmd and Sscanf - by Markx - 28.03.2011, 20:00
Re: Using Zcmd and Sscanf - by gamer931215 - 29.03.2011, 10:45
Re: Using Zcmd and Sscanf - by Markx - 29.03.2011, 10:49
Re: Using Zcmd and Sscanf - by Mr_Scripter - 29.03.2011, 11:24
Re: Using Zcmd and Sscanf - by Markx - 29.03.2011, 11:36
Re: Using Zcmd and Sscanf - by Mr_Scripter - 29.03.2011, 13:47
Re: Using Zcmd and Sscanf - by Markx - 29.03.2011, 14:42
Re: Using Zcmd and Sscanf - by bake_pg - 29.03.2011, 19:40
Re: Using Zcmd and Sscanf - by Ironboy - 29.03.2011, 19:41
Re: Using Zcmd and Sscanf - by gamer931215 - 30.03.2011, 07:06
Re: Using Zcmd and Sscanf - by alpha500delta - 30.03.2011, 12:03
Re: Using Zcmd and Sscanf - by Markx - 30.03.2011, 17:48
Re: Using Zcmd and Sscanf - by sabreman - 02.04.2011, 12:19
Re: Using Zcmd and Sscanf - by Markx - 02.04.2011, 14:22
Re: Using Zcmd and Sscanf - by sabreman - 02.04.2011, 16:49
Re: Using Zcmd and Sscanf - by PinkFloydLover - 03.04.2011, 12:48
Re: Using Zcmd and Sscanf - by ricardo178 - 03.04.2011, 13:37
Re: Using Zcmd and Sscanf - by omer5198 - 03.04.2011, 13:38
Re: Using Zcmd and Sscanf - by bestr32 - 03.04.2011, 16:38
Re: Using Zcmd and Sscanf - by Markx - 03.04.2011, 21:14
Re: Using Zcmd and Sscanf - by Arnoldas - 27.04.2011, 20:08
Re: Using Zcmd and Sscanf - by Joe Staff - 27.04.2011, 20:18
Re: Using Zcmd and Sscanf - by Markx - 28.04.2011, 08:38
Re: Using Zcmd and Sscanf - by xRyder - 28.04.2011, 11:16
Re: Using Zcmd and Sscanf - by Markx - 29.04.2011, 11:23
Re: Using Zcmd and Sscanf - by Shubham - 08.05.2011, 12:25
Re: Using Zcmd and Sscanf - by Markx - 11.05.2011, 18:41
Re: Using Zcmd and Sscanf - by roadless - 12.05.2011, 17:21
Re: Using Zcmd and Sscanf - by Mr.Carson Clay - 07.02.2012, 09:48
Re: Using Zcmd and Sscanf - by lsfmd - 07.02.2012, 15:18

Forum Jump:


Users browsing this thread: 1 Guest(s)