10.12.2012, 00:47
(
Последний раз редактировалось kamzaf; 22.01.2013 в 22:09.
)
Writing Commands using sscanf2 & zcmd
Before we start you must include these two lines in the top of your script:
pawn Код:
#include <a_samp>
#include <sscanf2>
#include <zcmd>
sscanf.inc
zcmd.inc
Plugin downloads:
sscanf.dll Windows only!
Now lets start with a simple command.
pawn Код:
COMMAND:help(playerid, params[]) //Command is: help
{
Now when a player only types: /Help. Nothing after it (which is called "params") then you may include this line:
pawn Код:
COMMAND:help(playerid, params[]) //Command is: help
{
#pragma unused params
//Tells the script that there is no text after the "/help" command, (IS OPTIONAL)
Now we will use this function: to send a message to the player who types: "/help"
pawn Код:
SendClientMessage(playerid, COLOR, "this is the text the player will see");
//Where "playerid" is the player who types "/help"
//"COLOR" is the color which you will need to define in the top of your script.
//"text"); is the text you want the player to see.
pawn Код:
COMMAND:help(playerid, params[]) //Command is: help
{
#pragma unused params
//Tells the script that there is no text after the "/help" command
SendClientMessage(playerid, red, "_________________________Server Help_____________________________");
SendClientMessage(playerid, green, "[HELP] This is a BLANK server, Work with your team to");
SendClientMessage(playerid, green, "[HELP] destroy other teams and earn the highest score");
SendClientMessage(playerid, green, "[HELP] See /admins if you need any help");
SendClientMessage(playerid, green, "[HELP] For more information on the commands see: /cmds");
SendClientMessage(playerid, green, "[HELP] /rules - For server rules");
SendClientMessage(playerid, red, "_________________________________________________________________");
}
Part 2:
Using sscanf + zcmd to make commands.Lets start with a /givemoney command.
pawn Код:
CMD:givemoney(playerid, params[])
{
pawn Код:
CMD:
pawn Код:
COMMAND:
pawn Код:
CMD:givemoney(playerid, params[])
{
new giveplayerid, amount
pawn Код:
CMD:givemoney(playerid, params[])
{
new giveplayerid, amount;
new string[128];
pawn Код:
CMD:givemoney(playerid, params[])
{
new giveplayerid, amount;
new string[128];
if (sscanf(params, "ud", giveplayerid, amount)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /givecash [playerid/partname] [amount]");
pawn Код:
CMD:givemoney(playerid, params[])
{
new giveplayerid, amount;
new string[128];
if (sscanf(params, "ud", giveplayerid, amount)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /givecash [playerid/partname] [amount]");
else if (giveplayerid == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
else if (amount > GetPlayerMoney(playerid)) SendClientMessage(playerid, 0xFF0000AA, "Insufficient Funds");
else if (giveplayerid == playerid) SendClientMessage(playerid, 0xFF0000AA, "You cannot send money to yourself");
pawn Код:
else if (giveplayerid == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
pawn Код:
else if (amount > GetPlayerMoney(playerid)) SendClientMessage(playerid, 0xFF0000AA, "Insufficient Funds"
Now before we go on, let me clarify that "giveplayerid" is the player which the money is being sent to.
And "playerid" is the player who is typing that command.
pawn Код:
else if (giveplayerid == playerid) SendClientMessage(playerid, 0xFF0000AA, "You cannot send money to yourself");
pawn Код:
CMD:givemoney(playerid, params[])
{
new giveplayerid, amount;
new string[128];
if (sscanf(params, "ud", giveplayerid, amount)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /givecash [playerid/partname] [amount]");
else if (giveplayerid == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
else if (amount > GetPlayerMoney(playerid)) SendClientMessage(playerid, 0xFF0000AA, "Insufficient Funds");
else if (giveplayerid == playerid) SendClientMessage(playerid, 0xFF0000AA, "You cannot send money to yourself");
GivePlayerMoney(giveplayerid, amount);
GivePlayerMoney(playerid, -amount);
format(string, sizeof string, "[SERVER] %d amount of Money has been Sent to %s", amount, giveplayerid);
SendClientMessage(playerid, COLOR_RED, string);
format(string, sizeof string, "[SERVER] %d amount of Money has Sent by %s", amount, playerid);
SendClientMessage(giveplayerid, COLOR_RED, string);
return 1;
}
pawn Код:
GivePlayerMoney(giveplayerid, amount);
This:
pawn Код:
GivePlayerMoney(playerid, -amount);
pawn Код:
format(string, sizeof string, "[SERVER] %d amount of Money has been Sent to %s", amount, giveplayerid);
SendClientMessage(playerid, COLOR_RED, string);
pawn Код:
format(string, sizeof string, "[SERVER] %d amount of Money has Sent by %s", amount, playerid);
SendClientMessage(giveplayerid, COLOR_RED, string);
pawn Код:
return 1;
Please comment and rep.
Also please inform me of any bugs.