[Tutorial] Random Automatic Server Messages
#1

Introduction
Hey guys, how are you?
I wanted to start writing some tutorials for the SA-MP Community.
At first, I'd like to start low, with some really simple tutorials. After that, I'll probably move on to some more complicated tutorials. ATM This is my first tutorial here, so I'll be happy to get suggestions from you .
Let's start?

What we're making
We're going to make an Random Automatic Server Messages system.
Every hour (Of course you'll be able to change the time by yourself in the define), there is going to be a random server message (from a variable).

Tutorial
First, let's create a new FS (FilterScript). We're going to start clean, so just create a new file and save it as "ASM.pwn" (Feel free to change the name to w/e you want ) in your filterscripts directory.

Now, let's write this down:
pawn Code:
#include <a_samp>
That's basically an include file that has to be in every new FS/GM you make.

After that, let's add this line:
pawn Code:
#define MESSAGE_TIME 3600000 // 1000 = 1 sec
We defined here the time for each server message. 1000 is equal to 1 second. Therefore, 3600000 = 1 hour.

Okay, let's make the server message array variable.
Add this:
pawn Code:
new ServerMessages[3][] = {
    "This is our first server message!",
    "This FS rules! Already second message, huh?",
    "I'm sexy and I know it."
};
This is a variable called "ServerMessages" which is an array that contains 3 cells (When you make an array, you start counting from 0. Therefore, you always need at least 1 more cell when you define the variable itself. I made 3 because I have 0,1,2 messages, and +1 more).
The messages are:
Quote:

"This is our first server message!"
"This FS rules! Already second message, huh?"
"I'm sexy and I know it."

Now, let's add the timer which shows the messages. Shall we?
Add this line below the variable:
pawn Code:
forward ShowSM();
This basically forwards our new function. If we're going to make a function (public), than we must forward it first.

Now, add this:
pawn Code:
public ShowSM() {
    new RandomSM = random(sizeof(ServerMessages));
    SendClientMessageToAll(0xFFFFFFAA, ServerMessages[RandomSM]);
}
Let me explain what we've done here.
The first line declares that this is a public (function).
After that, we made a new variable called "RandomSM", which is going to be a random number from the "ServerMessages" array. The function "random" picks a random number from 0 to the max. number defined inside the parenthesis (). In this case, we didn't want like the number 100. Therefore, we inserted the "sizeof" function which in this case, returns the amount of cells in the array.

Finally, let's add this:
pawn Code:
public OnFilterScriptInit() {
    SetTimer("ShowSM", MESSAGE_TIME, true);
    return 1;
}
The public "OnFilterScriptInit" is called when the FS is loaded (when you start samp-server.exe).
Then we set a timer for the public "ShowSM", with the interval of "MESSAGE_TIME" (1 hour in this case), with the parameter true (repeating).

Enjoy guys , and have a nice day.
Reply
#2

http://forum.sa-mp.com/showthread.ph...andom+messages
http://forum.sa-mp.com/showthread.ph...andom+messages
http://forum.sa-mp.com/showthread.ph...andom+messages
http://forum.sa-mp.com/showthread.ph...andom+messages
http://forum.sa-mp.com/showthread.ph...andom+messages
https://sampwiki.blast.hk/wiki/Random_Messages
Reply
#3

Oops? :P
Hmm.. didn't know there's that much out there. Sorry :S
Reply
#4

Maybe make a tutorial about Random messages , using textdraws
Reply
#5

Quote:
Originally Posted by Mr.Fames
View Post
Maybe make a tutorial about Random messages , using textdraws
Yes, it will be a good Idea,like LAdmin script has. But anyway 5/5 because it is well explained. Hope you`ll have succes !
Reply
#6

Quote:
Originally Posted by Mr.Fames
View Post
Maybe make a tutorial about Random messages , using textdraws
There is already tutorial for this too
Check Dripac's Random Textdraw Tutorial.
Reply
#7

Thank you guys .
And I might do that tutorial too. There's only one.
UPDATE: https://sampforum.blast.hk/showthread.php?tid=341561
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)