[Tutorial] Admin /announce with gametext - Easy
#1

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
Reply
#2

Thanks! Really useful definitely going to use this!
Reply
#3

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

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

Very basic but well defined man KEEP IT UP
Reply
#6

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

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.
Reply
#8

A couple of things I noticed:
  • You don't check to verify the value is actually positive only above 8.
    pawn Code:
    if(ty >= 0 && ty <= 7)
    {
          // code here
    }
    else // rejection code
    or more like how you did it:
    pawn Code:
    if(ty < 0 || ty > 6) return // message
    else if(ty == 2) return // message
  • You don't check to make sure there is an equal balance of ~ characters(I gave you code and an example for this in your other thread).
Reply
#9

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
Reply
#10

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


Forum Jump:


Users browsing this thread: 1 Guest(s)