• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Lua] GetTimeOfDay broken V1.31.1

Status
Not open for further replies.
I wanted to make a skill in Warcraft 3 V1.31.1 in Lua mode using bj_dncIsDaytime. But for some reason it always said it is night, which confused me as the ingame clock showed 12+.

Therefore I gone searching. Overwrote the bj functions doing this day/nigh stuff, added some prints which displayed the time inside the events.
Lua:
function SetDNCSoundsDay()
    local ToD = GetTimeOfDay()
    print("Custom Day Func", ToD)
    if (ToD >= bj_TOD_DAWN and ToD < bj_TOD_DUSK) and not bj_dncIsDaytime then
    print("set Day")
        bj_dncIsDaytime = true

        -- change ambient sounds
        StopSound(bj_nightAmbientSound, false, true)
        StartSound(bj_dayAmbientSound)
    end
end

function SetDNCSoundsNight()
    local ToD = GetTimeOfDay()
    print("Custom Night Func", ToD)
    if (ToD < bj_TOD_DAWN or ToD >= bj_TOD_DUSK) and bj_dncIsDaytime then
        print("set Night")
        bj_dncIsDaytime = false

        -- change ambient sounds
        StopSound(bj_dayAmbientSound, false, true)
        StartSound(bj_nightAmbientSound)
    end
end

Ingame Log showed this
Time of Day - Day broken .jpg


Which looks like a float precision problem.

To fix it I let GetTimeOfDay go over a proxy which rounds it to hours as I don't need the minute feature.
Lua:
do -- Round GetTimeOfDay to full hours without this it will not be 6 and not 18 when the dawn dusk event happens breaking day/night cycle code
    local old = GetTimeOfDay
    function GetTimeOfDay()
        return math.floor(old() + 0.1)
    end
end
 
Status
Not open for further replies.
Top