LUA function: get_time_of_day
Here is function I made so I could add a clock mod. It would be nice to have this added upstream.
clock mod link in case anyone wants to check it out.
clock mod link in case anyone wants to check it out.
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
const char EnvRef::className[] = "EnvRef";
const luaL_reg EnvRef::methods[] = {
method(EnvRef, add_node),
method(EnvRef, remove_node),
method(EnvRef, get_node),
method(EnvRef, get_node_or_nil),
method(EnvRef, get_node_light),
method(EnvRef, get_time_of_day), <--- Add this
method(EnvRef, add_entity),
method(EnvRef, add_item),
method(EnvRef, add_rat),
method(EnvRef, add_firefly),
method(EnvRef, get_meta),
method(EnvRef, get_player_by_name),
method(EnvRef, get_objects_inside_radius),
{0,0}
};
// EnvRef:get_time_of_day()
static int l_get_time_of_day(lua_State *L)
{
EnvRef *o = checkobject(L, 1);
ServerEnvironment *env = o->m_env;
if(env == NULL) return 0;
// Do it
u32 time_of_day = env->getTimeOfDay();
time_of_day %= 24000;
lua_pushinteger(L, time_of_day);
return 1;
}