22.09.2011, 13:19
(
Last edited by AceFlyer; 22/09/2011 at 01:36 PM.
Reason: Update
)
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
New Variables
[/COLOR]pawn Code:
new Weather;
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);
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();
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");
}
}
pawn Code:
Weather = random(20);
SetPlayerWeather(i,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 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);