wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Resources > Code Resources > Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 09-12-2008, 03:12 AM   #1
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,279

Submissions (17)

moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Idea Random weather script

Random weather script
By moyack. 2008.

I did this as a request: a code that changes randomly the weather from normal to a rainy day. Due to its configurability and easy to use (just copy it to your map and it will work) I'll post it to the public. Now the current version allows multiple types of weathers and with a few functions you can achieve very nice weather effect transitions.


How the script works?

The script initializes a timer with a random duration (configurable via globals), and it will change from no weather to a weather environment. if you use the minimalistic version, it will turn on and off in a random way the specified weather. If you use the Standard version, it will do the same but with a set of weathers configured previously. this preconfiguration can be done at map init or at game time... there's no limitation.


Credits and Acknowledgments

Greetings to Syntic_Arrow for doing the request.
Credits to Ammorth for the suggestion of weights to implement randomness
Gives credits when you use it...


How to install:
  1. Create a new trigger
  2. Call it whatever you want
  3. Convert it to custom text
  4. Delete all the content of that trigger
  5. Paste this trigger code and voila!!!

Standard version:
The standard version offers the possibility to setup the kind of weathers you want to see in your map and their chances to appear. To start a set of weathers, you just have to add a code like this:

Collapse Sample code:
function StartWeather takes nothing returns nothing // This function can run at map init...
    call CleanWeatherWeights() // Prepares and clean the Weather script...
    call SetWeatherWeight(Northrend_Blizzard, 3.) // adds a weather type and its weight.
    call SetWeatherWeight(Rays_Of_Light, 5.)
    call SetWeatherWeight(Wind_Heavy, 8.)
    // if a weather has a higher weight, it will have more chances to happen than others.
    // this value is arbitrary...
endfunction

If you need to change the weather weights, or types, you must clean them with CleanWeatherWeights() and then reset the values with SetWeatherWeight(...) command.

Collapse Random Weather Script - Standard version:
// Random weather changer, by moyack. 2008.
library RandomWeather initializer init
// Configuration section
globals
    private constant real    MinDur = 5. // minimum time that we have to wait between weathers
    private constant real    MaxDur = 15. // maximum time that we have to wait between weathers
endglobals
// End configuration section
globals
    // Weather Type Constants
    constant integer Ashenvale_Rain_Heavy    = 'RAhr'
    constant integer Ashenvale_Rain_Light    = 'RAlr'
    constant integer Dalaran_Shield          = 'MEds'
    constant integer Dungeon_Blue_Fog_Heavy  = 'FDbh'
    constant integer Dungeon_Blue_Fog_Light  = 'FDbl'
    constant integer Dungeon_Green_Fog_Heavy = 'FDgh'
    constant integer Dungeon_Green_Fog_Light = 'FDgl'
    constant integer Dungeon_Red_Fog_Heavy   = 'FDrh'
    constant integer Dungeon_Red_Fog_Light   = 'FDrl'
    constant integer Dungeon_White_Fog_Heavy = 'FDwh'
    constant integer Dungeon_White_Fog_Light = 'FDwl'
    constant integer Lordaeron_Rain_Heavy    = 'RLhr'
    constant integer Lordaeron_Rain_Light    = 'RLlr'
    constant integer Northrend_Blizzard      = 'SNbs'
    constant integer Northrend_Snow_Heavy    = 'SNhs'
    constant integer Northrend_Snow_Light    = 'SNls'
    constant integer Outland_Wind_Heavy      = 'WOcw'
    constant integer Outland_Wind_Light      = 'WOlw'
    constant integer Rays_Of_Light           = 'LRaa'
    constant integer Rays_Of_Moonlight       = 'LRma'
    constant integer Wind_Heavy              = 'WNcw'
    // End Weather type Constants...
    private boolean IsWeather = false
endglobals

private struct Weather // this is the struct that manages all the weather behavior
    private static rect R
    private static real total = 0.
    private static integer index = 0
    weathereffect w
    integer id
    real weight
    real chance
    
    private method onDestroy takes nothing returns nothing
        call RemoveWeatherEffect(.w)
    endmethod
    
    static method Clean takes nothing returns nothing
        local integer i = 1
        local Weather W
        loop
            exitwhen i > Weather.index
            set W = Weather(i)
            call W.destroy()
            set i = i+1
        endloop
        set Weather.index = 0
    endmethod
    
    static method Add takes integer id, real w returns nothing
        local integer i = 1
        local Weather W = Weather.allocate()
        set W.id = id
        set W.weight = w
        set W.w = AddWeatherEffect(Weather.R, id)
        call EnableWeatherEffect(W.w, false)
        set Weather.total = Weather.total + w
        set Weather.index = integer(W)
        loop
            exitwhen i > Weather.index
            set W = Weather(i)
            set W.chance = W.weight / Weather.total
            set i = i+1
        endloop
    endmethod
    
    static method Start takes nothing returns nothing
        local integer i = 1
        local real r = GetRandomReal(0,1)
        local real s = 0.
        local Weather W
        loop
            exitwhen i > Weather.index
            set W = Weather(i)
            exitwhen s <= r and r < s+W.chance
            set s = s+W.chance
            set i = i+1
        endloop
        call EnableWeatherEffect(W.w, true)
    endmethod
    
    static method Stop takes nothing returns nothing
        local integer i = 1
        local Weather W
        loop
            exitwhen i > Weather.index
            set W = Weather(i)
            call EnableWeatherEffect(W.w, false)
            set i = i+1
        endloop
    endmethod
    
    private static method onInit takes nothing returns nothing
        set Weather.R = GetWorldBounds()
    endmethod
endstruct

private function Loop takes nothing returns nothing
    local timer t = GetExpiredTimer()
    set IsWeather = not IsWeather
    if IsWeather then
        call Weather.Start()
    else
        call Weather.Stop()
    endif
    call PauseTimer(t)
    call TimerStart(t, GetRandomReal(MinDur, MaxDur), false, function Loop)
    set t = null
endfunction

private function init takes nothing returns nothing
    call TimerStart(CreateTimer(), GetRandomReal(MinDur, MaxDur), false, function Loop)
endfunction
// ==============
// user functions
// ==============
function SetWeatherWeight takes integer wid, real w returns nothing
    call Weather.Add(wid, w)
endfunction

function CleanWeatherWeights takes nothing returns nothing
    call Weather.Clean()
endfunction

endlibrary

Expand Minimalistic version. Only manages one type of weather:

Expand Weather RawCodes:
Attached Images
File Type: gif weather.gif (22.8 KB, 146 views)

Last edited by moyack : 09-18-2008 at 02:45 AM.
moyack is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 09-12-2008, 05:29 AM   #2
burningice95
User
 
burningice95's Avatar
 
Join Date: Jun 2007
Posts: 218

burningice95 has little to show at this moment (3)

Send a message via AIM to burningice95 Send a message via MSN to burningice95 Send a message via Yahoo to burningice95
Default

Seems a little simple.....
__________________
Burningice255: What more does GUI need anyway?
redscores1: How about a syntax checker?
burningice95 is offline   Reply With Quote
Old 09-12-2008, 05:30 AM   #3
darkwulfv
Alpha Male of Wc3c
 
darkwulfv's Avatar


Official Map Reviewer
 
Join Date: Mar 2006
Posts: 3,646

Submissions (6)

darkwulfv is just really nice (270)darkwulfv is just really nice (270)

Send a message via AIM to darkwulfv
Default

One thing: I would put where you can find the rawcode of weather (because I sure don't know).

EDIT: That's why this is a script, not a system.
__________________
The Spell Request Thread
Quote:
Originally Posted by Joe-Black-5
a dota like map but with unique stuff
(There was no map attached, and that was all the thread said.)
Spells I've Made

Darkwulfv's Lightning Grapple || Tritanis' Lazy Bolt


Last edited by darkwulfv : 09-12-2008 at 05:31 AM.
darkwulfv is offline   Reply With Quote
Old 09-13-2008, 02:18 AM   #4
Anopob
Yay!
 
Anopob's Avatar
 
Join Date: May 2006
Posts: 870

Anopob has a spectacular aura about (120)

Default

What darkwulfv said, as adjusting this to snow or fog or whatever (or multiple weathers at random times if so) would be great.
__________________
Give +REP to people who help you with things or make good resources.
Better Ways of Requesting For Help - Race Contest #2 WIP Thread (Bone Race)
As of December 1st I have my blue rep. Yay :D
Anopob is offline   Reply With Quote
Old 09-13-2008, 06:51 AM   #5
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

"Random Rain" is a bit misleading since it could work for any kind of weather.

I say add support for all types of weather, enabling/disabling specific weather types, and setting the relative frequency of each.
grim001 is offline   Reply With Quote
Old 09-14-2008, 03:47 PM   #6
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,279

Submissions (17)

moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Default

Ok, I'll add a function which will set the chances that a weather could happen.

call SetWeatherChance('RAhr', 0.15) // it will have a 15% chance that a rain happens...
moyack is offline   Reply With Quote
Old 09-14-2008, 08:08 PM   #7
Ammorth
I blink, therefore I am.
 
Ammorth's Avatar
 
Join Date: Sep 2006
Posts: 1,812

Submissions (10)

Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)

Default

I would instead use a weight, as calling:

Collapse JASS:
call SetWeatherChance('RAIN', 1.00)
call SetWeatherChance('SNOW', 1.00)

