- Joined
- Jan 1, 2011
- Messages
- 1,528
A little something I thought other people might be able to use
JASS:
/*
This system allows you to edit day and night values ingame with ease using
function SetDayNight
But it requires that you have not edited any of the day and night values in gameplay constants
function SetDayNight takes real WholeDay, real PcntDay, real PcntNight, real TIME, real UpdateTime returns nothing
real WholeDay is how many seconds there are in a whole cycle of day and night (default is 480 seconds)
real PcntDay is how much of those WholeDay seconds will be day (default is 50%, which is 240 seconds)
real PcntDay is how much of those WholeDay seconds will be night (default is 50%, which is 240 seconds)
real TIME is what you want this update to start on. This value can be 0.00 to 24.00
real UpdateTime is how often the timer fires the Cycle function (lower values allow smoother day/night transitions)
Example: (Default game time) call SetDayNight (480, 0.50, 0.50, 6.00, 0.1)
You may use the boolean IsDay to detect if it is day or night
When real DNEvent becomes 1.00 it has just turned day, when it becomes 2.00 it has just turned night
*/
library DayNight //By maddeem
globals
private real DayL
private real DayTick
private real NightTick
private real time
private timer t = CreateTimer()
public real DNEvent
public boolean IsDay
endglobals
private function Cycle takes nothing returns nothing
if time >= 6 and time < 18 then
set time = time + DayTick
if not IsDay then
set IsDay = true
set DNEvent = 1
set DNEvent = 0
endif
else
if time >= 24 then
set time = time - 24
endif
set time = time + NightTick
if IsDay then
set IsDay = false
set DNEvent = 2
set DNEvent = 0
endif
endif
call SetFloatGameState(GAME_STATE_TIME_OF_DAY, time)
endfunction
function SetDayNight takes real WholeDay, real PcntDay, real PcntNight, real TIME, real UpdateTime returns nothing
local real Tick = 24 / WholeDay * UpdateTime
call PauseTimer(t)
call SuspendTimeOfDay(true)
call TimerStart(t, UpdateTime, true, function Cycle)
set DayTick = Tick / PcntDay
set NightTick = Tick / PcntNight
set time = TIME
if time >= 6 and time < 18 then
set IsDay = true
else
set IsDay = false
endif
call SetFloatGameState(GAME_STATE_TIME_OF_DAY, time)
endfunction
endlibrary
Last edited: