Page 1 of 1
Weather system scripting help
Posted: Mon Nov 03, 2014 2:05 am
by TSotP
Hi, i mentioned this morning in the Editor Tutorials on YouTube thread that i was thinking about making a script for a weather system
(
viewtopic.php?f=22&t=7055&start=60#p81445)
well, i ended up creating 2 scripts in order to try and get it to work. The first script uses a timer to start the script, which then is supposed to add 1 to a counter. This counter will be referenced in my other script. I then have a second script, which is started by the same timer, that checked which 'day' it is and changes the sky_box at a specified time.
the problem i am having is that it doesn't work and i have so little experiance with scripts that i have no idea why.
any ideas what i have done wrong?
Script 1 (day counter)
Code: Select all
function DayCount()
if GameMode.getTimeOfDay() == 1.99 then
day_counter.counter:incriment()
else
end
if day_counter.counter:getValue() == 7 then
day_counter.counter:setValue(0)
else
end
end
Script 2 (weather changer)
Code: Select all
function WeatherCycle()
if day_counter.counter:getValue() == 2 and
GameMode.getTimeOfDay() == 0.7 then
weather_forest_day_sky:destroy()
spawn("cemetery_sky",self.go.level,0,0,0,0,"weather_cemetery_sky")
end
if day_counter.counter:getValue() == 4 and
GameMode.getTimeOfDay() == 0.5 then
weather_cemetery_sky:destroy()
spawn("castle_arena_sky",self.go.level,0,0,0,0,"weather_castle_arena_sky")
end
if day_counter.counter:getValue() == 5 and
GameMode.getTimeOfDay() == 1.6 then
weather_castle_arena_sky:destroy()
spawn("cemetery_sky",self.go.level,0,0,0,0,"weather_cemetery_sky")
end
if day_counter.counter:getValue() == 6 and
GameMode.getTimeOfDay() == 0.3 then
weather_cemetery_sky:destroy()
spawn("forest_day_sky",self.go.level,0,0,0,0,"weather_forest_day_sky")
end
end
Re: Weather system scripting help
Posted: Mon Nov 03, 2014 2:25 am
by Blichew
I didn't do anything with weather yet (hell, I didn't do anything with outdoor areas yet

) but I think the problem is that you're always checking if GameMode.getTimeOfDay() ==
something. Did you try if timeOfDay actually become this
exact numbers ? Maybe one "tick" just jumps over, let's say value 0.3 which you're checking for ? Maybe try replacing those ifs with something like that:
Day counter:
Code: Select all
function DayCount()
if GameMode.getTimeOfDay() > 1.99 then
day_counter.counter:incriment()
GameMode.setTimeOfDay(0) -- to prevent from increasing the counter another time for let's say 1.991 and so on
else
end
if day_counter.counter:getValue() == 7 then
day_counter.counter:setValue(0)
else
end
end
Same with weather one. That will be harder I think because you'll have to keep statuses for each sky otherwise it'll try to re-spawn the sky every time (if you just change == to >).
Generally time of day gets it's value incremented by 0.0007456421 or something like that