wouldn't work out very well.

Collapse JASS:
call SetWeatherChance('RAIN', 8)
call SetWeatherChance('SNOW', 3)

rain = 8/(8+3) = 72.7%
snow = 3/(8+3) = 27.3%
__________________
Ammorth is offline   Reply With Quote
Old 09-15-2008, 01:00 AM   #8
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,279

Submissions (17)

moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Default

Quote:
Originally Posted by Ammorth
I would instead use a weight, as calling:

Collapse JASS:
call SetWeatherChance('RAIN', 1.00)
call SetWeatherChance('SNOW', 1.00)

wouldn't work out very well.

Collapse JASS:
call SetWeatherChance('RAIN', 8)
call SetWeatherChance('SNOW', 3)

rain = 8/(8+3) = 72.7%
snow = 3/(8+3) = 27.3%
I was thinking to make a code that behaves similar to... the system that the AI editor has to select the hero's chances of being trained. If you set one value, the other values get adjusted, so in the first scenario you proposed, simply the system will impose the snow and will set 0% chances to the other weathers.

I've added the weathers (20 in total) and I'm coding the calculation part. As soon as I have them ready, I'll post the updated version.
moyack is offline   Reply With Quote
Old 09-16-2008, 08:05 AM   #9
ADOLF
User from USSR
 
Join Date: Jan 2007
Posts: 127

Submissions (3)

ADOLF will become famous soon enough (36)ADOLF will become famous soon enough (36)

Send a message via ICQ to ADOLF
Default

change of weather with all map (if it big) can cause a lag, i shared a map on regions and create weathereffect timed in each region
__________________
ADOLF is offline   Reply With Quote
Old 09-18-2008, 02:42 AM   #10
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,279

Submissions (17)

moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Default

Code updated. Comments are appreciated.
moyack is offline   Reply With Quote
Old 09-18-2008, 02:54 AM   #11
Ammorth
I blink, therefore I am.
 
Ammorth's Avatar
 
Join Date: Sep 2006
Posts: 1,812

Submissions (10)

Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)

Default

There is one issue with this script which is not adressed in the setup. The issue is not with the script itself but with the game engine.

Read the bottem of this post for the info: http://www.wc3campaigns.net/showthread.php?t=91176

Quote:
Originally Posted by Ammorth
The one effect rule
There are different types of weather effects: Rain, Shield, Dungeon Fog, Snow, Rays and Wind. Each type of effect can only have one instance of itself per 512 square. This includes disabled weather effects. This means you cannot create Lordaeron Rain and Ashenvale Rain on the same square. The first one created will be viewable, while the other will be non-existent.
__________________

Last edited by Ammorth : 09-18-2008 at 02:54 AM.
Ammorth is offline   Reply With Quote
Old 09-18-2008, 03:44 AM   #12
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,279

Submissions (17)

moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Default

Quote:
Originally Posted by Ammorth
There is one issue with this script which is not adressed in the setup. The issue is not with the script itself but with the game engine.

Read the bottem of this post for the info: http://www.wc3campaigns.net/showthread.php?t=91176
Actually (and without noticing) the script takes this situation into account :P, because it lets one period with any of the effects and other period will all the effects off. There's no chance that 2 or more effects gets turned on at the same time (at least with my test).

Last edited by moyack : 09-18-2008 at 03:44 AM.
moyack is offline   Reply With Quote
Old 09-18-2008, 04:44 AM   #13
Ammorth
I blink, therefore I am.
 
Ammorth's Avatar
 
Join Date: Sep 2006
Posts: 1,812

Submissions (10)

Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)

Default

Its not an issue with effects being displayed, it that you can't create 2 effects of the same "style" on the same grid piece. The only way around this is to remove and then create the new style. The problem with this is that it re-introduces lag caused by weather creation.
__________________
Ammorth is offline   Reply With Quote
Old 09-18-2008, 08:36 AM   #14
DioD
obey
 
DioD's Avatar
 
Join Date: Feb 2006
Posts: 1,532

Submissions (4)

DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)

Send a message via ICQ to DioD
Default

Link some game affect to weather type (i prefer linked list of linked struct, soo you will able to set more then one effect per weather).

Add preload functions, weather lag a lot on first call.

Also add some way to call weather locally (turn on\off for single player).
DioD is offline   Reply With Quote
Old 09-18-2008, 09:56 PM   #15
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

Yes, turn the thing into a non-minimalist monster.

I think linking to effect is interesting but it raises the scope of the initial idea too much, perhaps for a new system, I actually made that one day for TTOR and reused it in my arena, so I might end up releasing a weather system one day.

Either way, I don't like this idea too much, but as an utility for those guys that want to have random weather in their map, I guess it is fine, approved.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 08:43 PM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services