SA-MP Forums Archive
[Tutorial] Admin /announce with gametext - Easy - 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] Admin /announce with gametext - Easy (/showthread.php?tid=594176)



Admin /announce with gametext - Easy - Karan007 - 14.11.2015

Hello guys,

this is a tutorial on how to make an /announce command for admins. This is a really easy script to make. I made this tutorial for newbies who don't know how to make this command. Let's start it now!


Scripting.

PHP Code:
CMD:announce(playerid,params[])

This specifies the command announce and we are opening braces.

PHP Code:
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1"Error: You are not rcon logged in!"
This means if he is not rcon logged in, it will return the following message. We'll split this a bit. "!" this specifies "if not". Splitting - if(!IsPlayerAdmin(playerid)) ; Let's split this bit of code. If that player IS NOT admin;

PHP Code:
    new msg[25], tytime
so we will use the msg as the string ; 25 specifies how many letters should the string contains.

PHP Code:
    if(sscanf(params"iis[25]"timetymsg)) return SendClientMessage(playerid, -1"Usage: /announce [Time] [Msg Type] [TEXT]"); 
This checks the parameters and if he didn't wrote the parameters correctly, then it will send that "Usage" message.

|----------ADDITIONAL NOTES----------|
i - Integer (Number) - Used as time
i - Integer (Number) - Used as the type
s - String (Letters) - Used for the message
|---------------------------------------|


Now, we will restrict the type 2 that is bugged.

This code checks if he wrote the "ty" as 2,0 or more than 8 and if he did, the server will return the "Error" message.

PHP Code:
    if(ty >= || ty <= || ty == 2) return SendClientMessage(playerid, -1"Only 1,3,4,5,6,7"); 
Now, let's move on to the final code.
PHP Code:
    GameTextForAll(msgtimety);
    return 
1;

This sends all the players the message by the msg we wrote, with the time to stop the message and the type. Returning 1 will execute the command.

|-USING COLORS-|

We can also use colors in them. An example is below.

/announce 5000 4 ~r~ <- Red color ~b~ <- Blue color

|-FULL CODE-|

PHP Code:
CMD:announce(playerid,params[])
{
    if(!
IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1"Error: You are not rcon logged in!");
    new 
msg[25], tytime;
    if(
sscanf(params"iis[25]"timetymsg)) return SendClientMessage(playerid, -1"Usage: /announce [Time] [Msg Type] [TEXT]");
    if(
ty >= || ty == || ty == 2) return SendClientMessage(playerid, -1"Only 1,3,4,5,6,7");
    
GameTextForAll(msgtimety);
    return 
1;

|-END OF TUTORIAL-|

I made another tutorial |-Click here-| This tutorial contains more detailed in formatting, you guys can check it out for more information about formatting message in dialogs. And it is also useful for gametext.

Credits

Karan007 - Created this tutorial/script
SA-MP Team - Created SA-MP
Y_Less - Sscanf
Zeex - ZCMD



Enjoy


Re: Admin /announce with gametext - Easy - Hellceaser - 14.11.2015

Thanks! Really useful definitely going to use this!


Re: Admin /announce with gametext - Easy - SecretBoss - 14.11.2015

Nothing special, but as I can see you explained everything very well, it's kinda useful for new guys on scripting


Re: Admin /announce with gametext - Easy - Karan007 - 14.11.2015

Thanks you all, thread has been updated with gametext colors.


Re: Admin /announce with gametext - Easy - HydraHumza - 14.11.2015

Very basic but well defined man KEEP IT UP


Re: Admin /announce with gametext - Easy - thefirestate - 14.11.2015

You forget to tell sscanf how big the text string should be.

You are doing this:

PHP Code:
if(sscanf(params"iis"timetymsg)) return SendClientMessage(playerid, -1"Usage: /announce [Time] [Msg Type] [TEXT]"); 
When it should be:

PHP Code:
if(sscanf(params"iis[25]"timetymsg)) return SendClientMessage(playerid, -1"Usage: /announce [Time] [Msg Type] [TEXT]"); 
Otherwise it will produce a warning.

Anyways, you've did pretty good job and the explanations you gave are detailed enough for newbies in pawn.


Re: Admin /announce with gametext - Easy - Karan007 - 15.11.2015

Quote:
Originally Posted by thefirestate
View Post
You forget to tell sscanf how big the text string should be.

You are doing this:

PHP Code:
if(sscanf(params"iis"timetymsg)) return SendClientMessage(playerid, -1"Usage: /announce [Time] [Msg Type] [TEXT]"); 
When it should be:

PHP Code:
if(sscanf(params"iis[25]"timetymsg)) return SendClientMessage(playerid, -1"Usage: /announce [Time] [Msg Type] [TEXT]"); 
Otherwise it will produce a warning.

Anyways, you've did pretty good job and the explanations you gave are detailed enough for newbies in pawn.
No, it isn't necessary to do this. And also i had already defined the msg as 25, so we don't need to add it again.


Re: Admin /announce with gametext - Easy - Abagail - 15.11.2015

A couple of things I noticed:


Re: Admin /announce with gametext - Easy - iKarim - 16.11.2015

Nice tutorial men, good work.
but you have to add string size in sscanf, to avoid such warnings.
I prefer using sscanf macros like this:
PHP Code:
extract params -> new timetystring:s[25]; else
    return 
SendClientMessage(playerid, -1"Usage: /announce [Time] [Msg Type] [TEXT]"); 
* PawnHunter salutes


Re: Admin /announce with gametext - Easy - Karan007 - 16.11.2015

Quote:
Originally Posted by PawnHunter
View Post
Nice tutorial men, good work.
but you have to add string size in sscanf, to avoid such warnings.
I prefer using sscanf macros like this:
PHP Code:
extract params -> new timetystring:s[25]; else
    return 
SendClientMessage(playerid, -1"Usage: /announce [Time] [Msg Type] [TEXT]"); 
* PawnHunter salutes
Well, i didn't receive ANY warnings the way i used it. Anyways, i made it like you guys want it.