[Tutorial] Random Weather System
#1

Random Weather Tutorial
This Tutorial Is About creating Random a Random Weather System Which Will Change The Weather Over A Random Period Of Time ok Lets Begin

First Of all Some Useful Functions That Will Help You Understand This Tutorial Better
SetTimer
Switch
Loops

Ok Now Lets Begin With The Coding Part Of it:

first we start with the basic defines And New Variables:
Defines

pawn Code:
#define COLOR_LIGHTBLUE 0x33CCFFAA
#define RWTime 60000*3
[COLOR="rgb(154, 205, 50)"]
New Variables
[/COLOR]
pawn Code:
new Weather;
The"#define COLOR_LIGHTBLUE 0x33CCFFAA" will Define a Color In a Hex Code So you Wont Get Some Errors

The "#define RWTime 60000*3" Defines The Timer Time Setting For Easier Access Later On ie,it defines the time a timer will take to call a random weather

Ok Once We Have Done That We Will Have To Set Up a Timer
for Those Of You Who don't Know
pawn Code:
native SetTimer(funcname[],interval,repeating);
More Info About the timers Is Given in the Some Useful Functions List

ok Moving On
now We will code a Public Function For The Timer
Before That We Need To Forward It so Add This Anywhere in your Code Above your Timers Public
pawn Code:
forward RandomWeather();
Now You Can Add A Public To The timer Without Any Errors
pawn Code:
public RandomWeather()
{
   
            Weather = random(20);
            SetWeather(Weather);
            switch(Weather)
            {
            case 0:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Sunny Skies |[Visibility]:High |[Winds]:NA |[Clouds]:Moderate");
            case 1:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Moderate Sunny Skies [Visibility]:High [Winds]:NA [Clouds]:Moderate");
            case 2:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Sunny Skies [Visibility]:High [Winds]:NA [Clouds]:Moderate");
            case 3:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Sunny Skies [Visibility]:High [Winds]:NA [Clouds]:Moderate");
            case 4:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Sunny Skies |[Visibility]:High |[Winds]:NA |[Clouds]:Moderate");
            case 5:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Sunny Skies |[Visibility]:High |[Winds]:NA |[Clouds]:Moderate");
            case 7:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Sunny Skies |[Visibility]:High |[Winds]:NA |[Clouds]:Moderate");
            case 8:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Wet Rainy Weather |[Visibility]:Medium |[Winds]:Moderate |[Clouds]:Heavy");
            case 9:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Thick Fog |[Visibility]:Low |[Winds]:Moderate |[Clouds]:Heavy");
            case 10:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Moderate Sunny Skies |[Visibility]:High |[Winds]:NA |[Clouds]:Moderate");
            case 11:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: HeatWave |[Visibility]:High |[Winds]:NA |[Clouds]:Moderate");
            case 12:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Hazy/Dull Weather |[Visibility]:Moderate |[Winds]:NA |[Clouds]:High");
            case 13:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Hazy/Dull Weather |[Visibility]:Moderate |[Winds]:NA |[Clouds]:High");
            case 14:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Hazy/Dull Weather |[Visibility]:Moderate |[Winds]:NA |[Clouds]:High");
            case 15:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Heavy RainStorm |[Visibility]:Low |[Winds]:Very High |[Clouds]: very Thick");
            case 16:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Scorching Hot Bright Weather |[Visibility]:High |[Winds]:NA |[Clouds]:Low");
            case 17:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Scorching Hot Bright Weather |[Visibility]:High |[Winds]:NA |[Clouds]:Low");
            case 18:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Scorching Hot Bright Weather |[Visibility]:High |[Winds]:NA |[Clouds]:Low");
            case 19:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Sand Storm |[Visibility]:Very-Low |[Winds]: High Speed Winds |[Clouds]:Heavy");
            case 20:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Toxic Green Smog |[Visibility]:Low |[Winds]:Moderate |[Clouds]:Heavy");

       
    }
}
ok Thats Quite a Big Piece of Code To Digest So ive broken it in Smaller segments
pawn Code:
Weather = random(20);
SetPlayerWeather(i,Weather);
The Random function Selects a Random Weather id And The Next bit Sets The Weather

