• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua How to detect it is night?

filipus

Member
Joined
Dec 31, 2010
Messages
229
Reaction score
12
So, is there any way?
How does the server calculate the day and night cicle?

I'm currently using tibian time correctly (using the tíbia watch script haha) but I can't find a way to determine if its night or not. My problem is that the moment that the night activates seems to change acording to the moment you turn your server on o_O


@Solved

Just use getWorldLight(). If you are using 0.3.6 you need to edit the sources (go to the function and instead of returning 1, return 2) because you get the wrong value from the function.
 
Last edited:
Check the time, and just if time > 18:00 then ... does not work? I don't know really. :p
 
Check the time, and just if time > 18:00 then ... does not work? I don't know really. :p
That would work IF
2urngpt.png

this didn't happen.
I don't get it, nighttime seems to be random or according to when the server started up. Shouldn't time be the same thing?

@Ninja @Limos
 
Code:
local varh = (os.date('%M') * 60 + os.date('%S')) / 150
local tibH = math.floor(varh)

I just checked, it seems correct (all other watch scripts are like that).

@Edit

I was testing right now and what is seems to happen is that the day/night cycle resets but the time keeps going.
So I shutdown the server, it was 13:00 and opened again it was 13:05 (time to login get a watch and click it).
Should the time also reset? How can I do that?
 
Last edited:
os.date() and os.time() are Lua functions, and they check the operating system clock for their values.

If the server implements a different day/night cycle, you need a way to test what OT believes is the time.

I found these global OT functions:

getTibianTime()
getWorldTime()
getWorldUpTime()
getWorldLight()

I suggest you print those and os.date, os.time, convert to consistent formatting, and then tell us what's going on :)
 
Code:
static const int32_t LIGHT_LEVEL_DAY = 250;
        static const int32_t LIGHT_LEVEL_NIGHT = 40;
        static const int32_t SUNSET = 1305;
        static const int32_t SUNRISE = 430;
those are in source.you need a expert to explain them i cant really understand what they mean
 
Use something like this:
Code:
if getTibianTime() == xxx then
xyz
else
xyz
end
 
os.date() and os.time() are Lua functions, and they check the operating system clock for their values.

If the server implements a different day/night cycle, you need a way to test what OT believes is the time.

I found these global OT functions:

getTibianTime()
getWorldTime()
getWorldUpTime()
getWorldLight()

I suggest you print those and os.date, os.time, convert to consistent formatting, and then tell us what's going on :)

You are a genius, that really helped me.
Could you tell me where did you find those functions? I searched in compact but didn't found anything.

Thanks everyone :)
 
luascript.cpp in the source you will find all function you need
--Edit
you can use this function to get the light
getWorldLight() -- the world main light
getPlayerLight(cid) -- the player light atm (EX:if you are using a lightwand it will change the light)
-- Another Edit
Code:
//(1440 minutes/day) * 10 seconds event interval / (3600 seconds/day)
   lightHourDelta = 1440 * 10 / 3600;
   lightHour = SUNRISE + (SUNSET - SUNRISE) / 2;
   lightLevel = LIGHT_LEVEL_DAY;
   lightState = LIGHT_STATE_DAY;
this will tell you everything
 
Last edited:
luascript.cpp in the source you will find all function you need
--Edit
you can use this function to get the light
getWorldLight() -- the world main light
getPlayerLight(cid) -- the player light atm (EX:if you are using a lightwand it will change the light)
-- Another Edit
Code:
//(1440 minutes/day) * 10 seconds event interval / (3600 seconds/day)
   lightHourDelta = 1440 * 10 / 3600;
   lightHour = SUNRISE + (SUNSET - SUNRISE) / 2;
   lightLevel = LIGHT_LEVEL_DAY;
   lightState = LIGHT_STATE_DAY;
this will tell you everything


Yea, I already solved the issue with getWorldLight()
Thanks for helping anyway :D
 
Back
Top