SA-MP Forums Archive
[Tutorial] Random Messages (Yes another one) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Random Messages (Yes another one) (/showthread.php?tid=292330)



Random Messages (Yes another one) - FireCat - 23.10.2011

Brief introduction
Hello aprentices.
Yes another "random messages" tutorial, but I'll try to explain it has good has I can (:

Resources
For this tutorial, you won't need to download anything, however you will need to create a few this.
Lets check the functions:
Creating the array
Alright lets start the practic and theoric method. (:
First of all we will have to create a "section" of what we call '2d array'
pawn Code:
new RandomMessages[][] = //Creating the array, and leaving the [][] empty so you can create as many messages as you want.
{
"Random message 1",//Message nr.1, we put them in quotes because it's a string.
"[HiC]TheKiller stinks",//Exactly the same
"Blood is a mawd."//The same, but without the coma because it's the last one, leading the pawn compiler to say "It's the last one of this array".
};
Every time you want to create some text for some function or send any message,
You have to add them in quotes, otherwise it's another symbol, and of course it will give an error.
For example this:
pawn Code:
new sometext[4] = "Yes"; //3 cells for the text, and 1 for pawn.
Is like x1000 times different from:
pawn Code:
new sometext[4] = Yes;
If you ever want to do it like the 2nd way, there is a possibilty, but you would have to define it first.
So it would become like this:
pawn Code:
#define Yes "Yes"//Noticed we added the quotes?
new sometext[4] = Yes;
Forwarding
Ok, now that we have our array created, lets forward the timer.
Before "OnGameModeInit", add this:
pawn Code:
forward SendRandomMessage();
Q: So what's the difference between Stock and Public? Because stock we don't have to write "forward"...
A: It's a bit simple, well first of all, you can't use stocks for timers, so there is the main reason.
Second of all, publics can't return strings, and stocks can.
For example:
pawn Code:
stock ReturnAdminLevelAsString(playerid,level)
{
switch(level)
{
case 1: return "Level 1";//If the player has level 1 it will return has a text "Level 1".
case 2: return "Level 2";//If the player has level 2 it will return has a text "Level 2".
}
return "Level 0";//Else if the level doesn't match any from above it will return "Level 0";
}
You can't do that example with public.

Ok back to the tutorial, after you forwarded the timer, under OnGameModeInit add this:
pawn Code:
SetTimer("SendRandomMessage",30000,true);
The parameters of SetTimer are:
  1. "SendRandomMessage" - This is the callback that we want to call
  2. 30000 - This is the interval between each call in milliseconds (ms). 1000 ms equals one second.
  3. true - This parameter tells the timer to repeat itself. It can also be set to 'false', in which case it will only run once.
//Credits to hiddos (freakin' annoying bird)
Ok compiled and no errors? Great!

Creating the public function
Alright, after forwarding our timer, and setting the timer, we have to create some function,
So it can actually send a random message to everyone (:
Ok, so at the end of your game mode add this:
pawn Code:
public SendRandomMessage()
{
new ChosenMessage = random(sizeof RandomMessages);//Choosing a random message from our array with the random messages that we created before.
SendClientMessageToAll(-1,RandomMessages[ChosenMessage]);//Sending the message to everyone, with the chosen message, that the server randomly choose.
return 1;//We couldn't put here "return SendClientMessage..." because this is a public, not a stock.
}
The end
Ok, if you followed all the steps, and got no errors, try loading the the server and go in game! (:
CAUTION: I did not test the script, so please tell me if it worked or if you're getting any errors, so we can discuss about it.
Bye bye and good luck! (:


Re: Random Messages (Yes another one) - [MWR]Blood - 23.10.2011

CAUTATION
It's CAUTION u nub
otherwise nice, unawd.


Re: Random Messages (Yes another one) - Kostas' - 23.10.2011

Nice!
1 question, where these messages appears. On chat or somewhere else on the screen?


Re: Random Messages (Yes another one) - vassilis - 23.10.2011

..Its good and well explained for new scripters.
**ITS Caution


Re: Random Messages (Yes another one) - FireCat - 23.10.2011

Quote:
Originally Posted by Kostas'
View Post
Nice!
1 question, where these messages appears. On chat or somewhere else on the screen?
On the chat (SendClientMessage)
Quote:
Originally Posted by vassilis
View Post
..Its good and well explained for new scripters.
**ITS Caution
Lol thanks :b


Re: Random Messages (Yes another one) - Vince - 23.10.2011

Quote:
Originally Posted by topic title
(Yes another one)
What's the point?


Re: Random Messages (Yes another one) - FireCat - 23.10.2011

Quote:
Originally Posted by Vince
View Post
What's the point?
Are you dumb or something?
There are like 100 of them, and 1000 release of them.
But I tried to explain more than the others.
If your post after this one if going to be a raged one, I'm reporting you.


Re: Random Messages (Yes another one) - Biesmen - 23.10.2011

Quote:
Originally Posted by FireCat
View Post
Are you dumb or something?
There are like 100 of them, and 1000 release of them.
But I tried to explain more than the others.
If your post after this one if going to be a raged one, I'm reporting you.
Take a look at my signature and take that filterscript as an example.


Re: Random Messages (Yes another one) - FireCat - 23.10.2011

Quote:
Originally Posted by Biesmen
View Post
Take a look at my signature and take that filterscript as an example.
Ok take a look at this: https://sampforum.blast.hk/showthread.php?tid=286396


Re: Random Messages (Yes another one) - Kostas' - 23.10.2011

Quote:
Originally Posted by FireCat
View Post
On the chat (SendClientMessage)
Great! I wanted one on the Chat, because I have already one under the map