[Tutorial] Making a /announce command in ZCMD and sscanf
#1

Well,people i have seen a lot of guys searching around for a /announce command or even if they have it it has some problem or something.So today i decided to show you how you can make a FULLY WORKING /announce command in ZCMD and sscanf.

First i will tell you the code then i will explain it....

Code:
CMD:announce(playerid, params[])
{
    
    if(IsPlayerAdmin(playerid))
		return SendClientMessage(playerid, "You are not allowed to use this command");

    new text[64], time, style;
    if (sscanf(params, "iis[64]", style, time, text)) return
        SendClientMessage( playerid,"Usage: /announce <style[0-6]> <time in ms> <text>");

    if (strlen(text) > 64) return
        SendClientMessage(playerid,"Message too long please shorten it ");

    if(style == 2) return SendClientMessage(playerid,"Bug with style 2 don't use it!");
    
    if (style < 0 || style > 6) return
        SendClientMessage(playerid,0x854900FF,"Invalid style");

    if (time > 20*1000) return
        SendClientMessage(playerid,"No longer than 20 seconds");

    GameTextForAll(text, time, style);
    
    return true;
}
Now to understand the code

1.
Code:
if(IsPlayerAdmin(playerid))
		return SendClientMessage(playerid, "You are not allowed to use this command")
This command checks if the player i rcon admin or not you can change this to normal admins only by seeing what is defined in your admin system.If the player is not rcon admin it send a error.

2.
Code:
new text[64], time, style;
    if (sscanf(params, "iis[64]", style, time, text)) return
        SendClientMessage( playerid,"Usage: /announce <style[0-6]> <time in ms> <text>");
This code first defines usage and parameters.

3.
Code:
 if (strlen(text) > 64) return
        SendClientMessage(playerid,"Message too long please shorten it ");
This checks if the text exceeds the length of 64 chars. if it does it sends and error.

4.
Code:
if(style == 2) return SendClientMessage(playerid,"Bug with style 2 don't use it!");
This checks if the style is 2 because according to GTA:SA style 2 wont disappear from the screen till you respawn so if the style = 2 then it sends an error.

5.
Code:
    if (style < 0 || style > 6) return
        SendClientMessage(playerid,0x854900FF,"Invalid style");
This checks if the style is valid that means between 1-6 or it sends an error.

6.
Code:
    if (time > 20*1000) return
        SendClientMessage(playerid,"No longer than 20 seconds");
This checks if the time of the gametext exceeds 20 seconds it sends an error if it does you can change this.

7.
Code:
GameTextForAll(text, time, style);
finally if there are no problems it sends a gametext to all.

Please +rep me if you like my work.Thank you.

Have a nice day......
Reply
#2

You have some argument type mismatch.
It's
pawn Code:
SendClientMessage(playerid,COLOR,"Invalid style");
Not
pawn Code:
SendClientMessage(playerid,"Invalid style");
Reply
#3

Quote:
Originally Posted by Kostas'
View Post
You have some argument type mismatch.
It's
pawn Code:
SendClientMessage(playerid,COLOR,"Invalid style");
Not
pawn Code:
SendClientMessage(playerid,"Invalid style");
sorry i had forgotten now edited!!!!!!!!!
Reply
#4

its simple and nice. 4/5.
Reply
#5

I think you made a error
pawn Code:
if(IsPlayerAdmin(playerid))
        return SendClientMessage(playerid, "You are not allowed to use this command");
Should be
pawn Code:
if(!IsPlayerAdmin(playerid))
        return SendClientMessage(playerid, "You are not allowed to use this command");
So it will only work for rcons
Reply
#6

I am sorry for all errors as in my server i dont use rcon i use P_DATA etc etc so maybe i made a mistake soryy!
Reply
#7

There's a couple of mistakes in the code but other than that it works great!
Reply
#8

Apologies for my old post sayin about that it only works for players, atleast the good part is the announce command works like kuddie said. Good job §с†¶e®РµРe or w/e your name is XD.
Reply
#9

Nice
Reply
#10

Thanks
Reply
#11

Good work man 10/10 very good job
Reply
#12

Quote:
Originally Posted by BlackRolePlay
Посмотреть сообщение
Good work man 10/10 very good job
Thanks
Reply
#13

Just use

PHP код:
SendClientMessage(playerid, -1"Text"); 
Instead of puttin in the colour, etc... Plus atm you have argument type mismatch, you might wanna fix em.
Reply
#14

Nice tut,i added this on my DM server xD
Reply
#15

No Problem
Reply
#16

simple and nice, thnx
Reply
#17

I have read all the instructions, but when I compile I get Errors!!!:
Код:
C:\Users\Adonay\Desktop\samp03e_svr_R2_win32TEST\filterscripts\announce.pwn(1) : fatal error 100: cannot read from file: "zcmd" C:\Users\Adonay\Desktop\samp03e_svr_R2_win32TEST\filterscripts\announce.pwn(1) : fatal error 100: cannot read from file: "sscanf"
Here is the filterscript Filterscript:
Код:
#include <a_samp>
#include <zcmd>
#include <sscanf>

CMD:announce(playerid, params[])
{

    if(IsPlayerAdmin(playerid))
		return SendClientMessage(playerid, "You are not allowed to use this command");

    new text[64], time, style;
    if (sscanf(params, "iis[64]", style, time, text)) return
        SendClientMessage( playerid,"Usage: /announce <style[0-6]> <time in ms> <text>");

    if (strlen(text) > 64) return
        SendClientMessage(playerid,"Message too long please shorten it ");

    if(style == 2) return SendClientMessage(playerid,"Bug with style 2 don't use it!");

    if (style < 0 || style > 6) return
        SendClientMessage(playerid,0x854900FF,"Invalid style");

    if (time > 20*1000) return
        SendClientMessage(playerid,"No longer than 20 seconds");

    GameTextForAll(text, time, style);

    return true;
}
Reply
#18

200.000 tutorials on how to create commands using sscanf and zcmd..
1/10.
Reply


Forum Jump:


Users browsing this thread: 9 Guest(s)