Random Messages
From SA-MP Wiki
Preparements
This is the tutorial about making random messages show up.
Firstly, we'll set the messages ready:
new RandomMSG[][] = { "Random Message 1", "Random Message 2", "Random Message 3" };
Secondly, we'll have to set the timer, like this (for example, OnGameModeInit):
SetTimer("SendMSG", 60000, true); // 60000ms = 60 seconds = 1 minute
Setting up the function
The function we'll use is called "SendMSG", so lets forward it (Forwarding)
forward SendMSG();
Now, lets do the function itself:
public SendMSG()
Making the message show
Head to the callback (Forwarded already, set up in somewhere in the script below main())
public SendMSG() // What it looks at the moment
So, lets open the callback (do the following as shown):
public SendMSG() { // effect }
Now, we'll do the effect at "//effect" (NOTE: "//effect" isn't some special character. "//" gives you a comment line) Simply,
new randMSG = random(sizeof(RandomMSG)); //calculates the size of RandomMSG (which is 3) SendClientMessageToAll(COLOR, RandomMSG[randMSG]); // Replace the "color" with your defined color.
So at the end we have this callback:
public SendMSG() { new randMSG = random(sizeof(RandomMSG)); SendClientMessageToAll(COLOR, RandomMSG[randMSG]); // Replace the "COLOR" with your defined color. }