SA-MP Forums Archive
[Tutorial] Making a /announce command in ZCMD and sscanf - 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] Making a /announce command in ZCMD and sscanf (/showthread.php?tid=297689)



Making a /announce command in ZCMD and sscanf - §с†¶e®РµРe - 17.11.2011

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......


Re: Making a /announce command in ZCMD and sscanf - Kostas' - 17.11.2011

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



Re: Making a /announce command in ZCMD and sscanf - §с†¶e®РµРe - 17.11.2011

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!!!!!!!!!


Re: Making a /announce command in ZCMD and sscanf - Astralis - 19.11.2011

its simple and nice. 4/5.


Re: Making a /announce command in ZCMD and sscanf - Tanush123 - 25.11.2011

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


Re: Making a /announce command in ZCMD and sscanf - §с†¶e®РµРe - 26.11.2011

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!


Re: Making a /announce command in ZCMD and sscanf - Kuddie - 29.11.2011

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


Re: Making a /announce command in ZCMD and sscanf - Tanush123 - 30.11.2011

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.


Re: Making a /announce command in ZCMD and sscanf - Rudy_ - 30.11.2011

Nice


Re: Making a /announce command in ZCMD and sscanf - §с†¶e®РµРe - 10.12.2011

Thanks


Re: Making a /announce command in ZCMD and sscanf - BlackRolePlay - 10.12.2011

Good work man 10/10 very good job


Re: Making a /announce command in ZCMD and sscanf - §с†¶e®РµРe - 11.12.2011

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


Re: Making a /announce command in ZCMD and sscanf - =WoR=G4M3Ov3r - 11.12.2011

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.


Re: Making a /announce command in ZCMD and sscanf - ComiGF - 21.12.2011

Nice tut,i added this on my DM server xD


Re: Making a /announce command in ZCMD and sscanf - §с†¶e®РµРe - 01.01.2012

No Problem


Re: Making a /announce command in ZCMD and sscanf - $$inSane - 06.05.2012

simple and nice, thnx


Re: Making a /announce command in ZCMD and sscanf - xMaGmOtAnEtHx - 18.08.2012

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;
}



Re: Making a /announce command in ZCMD and sscanf - im - 18.08.2012

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