28.03.2011, 19:43
Using Zcmd and Sscanf
By: Markx
1. StepBy: Markx
-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>
-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
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[])
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;
}
pawn Код:
new Player;
pawn Код:
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: You are not a RCON Admin!");
pawn Код:
if (sscanf(params, "u", Player)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /heal [PlayerID]");
-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");
Now we wanna set his health to full, right? so will will add this:
pawn Код:
SetPlayerHealth(Player, 100.0);
pawn Код:
SendClientMessage(Player, 0x00FF00AA, "You have been healed");
pawn Код:
SendClientMessage(playerid, 0x00FF00AA, "Player healed");
pawn Код:
}
return 1;
}
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.
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