Re: Weather system scripting help
Posted: Mon Nov 03, 2014 2:29 am
by NutJob
You may be better off using a polling system on a timer instead. That way you can use integers and deltas for duration. You can still pull the game time into your polling tick and use that for conditionals.
Re: Weather system scripting help
Posted: Mon Nov 03, 2014 9:13 am
by TSotP
What about if I added in the lines
Code: Select all
if day_counter.counter:getValue() == 2 and
GameMode.getTimeOfDay() > 0.7 and GameMode.getTimeOfDay < 0.70099 then
weather_forest_day_sky:destroy()
spawn("cemetery_sky",self.go.level,0,0,0,0,"weather_cemetery_sky")
GameMode.setTimeOfDay(0.701)
end
Do you think that might stop multiple iterations from happening? Since a single game tick should always land between 0.7 and 0.701
Re: Weather system scripting help
Posted: Mon Nov 03, 2014 9:15 am
by TSotP
NutJob wrote:You may be better off using a polling system on a timer instead. That way you can use integers and deltas for duration. You can still pull the game time into your polling tick and use that for conditionals.
I'd love to be able to do that, but I genuinely have no idea what it means in terms of scripting lol
Re: Weather system scripting help
Posted: Mon Nov 03, 2014 9:22 am
by Drakkan
how is the weather system working with areas, where you need some particular weather ? (for example I´d like the cemetery map, where is always cemetary_sky). Or is the weather replacing this ?
Otherwise I like the weather idea. Also if you want make some randomnes rather then cycling I think it woul be better to define some weathers and than just some fucntion which will randomly pick from it depending on actual time.
I aslo hope somebody will do some rain / snow weather, that could be cool !
Re: Weather system scripting help
Posted: Mon Nov 03, 2014 9:36 am
by TSotP
Drakkan wrote:how is the weather system working with areas, where you need some particular weather ? (for example I´d like the cemetery map, where is always cemetary_sky). Or is the weather replacing this ?
Otherwise I like the weather idea. Also if you want make some randomnes rather then cycling I think it woul be better to define some weathers and than just some fucntion which will randomly pick from it depending on actual time.
I aslo hope somebody will do some rain / snow weather, that could be cool !
Well, currently it's not working lol. But I think the system will only run on the map you place it on. As far as I've seen, you can't have multiple sky boxes on a single map anyway. So you would just place the script and timers on the map you need it for.
Once I manage to get it running I'll look into adding conditions to the individual sky spawns such as late night/early morning fog particles and ambient light turned off. Foggy evenings with no fog particles etc.
And random would be good. But my thinking was "what was the weather like last monday morning?.. I have no idea." lol, hopefully the same will be true of the game lol.
Re: Weather system scripting help
Posted: Thu Nov 06, 2014 2:43 am
by TSotP
ok, i think i got the script to work. or at least it seem to on my machine.
to set this up, you need to add in a counter
"day_counter", a timer
"day_timer" and 2 scripts
"day_script_entity" & "weather_script_entity"
hook the timer up to both scripts with
TriggerOnStart
Day Counter Script
Code: Select all
function DayCount()
if GameMode.getTimeOfDay() > 1.99 then
day_counter.counter:increment()
GameMode.setTimeOfDay(0)
else
end
if day_counter.counter:getValue() == 7 then
day_counter.counter:setValue(0)
else
end
end
Weather Script
Code: Select all
function WeatherCycle()
if day_counter.counter:getValue() == 2 and
GameMode.getTimeOfDay() > 0.700 and
GameMode.getTimeOfDay() < 0.701 then
weather_forest_day_sky:destroy()
spawn("cemetery_sky",self.go.level,0,0,0,0,"weather_cemetery_sky")
GameMode.setTimeOfDay (0.7011)
else
end
if day_counter.counter:getValue() == 4 and
GameMode.getTimeOfDay() > 0.500 and
GameMode.getTimeOfDay() < 0.501 then
weather_cemetery_sky:destroy()
spawn("castle_arena_sky",self.go.level,0,0,0,0,"weather_castle_arena_sky")
GameMode.setTimeOfDay (0.5011)
end
if day_counter.counter:getValue() == 5 and
GameMode.getTimeOfDay() > 1.600 and
GameMode.getTimeOfDay() < 1.601 then
weather_castle_arena_sky:destroy()
spawn("cemetery_sky",self.go.level,0,0,0,0,"weather_cemetery_sky")
GameMode.setTimeOfDay (1.6011)
end
if day_counter.counter:getValue() == 6 and
GameMode.getTimeOfDay() > 0.300 and
GameMode.getTimeOfDay() < 0.301 then
weather_cemetery_sky:destroy()
spawn("forest_day_sky",self.go.level,0,0,0,0,"weather_forest_day_sky")
GameMode.setTimeOfDay (0.3011)
end
end
and the weather should change automatically every few days.
There might be a much more elegant way to do this script, but it works
