Author Topic: Script_Advert - announce anything server-wide  (Read 2580 times)

Script_Advert allows you to centerprint everyone a message as an admin.
Usage: /advert message (sends advert)
/setadvtime number (sets the time the advert stays up for)

You may use control chars such as <color:fff000> and <font:impact:20> in your message, because why not?
This took 5 minutes to code, but I still want to release it because I don't like private add-ons.
I'm aware that Kalphiter released something similar, but Kalphiter is a bitch and I can't find his download.
Download
« Last Edit: May 29, 2015, 02:38:46 PM by -Setro- »


You can already send server-wide messages through the console with
talk(""); and announce("");

I understand this uses a timed center-print instead, so I guess it is a little different.

Oh, I noticed that anyone can change the time, please make that admin-only. Also, you really should specify limits on the time, so other admins won't potentially abuse it and make advert for lyfe

P.S. The ifNumber function really isn't needed for something like this. Here is your whole code in a nutshell:

Code: [Select]
//Server-Wide-Center-Print-Advert
//Originally by -Setro-
//Recoded by Gothboy for efficiency

$Advert::Pref::Time = 3;

function serverCMDAdvert(%client,%a,%b,%c,%e,%f,%g,%h,%i,%j,%k,%l,%m,%val)
{
%val = $Advert::Pref::Time;
%msg = %a SPC %b SPC %c SPC %d SPC %e SPC %f SPC %g SPC %h SPC %i SPC %j SPC %k SPC %l SPC %m;
if(!%client.isAdmin)
return;
else
centerPrintAll("\c0 Alert from " @ %client.name @ " :<br>\c6 " @ %msg @ " ",%val);
}
function serverCMDSetAdTime(%client,%msg)
{
%val = stripChars(%msg, "@#$%^&*()_+-={}|:<>?[]\;',./abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");

if(%client.isAdmin && %val >= 0 && %val <= 30)
{
messageClient(%client,'',"\c0Advert time set to \c4 " @ %val @ " ");
}
else if(%client.isAdmin)
{
messageClient(%client,'',"\c0 Please specify a number \c4-1 \c0and\c4 30 ");
echo("Advert Time Specification Error");
}
else
return;
}
Notice how I strip the characters and symbols so that you can type a%/>bcdf2aadglyp8
and still only get 28 as the outcome

You could probably even throw in a nifty little server sound

You never mention that this is just
a timed center-print
You may want to point this out to clear any confusion.
Script_Advert allows you to leave important notifications for players in minigames, and everywhere server-side, as an admin.
This doesn't explain well.
Though if you could make boards and signs that have chat-controlled text, that would be great.

fixed
also gothboy, that's not what i want, thanks for trying to help though
« Last Edit: May 29, 2015, 02:39:31 PM by -Setro- »

fixed
also gothboy, that's not what i want, thanks for trying to help though
Thanks for fixing the admin set time function.

However, when I type /setAdvTime 4b I get:
"That isnt a number" and "Advert Time Set To 4"
If you actually took the time to look at my code, you will see I have tried to show you how to avoid this simple malfunction.

Also, its a bit pointless to echo in console when someone adverts, since it's displayed to everyone in obvious center-print already. It makes better logic to only echo when someone sets the advert time, don't you think?

Also, its a bit pointless to echo in console when someone adverts, since it's displayed to everyone in obvious center-print already. It makes better logic to only echo when someone sets the advert time, don't you think?
No, I want that as an anti-abuse measure so we know who sets the time to 99999999999999

No, I want that as an anti-abuse measure so we know who sets the time to 99999999999999
Okay or you could avoid the abuse all together by setting a max time limit.
I already said to keep the echo for the time, but not for the actual message.
You'll still see who sets the time...

Anyways, what about the other issue? That's really the main problem

No, I want that as an anti-abuse measure so we know who sets the time to 99999999999999
You should use the mClamp or mClampF function (latter function supports decimal numbers) to stop people from doing absurd times.
ex: %time = mClamp(%time,1,300);
If %time < 1, it'll return 1, while if %time > 300, it'll return 300.

That %Val on the code should be the second argument, not the last.

That %Val on the code should be the second argument, not the last.
Ya. Idk. It makes more logical sense for me to display the message first, then calculate the time it stays there. Plus, if your packaging events you'd normally put that value at the end anyways.

I will keep that in mind for message functions in the future though, thanks.

centerprintall("<color:ffffff>"@ %a SPC %b SPC %c SPC %d SPC %e SPC %f SPC %g SPC %h SPC %i SPC %j,$advtime);

For every unused available word there is one additional space between message and $advtime.

Also, you should just use if($val * 1 = $val) to check if something is a number. It's generally a bad practice but works with how torquescript handles strings.
« Last Edit: May 29, 2015, 03:18:21 PM by Dannu »

Ya. Idk. It makes more logical sense for me to display the message first, then calculate the time it stays there. Plus, if your packaging events you'd normally put that value at the end anyways.

I will keep that in mind for message functions in the future though, thanks.
What if someone wants to do /advert "Watch out" 3?

What if someone wants to do /advert "Watch out" 3?
Then it simply displays "Alert From %client.name "Watch out" 3    ?
The time is specified using /setAdTime, putting a 3 at the end just adds the 3 to the message

Also, you should just use if($val * 1 = $val) to check if something is a number. It's generally a bad practice but works with how torquescript handles strings.
That could still return string values? If %val = "hello";
Also what about symbols?

Another way to do it would be strReplace but I found the strip method to function better

This seriously needs to be re-written