[Tutorial] Making random messages
#1

Hello there, and thank you for viewing this tutorial. First of all, i would like to let you know that i know there are a lot of these tutorials around, but I plan on fully explaining everything.

Firstly, we will need to forward our timer, otherwise we will receive an error that a 'public function lacks forward declaration'. Example:
pawn Код:
forward MyTimer();
Secondly, find OnGameModeInit/OnFilterscriptInit, or wherever you plan to use the timer. I plan on using ongamemodeinit/onfilterscriptinit as it is when the server is started. Example:
pawn Код:
// under ongamemodeinit/onfilterscriptinit
SetTimer("MyTimer",600000,1); // Repeating timer, every 10 mins
Now, we will make our timer. The below code has multiple comments to tell you what each thing does, so it isn't just copying and pasting:
pawn Код:
public MyTimer()
{
     new rand = random(4); // We will have 4 different random messages, and rand is either 0, 1, 2 or 3
     if(rand == 0) SendClientMessageToAll(0xFFFFFFFF,"My first message!"); // If the random number is equal to 0, it sends the 1st message in a white colour
     else if(rand == 1)SendClientMessageToAll(0xFFFFFFFF,"My second message!"); // If the random number is equal to 1, it sends the 2nd message in a white colour
     else if(rand == 2)SendClientMessageToAll(0xFFFFFFFF,"My third message!"); // If the random number is equal to 2, it sends the 3rd message in a white colour
     else if(rand == 3)SendClientMessageToAll(0xFFFFFFFF,"My fourth message!"); // If the random number is equal to 3, it sends the 4th message in a white colour
     return 1;
}
Constructive criticism is always welcome, just no insults e.g. "You suck, you never explain anything" or whatever. This was made for scripting newbies that may want random messages. If there is anything which isn't explained well, tell me, and i will edit the tutorial. Thank you for viewing this, and don't forget to post your opinion of it!
Reply


Messages In This Thread
Making random messages - by bensmart469 - 20.10.2013, 13:34
Re: Making random messages - by Akira297 - 20.10.2013, 13:36
Re: Making random messages - by XStormiest - 20.10.2013, 14:02
Re: Making random messages - by bensmart469 - 20.10.2013, 21:46
Re: Making random messages - by Twizted - 20.10.2013, 21:46
Re: Making random messages - by bensmart469 - 20.10.2013, 21:50
Re: Making random messages - by [WA]iRonan - 21.10.2013, 10:08
Re: Making random messages - by Vince - 21.10.2013, 15:38

Forum Jump:


Users browsing this thread: 2 Guest(s)