[Tutorial] Random Messages [Simple]
#1

Hi guys,

Some people have been asking me how to add random messages into your gamemode because
they can't do it. So I'm going to show you how to add it in your script step by step.

You can define any of the below colors into your script.
pawn Code:
#define COLOR_GREEN         0x33AA33AA
#define COLOR_GREY          0xAFAFAFAA
#define COLOR_WHITE         0xFFFFFFAA
#define COLOR_YELLOW        0xFFFF00AA
#define COLOR_BLUE          0x0000BBAA
#define COLOR_ORANGE        0xFF9900AA
#define COLOR_RED           0xCC0000AA
Then you will need to forward the Random Messages function.
pawn Code:
//Forwards//
forward RandomMessages();
We will be defining the random messages in this function.
pawn Code:
//Random Messages//
new RandomMessages[][] =
{
       "Message 1 (Change this)",
       "Message 2 (Change this)",
       "Message 3 (Change this)"
};
Then we will need to set a timer for the Random Messages and the timer will
be placed below the public OnGameModeInit() function:
pawn Code:
public OnGameModeInit()
{
     SetTimer("RandomMessages",95000,1);
     return 1;
}
You will need to find an empty place in your script to add this callback.
This will get the Random Messages from above and send them as a client message.
pawn Code:
public RandomMessages()
{
     SendClientMessageToAll(COLOR_GREEN, RandomMessages[random(sizeof(RandomMessages))];
     return 1;
}
If this works for you, please feel free to rep me.

- Sean aka Sniperwars
Reply
#2

i don't see the thing called explanation.
Reply
#3

Simple but it's okay.

Someone already made a tutorial like this.
Reply
#4

This isn't a tutorial, you just past the code and say add this^^ 0/10
Reply
#5

This is just copied from a filterscript.

When making a tutorial you should explain in detail why and how you do it.
Reply
#6

By the way, it wouldn't work ANYWAYS, lol! Where are you telling the script to send them random? It has to look like (for example) this:

pawn Code:
public RandomMessages()
{
    new randomMsg = random(sizeof(randomMessages));
    SendClientMessageToAll(COLOR_ORANGERED, randomMessages[randomMsg]);
}
Reply
#7

Quote:
Originally Posted by Twisted_Insane
View Post
By the way, it wouldn't work ANYWAYS, lol! Where are you telling the script to send them random? It has to look like (for example) this:

pawn Code:
public RandomMessages()
{
    new randomMsg = random(sizeof(randomMessages));
    SendClientMessageToAll(COLOR_ORANGERED, randomMessages[randomMsg]);
}
Actually, the way he does it works as well. Doesn't change the fact that this isn't a tutorial but just a bunch of code though.
Reply
#8

Hiddos, tell me how the hell the concept would work? They should become "RANDOM messages", what he does is just sending them to all! He has to get out the info outta the arrray and define them randomly with the function.
Reply
#9

Quote:
Originally Posted by Twisted_Insane
View Post
By the way, it wouldn't work ANYWAYS, lol! Where are you telling the script to send them random? It has to look like (for example) this:

pawn Code:
public RandomMessages()
{
    new randomMsg = random(sizeof(randomMessages));
    SendClientMessageToAll(COLOR_ORANGERED, randomMessages[randomMsg]);
}
For the information, this is correct:
Code:
SendClientMessageToAll(COLOR_GREEN, RandomMessages[random(sizeof(RandomMessages))];
It works just fine, if you look very carefully you'll see the 'random' function is inside the array. If you still don't see it, here it is:
Code:
SendClientMessageToAll(COLOR_GREEN, RandomMessages[random(sizeof(RandomMessages))];
It works fine. In every parameter where you can put a number, it's also possible to put a function that returns a number, in this case the function is 'random'. You get it?


But still, this isn't a tutorial. Tutorials are supposed to teach people new stuff, and what new stuff have they learned here. How to copy and paste? Oh wait, not. It's not even explained how you can copy or paste a text.
Reply
#10

Quote:
Originally Posted by Twisted_Insane
View Post
Hiddos, tell me how the hell the concept would work? They should become "RANDOM messages", what he does is just sending them to all! He has to get out the info outta the arrray and define them randomly with the function.
he has directly put the random part inside.

SendClientMessageToAll(COLOR_GREEN, RandomMessages[random(sizeof(RandomMessages))];

instead of

new randomMsg = random(sizeof(randomMessages));
SendClientMessageToAll(COLOR_ORANGERED, randomMessages[randomMsg]);

so you can see, that randomMsg is equal to random(sizeof(randomMessages)) so
randomMessages[randomMsg] = RandomMessages[random(sizeof(RandomMessages))
which is basically the same
Reply
#11

Quote:
Originally Posted by Twisted_Insane
View Post
Hiddos, tell me how the hell the concept would work? They should become "RANDOM messages", what he does is just sending them to all! He has to get out the info outta the arrray and define them randomly with the function.
Try it out, it'll output random stuff.
Reply
#12

Quote:
Originally Posted by Twisted_Insane
View Post
Hiddos, tell me how the hell the concept would work? They should become "RANDOM messages", what he does is just sending them to all! He has to get out the info outta the arrray and define them randomly with the function.
Ok lets go in to detail
Code:
SendClientMessageToAll(COLOR_GREEN, RandomMessages[random(sizeof(RandomMessages))];

SendClientMessageToAll <- Function
COLOR_GREEN <- Color
RandomMessages[random(sizeof(RandomMessages)) <- Random
random(sizeof(RandomMessages)
Choosing a random NUMBER from randommessages, because he putted sizeof, so it will get a number.
So say it was 4, its exactly the same as doing:
RandomMessages[4]
Reply
#13

Looks completely like my tutorial xD

but mine is just with textdraws

https://sampforum.blast.hk/showthread.php?tid=327709
Reply
#14

For fuck sake guys, excuse me for posting a tutorial.
People script different to other people and besides, I didn't copy that
from the SA-MP wiki, I actually scripted that from scratch.
Reply
#15

If that's the case, then consider explaining what each individual line does, or assemble some sort of code-roundup, where you explain which part does what.
Reply
#16

Quote:
Originally Posted by sniperwars
View Post
For fuck sake guys, excuse me for posting a tutorial.
People script different to other people and besides, I didn't copy that
from the SA-MP wiki, I actually scripted that from scratch.
I do believe you. Have I ever said that I didn't? But still, this isn't a tutorial. The person who's reading it doesn't learn anything from this. You explain nothing about the functions you use. For example: what does SetTimer do and how does it work? Some people might not know this.
Reply
#17

its ok.. and simple. nice
Reply
#18

Thank's for this thread.
I Wanted to know how to create Random Messages,
And Now I know.
Reply
#19

// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT

#include <a_samp>
#if defined FILTERSCRIPT
#else
#endif

#define COLOR_GREEN 0x33AA33AA
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_WHITE 0xFFFFFFAA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_BLUE 0x0000BBAA
#define COLOR_ORANGE 0xFF9900AA
#define COLOR_RED 0xCC0000AA

//Forwards//
forward RandomMessages();

//Random Messages//
new RandomMessages[][] =
{
"Message 1 (Change this)",
"Message 2 (Change this)",
"Message 3 (Change this)"
};

public OnGameModeInit()
{
SetTimer("RandomMessages",95000,1);
return 1;
}

public RandomMessages()
{
SendClientMessageToAll(COLOR_GREEN, RandomMessages[random(sizeof(RandomMessages))];
return 1;
}



//Get To me Eror :
C:\Users\Richard\Desktop\RandomPms.pwn(36) : error 021: symbol already defined: "RandomMessages"
C:\Users\Richard\Desktop\RandomPms.pwn(37) : error 028: invalid subscript (not an array or too many subscripts): "RandomMessages"
C:\Users\Richard\Desktop\RandomPms.pwn(37) : error 072: "sizeof" operator is invalid on "function" symbols
C:\Users\Richard\Desktop\RandomPms.pwn(37) : error 029: invalid expression, assumed zero
C:\Users\Richard\Desktop\RandomPms.pwn(37) : fatal error 107: too many error messages on one line
Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
5 Errors.
Reply
#20

Can you give me the whole code ?
I can't read this shit.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)