[Tutorial] How to make Random weather.
#1

Hello SA-MP members. I had this in my GM for a long time, so i thought i should not be the only one to know how to do it.
So i decided to share it with you all. I think it would be great for RP servers like mine.

Here goes, we need to make a new variable.

pawn Код:
new Weather;
Then we need to make a function and forward it.

pawn Код:
forward RandomWeather();
public RandomWeather()
{

}
That by itself will do nothing so here is where the advance part comes in.
We need a Timer to set when to change the weather. Put the timer under, "OnGamModeInit();"

pawn Код:
SetTimer("RandomWeather",60000,true);//This sets the timer that will be repeated for 1 minute (1000 ms = 1 second) hence 1000 x 60 = 60000 (1 minute)
Now we will soon be finished but we need to add the rest of what the function will do.

pawn Код:
public RandomWeather()
{
    Weather = random(20);//The variable that we created will hold the random weather.
    SetWeather(Weather);//This will set the weather to a random number which is held in the variable "Weather"
}
I suggest you look here: Click Me, for the ids of the weather so you can know what you want.

We are finished. Thanks for reading and Learning.
Reply
#2

Hey thanks!
Really helpful and useful.
Just one minor question: Where do I put the 'public GlobalWeather()' ?
Reply
#3

Did you even try to compile your script?

pawn Код:
forward RandomWeather();
public GlobalWeather()
You forward a public named "RandomWeather" but the public itself is named "GlobalWeather".

Also, there is no need for a global variable.

pawn Код:
public GlobalWeather()
{
    return SetWeather(random(20)); //This will set the weather to a random number which is held in the variable "Weather"
}
Reply
#4

Quote:

forward RandomWeather();
public GlobalWeather()
{

}

Why the fuck are you messing up the headers?

EDIT: Too late
Reply
#5

So if I am right, I only need to use
Quote:

public GlobalWeather()
{
return SetWeather(random(20)); //This will set the weather to a random number which is held in the variable "Weather"
}

and i'm done?
Reply
#6

pawn Код:
SetTimer("RandomWeather",60000,true); // In OnGameModeInit
forward RandomWeather(); // Outside any other callback
public RandomWeather() // Outside any other callback
{
   return SetWeather(random(20));
}
Yes
Reply
#7

That is brilliant man. Thank you!
Reply
#8

Garison sorry it is fixed. And Thanks to you all.

This is even easier.

Quote:
Originally Posted by [03]Garsino
Посмотреть сообщение
pawn Код:
SetTimer("RandomWeather",60000,true); // In OnGameModeInit
forward RandomWeather(); // Outside any other callback
public RandomWeather() // Outside any other callback
{
   return SetWeather(random(20));
}
Yes
Reply
#9

How can I make the weather be set between a number of values given by me? for example I want only 3 weather ID's. 20 15 and 7.
Reply
#10

Quote:
Originally Posted by HeLiOn_PrImE
Посмотреть сообщение
How can I make the weather be set between a number of values given by me? for example I want only 3 weather ID's. 20 15 and 7.
im not sure who made this simple stock but i know it was not me

pawn Код:
stock RandomNumber(...)
    return getarg(random(numarg()));

//use it like


SetTimer("RandomWeather",60000,true); // In OnGameModeInit
forward RandomWeather(); // Outside any other callback
public RandomWeather() // Outside any other callback
{
   return SetWeather(RandomNumber(20,15,7));
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)