- Joined
- Jul 18, 2010
- Messages
- 2,377
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.
Ingame Log showed this
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.
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
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