30.08.2014, 21:21
Hello SA-MP forums, this is the first time creating a tutorial I thought I'd choose something simple and then later one I'd be able to take suggestions and create them.
Anything wrong with it? Feel free to PM me/comment.
Quick notice, I'm starting this from scratch so I'll leave in the auto-generated text, for example in OnGameModeInit
Let's start with defining some colours,
you can use #define to define let's say colours, but other things too.
Let's add these in
Okay, we have used this, what does it mean?
#define, speaks for itself it gives a word a definition.
"BLUE" is what we want to be defined
When working with colors, use colorpicker.com it's quite handy,
but when using #define make sure you add in a 0x[COLORCODE]FF or else it won't work.
Later when you're adding in different colours in let's say a SendClientMessage you can put them between {} but that'll come later.
Now, we're going to create a timer.
Head to "public OnGameModeInit()"
and then add under your defines this
Looks easy doesn't it?
We're using the function "SetTimer".
When you use SetTimer you will ALWAYS need to use a forward to forward it or else it's going to give errors.
It's mostly used like this SetTimer("TimerName", Milliseconds, true/false)
TimerName can be almost anything, not anything that has been used already to avoid confusion.
Milliseconds, 1 second = 1000 in SetTimer, so we used 60000 which is 60 seconds.
true/false, when true it will keep repeating, false it will only be executed.
Now, to make the timer do something, we need add a public AutoMessages
Let's break this down!
As you might know, when creating timers that you want to do something, make a public TIMERNAME();
Quick FYI: If you want it to use things like playerid, add it between the brackets of the forward and the public.
new randomMsg = random(2);
Here, I've created a new integer, and interger is mostly a number.
random(2) is basically telling the script to choose out of 2 random numbers (0 and 1)
You could use random(6) so it'll end up choosing between (0, 1, 2, 3, 4, 5)
if(randomMsg == 0)
this will check what the value for the randomMsg is set.
else if(randomMsg == 1)
Normally you could use if(randomMsg == 1)
but in the future if you work with bigger scripts this might come in handy because if it skips the first if, it will check else if randomMsg is equal to 1 and ONLY when it's equal to 1 or else it'll do it even when it's let's say 7.
And there is your automatic message! Here's the full script that I'm using at the moment to create this.
If you need ANY help feel free to ask me!
http://pastebin.com/7pGQ0bRJ
Thanks for reading through this, this is my first tutorial and I'm not the best at explaining hopefully you get it now!
Anything wrong with it? Feel free to PM me/comment.
Quick notice, I'm starting this from scratch so I'll leave in the auto-generated text, for example in OnGameModeInit
Let's start with defining some colours,
you can use #define to define let's say colours, but other things too.
Let's add these in
Code:
#define BLUE 0x4C1DF5FF #define GREY 0xB9B8BAFF
#define, speaks for itself it gives a word a definition.
"BLUE" is what we want to be defined
When working with colors, use colorpicker.com it's quite handy,
but when using #define make sure you add in a 0x[COLORCODE]FF or else it won't work.
Later when you're adding in different colours in let's say a SendClientMessage you can put them between {} but that'll come later.
Now, we're going to create a timer.
Head to "public OnGameModeInit()"
Code:
public OnGameModeInit() { SetTimer("AutoMessages", 60000, true); SetGameModeText("Blank Script"); AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0); return 1; }
Code:
forward AutoMessages();
We're using the function "SetTimer".
When you use SetTimer you will ALWAYS need to use a forward to forward it or else it's going to give errors.
It's mostly used like this SetTimer("TimerName", Milliseconds, true/false)
TimerName can be almost anything, not anything that has been used already to avoid confusion.
Milliseconds, 1 second = 1000 in SetTimer, so we used 60000 which is 60 seconds.
true/false, when true it will keep repeating, false it will only be executed.
Now, to make the timer do something, we need add a public AutoMessages
Code:
public AutoMessages() { new randomMsg = random(2); if(randomMsg == 0) { SendClientMessageToAll(BLUE, "Thanks for playing on my server! :)"); } else if(randomMsg == 1) { SendClientMessageToAll(GREY, "Is someone cheating? Tell an admin!"); } }
As you might know, when creating timers that you want to do something, make a public TIMERNAME();
Quick FYI: If you want it to use things like playerid, add it between the brackets of the forward and the public.
new randomMsg = random(2);
Here, I've created a new integer, and interger is mostly a number.
random(2) is basically telling the script to choose out of 2 random numbers (0 and 1)
You could use random(6) so it'll end up choosing between (0, 1, 2, 3, 4, 5)
if(randomMsg == 0)
this will check what the value for the randomMsg is set.
else if(randomMsg == 1)
Normally you could use if(randomMsg == 1)
but in the future if you work with bigger scripts this might come in handy because if it skips the first if, it will check else if randomMsg is equal to 1 and ONLY when it's equal to 1 or else it'll do it even when it's let's say 7.
And there is your automatic message! Here's the full script that I'm using at the moment to create this.
If you need ANY help feel free to ask me!
http://pastebin.com/7pGQ0bRJ
Thanks for reading through this, this is my first tutorial and I'm not the best at explaining hopefully you get it now!