24.10.2012, 19:11
First of all you should download ZCMD, and SSCANF.
put both of them inside pawno/includes
and SSCANF into plugins depends on your system .so for linux.
after you've done that, at the top of your gamemode add:
#include <YSI\y_ini>
#include <sscanf2>
without these you will not be able to use all sscanf and zcmd methods.
we will use this way:
COMMAND:mycommand(playerid, params[])
or
CMD:mycommand(playerid, params[])
start with
first make a new string[256];
for our message format.
and playername[MAX_PLAYER_NAME];
new string[256],playername[MAX_PLAYER_NAME];
we want to make a check if the player is admin rcon or not so.
Explanation:
the ! inside IsPlayerAdmin means if he's not admin. don't remove this or else admin will get this message and won't
be able to send an announce.
let's move on.
let's make a check if the player doesn't write any message inside the params.
if the params of the command are null <isnull> a return message will popup "/announce [text]"
k time to get the player name for the message.
playerid - is the playerid.
playername - the variable we made.
sizeof(playername) - the size of the player name, you can use numbers like 265 but i prefer sizeof.
let's move on.
the string of the message will be like that.
inside format(
string - is the string variable we made
sizeof(string) - the size of the message
%s is the name of the player
%s it's for strings.
%d it's for numbers
%s : %s",
first we have playername then message you can look by here.
playername, params
first playername then params.
then just simple send message to all
Full command
command with sscanf:
put both of them inside pawno/includes
and SSCANF into plugins depends on your system .so for linux.
after you've done that, at the top of your gamemode add:
#include <YSI\y_ini>
#include <sscanf2>
without these you will not be able to use all sscanf and zcmd methods.
we will use this way:
COMMAND:mycommand(playerid, params[])
or
CMD:mycommand(playerid, params[])
start with
Код:
CMD:announce(playerid, params) { return 1; }
for our message format.
and playername[MAX_PLAYER_NAME];
new string[256],playername[MAX_PLAYER_NAME];
we want to make a check if the player is admin rcon or not so.
Код:
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFF, "You are not admin");
the ! inside IsPlayerAdmin means if he's not admin. don't remove this or else admin will get this message and won't
be able to send an announce.
let's move on.
Код:
CMD:announce(playerid, params[]) { new string[256],playername[MAX_PLAYER_NAME]; if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFF, "You are not admin"); return 1; }
Код:
if(isnull(params)) return SendClientMessage(playerid, 0xFFFFFF, "/announce [text]");
k time to get the player name for the message.
Код:
GetPlayerName(playerid, playername, sizeof(playername));
playername - the variable we made.
sizeof(playername) - the size of the player name, you can use numbers like 265 but i prefer sizeof.
let's move on.
the string of the message will be like that.
Код:
format(string, sizeof(string), "%s : %s", playername, params);
string - is the string variable we made
sizeof(string) - the size of the message
%s is the name of the player
%s it's for strings.
%d it's for numbers
%s : %s",
first we have playername then message you can look by here.
playername, params
first playername then params.
then just simple send message to all
Код:
SendClientMessageToAll(0xFFFFFFF, string);
Код:
CMD:announce(playerid, params[]) { new string[256], pName[MAX_PLAYER_NAME]; if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFF, "You are not admin"); if(isnull(params)) return SendClientMessage(playerid, 0xFFFFFF, "/announce [text]"); GetPlayerName(playerid, pName, sizeof(pName)); format(string, sizeof(string), "{F2240D}[Admin] %s:{09F7C7} %s", pName, params); SendClientMessageToAll(0xFFFFFFF, string); return 1; }
Код:
CMD:announce(playerid, params[]) { new text[265],string[265],pName[MAX_PLAYER_NAME]; if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFF, "You are not admin"); if(sscanf(params,"s[265]",text)) return SendClientMessage(playerid, COLOR_WHITE,"/announce [text]"); GetPlayerName(playerid, pName, sizeof(pName)); format(string, sizeof(string), "{F2240D}[Admin] %s:{09F7C7} %s", pName, text); SendClientMessageToAll(0xFFFFFFF, string); return 1; }