20.10.2013, 13:34
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:
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:
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:
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!
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();
pawn Код:
// under ongamemodeinit/onfilterscriptinit
SetTimer("MyTimer",600000,1); // Repeating timer, every 10 mins
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;
}