• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[System] [Needs fix] Day/Night Manipulator

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:
Please fix the indentation.

I don't really understand what's wrong with the regular ability to change time of day?

That does not change the speed of day. Which you cannot do. (Don't point out the native that changes the speed, it is broken.)

This allows you to basically do anything with the day/night.
So if you want day to be 5 seconds and night to be 5 seconds you can do that. If you want a 24 hour day, you can do that as well.

I will fix the indentation, but that is the way I code :3
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
That does not change the speed of day. Which you cannot do. (Don't point out the native that changes the speed, it is broken.)

This allows you to basically do anything with the day/night.

I did not know that!

You know what you could also do; is many more lightmodel "phases", e.g. a different model for
morning
noon
afternoon
dusk
night
midnight
 
i agree :D

Also,your indention is messed up again :/

Gonna help you :D
[jass=]
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
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
call Cycle()
endfunction
endlibrary[/code]
 
i agree :D

Also,your indention is messed up again :/

Gonna help you :D
[jass=]
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
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
call Cycle()
endfunction
endlibrary[/code]
Updated indentation and fixed a bug.
 
- Add spaces between the function and global blocks.
- You need to follow common JASS convention: http://www.hiveworkshop.com/forums/...80/jpag-jass-proper-application-guide-204383/
- The documentation needs to be more organized. Try doing what Nes does or what I do.
You would include the name, version number and author, then a brief description (1-2 sentences)
Then you would have several blocks that define things like:
- API
- Credits
- Implementation Instructions (If needed)
- Warnings
- Required Resources
etc...
 
Top