pawn Code:
switch(Weather)
            {
            case 0:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Sunny Skies |[Visibility]:High |[Winds]:NA |[Clouds]:Moderate");
            case 1:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Moderate Sunny Skies [Visibility]:High [Winds]:NA [Clouds]:Moderate");
            case 2:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Sunny Skies [Visibility]:High [Winds]:NA [Clouds]:Moderate");
            case 3:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Sunny Skies [Visibility]:High [Winds]:NA [Clouds]:Moderate");
            case 4:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Sunny Skies |[Visibility]:High |[Winds]:NA |[Clouds]:Moderate");
            case 5:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Sunny Skies |[Visibility]:High |[Winds]:NA |[Clouds]:Moderate");
            case 7:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Sunny Skies |[Visibility]:High |[Winds]:NA |[Clouds]:Moderate");
            case 8:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Wet Rainy Weather |[Visibility]:Medium |[Winds]:Moderate |[Clouds]:Heavy");
            case 9:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Thick Fog |[Visibility]:Low |[Winds]:Moderate |[Clouds]:Heavy");
            case 10:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Moderate Sunny Skies |[Visibility]:High |[Winds]:NA |[Clouds]:Moderate");
            case 11:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: HeatWave |[Visibility]:High |[Winds]:NA |[Clouds]:Moderate");
            case 12:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Hazy/Dull Weather |[Visibility]:Moderate |[Winds]:NA |[Clouds]:High");
            case 13:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Hazy/Dull Weather |[Visibility]:Moderate |[Winds]:NA |[Clouds]:High");
            case 14:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Hazy/Dull Weather |[Visibility]:Moderate |[Winds]:NA |[Clouds]:High");
            case 15:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Heavy RainStorm |[Visibility]:Low |[Winds]:Very High |[Clouds]: very Thick");
            case 16:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Scorching Hot Bright Weather |[Visibility]:High |[Winds]:NA |[Clouds]:Low");
            case 17:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Scorching Hot Bright Weather |[Visibility]:High |[Winds]:NA |[Clouds]:Low");
            case 18:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Scorching Hot Bright Weather |[Visibility]:High |[Winds]:NA |[Clouds]:Low");
            case 19:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Sand Storm |[Visibility]:Very-Low |[Winds]: High Speed Winds |[Clouds]:Heavy");
            case 20:SendClientMessageToAll(COLOR_LIGHTBLUE,"METAR INFO: [Current Weather]: Toxic Green Smog |[Visibility]:Low |[Winds]:Moderate |[Clouds]:Heavy");
The Switch Control Structure And The Case 1: etc Replace normal if, elseif which makes it easier to type And also Makes Your code Faster I think
The Lines Of code Below It Are the Weather Messages for each weather id You Can Change it if you like To Make it display your own messages

or Else
Here is the code without any messages
pawn Code:
forward RandomWeather();
public RandomWeather()
{
   
            Weather = random(20);
            SetPlayerWeather(i,Weather);
Reply
#2

Heuumm seems nice... Nice tutorial
Reply
#3

Quote:
Originally Posted by Naruto_Emilio
View Post
Heuumm seems nice... Nice tutorial
Thanks
Reply
#4

Wohoo, looks nice, Great Tutorial, Dude..
Reply
#5

This looks like something which has been stripped. You haven't even explained anything in detail.
Reply
#6

Quote:
Originally Posted by Kush
View Post
This looks like something which has been stripped. You haven't even explained anything in detail.
ok i wont take your critical comment too bad ill try to improve on this tut
Reply
#7

pawn Code:
new Weather;
Weather = random( 20 );
SetWeather( Weather );
switch ( Weather )
{
    case 0 : SendClientMessageToAll( );
    // ...
}
No idea why you are using a loop ....
Reply
#8

Quote:
Originally Posted by Basicz
View Post
pawn Code:
new Weather;
Weather = random( 20 );
SetWeather( Weather );
switch ( Weather )
{
    case 0 : SendClientMessageToAll( );
    // ...
}
No idea why you are using a loop ....
my bad lol i forgot about that at first i wanted to create a random weather sperately for all the other cities but it kinda failed but i forgot to remove that bit :/
Reply
#9

Nice!!
Reply
#10

Nice tutorial if i make a TDM/DM GameMode il will use this tutorial to make some special on the server !
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)