Skip to content

Instantly share code, notes, and snippets.

@davisonio
Last active March 9, 2022 00:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davisonio/cd7158b25d543ad13f9d to your computer and use it in GitHub Desktop.
Save davisonio/cd7158b25d543ad13f9d to your computer and use it in GitHub Desktop.
Timer mod for minetest
local player_hud = {}
local timer = 0
local function floormod (x, y)
return (math.floor(x)%y)
end
local function get_time()
local secs = (60*60*24*minetest.env:get_timeofday())
local mins = floormod(secs/60, 60)
local hour = floormod(secs/3600, 60)
return ("%02d:%02d"):format(hour, mins)
end
minetest.register_globalstep(function (dtime)
timer = timer + dtime
if (timer >= 1.0) then
timer = 0
for _,p in ipairs(minetest.get_connected_players()) do
local name = p:get_player_name()
local h = p:hud_add({
hud_elem_type = "text",
name = "time",
position = {x=0.95,y=0.05},
scale = {x=100,y=100},
text = "In-Game Time: "..get_time(),
alignment = {x=0,y=0},
number = 0xFFFFFF,
})
if (player_hud[name]) then
p:hud_remove(player_hud[name]);
end
player_hud[name] = h;
end
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment