[Tutorial] Random Messages (Yes another one)
#1

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! (:
Reply
#2

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

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

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

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
Reply
#6

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

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.
Reply
#8

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.
Reply
#9

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
Reply
#10

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
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)