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], ty, time;
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]", time, ty, msg)) 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 >= 8 || ty <= 0 || 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(msg, time, ty);
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], ty, time;
if(sscanf(params, "iis[25]", time, ty, msg)) return SendClientMessage(playerid, -1, "Usage: /announce [Time] [Msg Type] [TEXT]");
if(ty >= 8 || ty == 0 || ty == 2) return SendClientMessage(playerid, -1, "Only 1,3,4,5,6,7");
GameTextForAll(msg, time, ty);
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", time, ty, msg)) return SendClientMessage(playerid, -1, "Usage: /announce [Time] [Msg Type] [TEXT]");
When it should be:
PHP Code:
if(sscanf(params, "iis[25]", time, ty, msg)) 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
You forget to tell sscanf how big the text string should be.
You are doing this:
PHP Code:
if(sscanf(params, "iis", time, ty, msg)) return SendClientMessage(playerid, -1, "Usage: /announce [Time] [Msg Type] [TEXT]");
When it should be:
PHP Code:
if(sscanf(params, "iis[25]", time, ty, msg)) 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:
- 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).
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 time, ty, string: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
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 time, ty, string: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.