SA-MP Forums Archive
[Tutorial] Simple /announce command. - 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] Simple /announce command. (/showthread.php?tid=387435)



Simple /announce command. - PaulDinam - 24.10.2012

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

Код:
CMD:announce(playerid, params)
{
   return 1;
}
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.
Код:
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFF, "You are not admin");
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.


Код:
CMD:announce(playerid, params[])
{
	new string[256],playername[MAX_PLAYER_NAME];
	if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFF, "You are not admin");
	return 1;
}
let's make a check if the player doesn't write any message inside the params.
Код:
if(isnull(params))  return SendClientMessage(playerid, 0xFFFFFF, "/announce [text]");
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.
Код:
GetPlayerName(playerid, playername, sizeof(playername));
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.
Код:
format(string, sizeof(string), "%s : %s", playername, params);
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
Код:
SendClientMessageToAll(0xFFFFFFF, string);
Full command
Код:
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;
}
command with sscanf:
Код:
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;
}



Re: Simple /announce command. - thefatshizms - 24.10.2012

Wait wait wait wait wait where the hell did we get ysi/ytimers from? Not everyone will have ysi so tell them to get it. Overall its not too bad of a tut.


Re: Simple /announce command. - PaulDinam - 24.10.2012

they don't need ysi..


Re: Simple /announce command. - JaKe Elite - 25.10.2012

Wa wa wait, what? Including YSI library to just one simple command??
Out of mind?, YSI is not even used in tutorial.


Re: Simple /announce command. - Emmet_ - 25.10.2012

Why is the announce text 265 cells big? You can only have around ~150 characters in a message (different for other resolutions).

You could of done this without sscanf either.

pawn Код:
CMD:announce(playerid, params[])
{
    new  
        string[152],
        pName[MAX_PLAYER_NAME]
    ;
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFF, "You are not admin");
    if (isnull(params)) return SendClientMessage(playerid, COLOR_WHITE,"/announce [text]");
    GetPlayerName(playerid, pName, sizeof(pName));
    format(string, sizeof(string), "{F2240D}[Admin] %s:{09F7C7} %s", pName, params);
    SendClientMessageToAll(0xFFFFFFF, string);
    return 1;
}