10.05.2012, 10:11
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:
That's basically an include file that has to be in every new FS/GM you make.
After that, let's add this line:
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:
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:
Now, let's add the timer which shows the messages. Shall we?
Add this line below the variable:
This basically forwards our new function. If we're going to make a function (public), than we must forward it first.
Now, add this:
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:
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.
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>
After that, let's add this line:
pawn Code:
#define MESSAGE_TIME 3600000 // 1000 = 1 sec
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."
};
The messages are:
Quote:
"This is our first server message!" "This FS rules! Already second message, huh?" "I'm sexy and I know it." |
Add this line below the variable:
pawn Code:
forward ShowSM();
Now, add this:
pawn Code:
public ShowSM() {
new RandomSM = random(sizeof(ServerMessages));
SendClientMessageToAll(0xFFFFFFAA, ServerMessages[RandomSM]);
}
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;
}
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.