This is improved version of kaeza's code (Licence: WTFPL) which you can find here.
Countdowns shows real time MM:SS to sunrise/sunset.
Licence: WTFPL
Dependences: none
DOWNLOAD
I'm not planning to develop this mod, this is final version.
Krock wrote:And why is this useful?
Hybrid Dog wrote:it's useful because if you set the time and time speed to real time you can play minetest with fullscreen and still be able to view the clock
EDIT: Where's the download?
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";
position = {x=0.5, y=0.01};
text = get_time();
number = 0xFFFF00;
scale = 20;
});
if (player_hud[name]) then
p:hud_remove(player_hud[name]);
end
player_hud[name] = h;
end
end
end);
if (player_hud[name]) then
p:hud_remove(player_hud[name]);
end
player_hud[name] = h;
Kilarin wrote:Is adding a new element and removing the old element more efficient then using hud_change to just change the text element of the previously added item?
kaeza wrote:Kilarin wrote:Is adding a new element and removing the old element more efficient then using hud_change to just change the text element of the previously added item?
There was a bug in the early stages of the Lua HUD (when the original mod was made) whereby calling hud_change() was completely ignored by the client, so this was a quick workaround.
I believe the bug is already fixed, so probably using hud_change() is better.
Edit:
About the globalstep:
The globalstep runs only once per server step (normally every 0.05 seconds, 50 milliseconds), which may be more or less depending on whether the server got busy with other tasks, or needs to "catch up" because of that, respectively. This is regardless of how many clients are connected. The `timer' variable is incremented by `dtime' seconds (which is the time since the previous call to the function was made, i.e. the time since the last server step). Now, the conditional ensures that the HUD only gets updated once at least a second has elapsed.
The loop iterates through the connected players exactly how you described it.
All in all the mod is quite simple and straightforward. If you need more explanations about this, don't hesitate to ask :)
local h = p:hud_add({
hud_elem_type = "text";
position = {x=0.5, y=0.01};
text = get_time();
number = 0xFFFF00;
scale = 20;
});
local h = p:hud_add({
hud_elem_type = "text";
position = {x=0.75, y=0.99};
text = get_time();
number = 0xFFFF00;
scale = 20;
});
local player_hud = {}
local timer = 0
local function floormod(x, y)
return math.floor(x) % y
end
local function get_time()
local time = minetest.get_timeofday()
--local secs = (60*60*24*time)
--local s = floormod(secs, 60)
local tmp = 24*time
local m = floormod(60*tmp, 60)
local h = floormod(tmp, 60)
--local time_to_sunrise
--if (time >= (0.198)) then
-- time_to_sunrise = 1200*(1.198 - time)
--else
-- time_to_sunrise = 1200*(0.198 - time)
--end
-- time to next sunrise in real-time seconds, 0.198 is time of sunrise in 0..1 range, 72" is world time speed const;
--local a = floormod(time_to_sunrise, 60)
--local b = floormod(time_to_sunrise/60, 60)
--local c = floormod(time_to_sunrise/3600, 60)
--return ("Time: %02d:%02d:%02d Next sunrise in: %02d:%02d:%02d"):format(h, m, s, c, b, a) --return ("%02d:%02d:%02d"):format(h, m, s);
return ("%02d:%02d"):format(h, m) --return ("%02d:%02d:%02d"):format(h, m, s);
end
minetest.register_globalstep(function(dtime)
timer = timer + dtime
if timer >= 1 then
timer = 0
for _,p in pairs(minetest.get_connected_players()) do
local name = p:get_player_name()
local h = p:hud_add({
hud_elem_type = "text";
position = {x=0.35, y=0.900}; --position = {x=0.35, y=0.900};
text = get_time();
number = 0xFFFF00; --colour
})
if player_hud[name] then
p:hud_remove(player_hud[name])
end
player_hud[name] = h
end
end
end)
Krock wrote:And why is this useful?
cHyper wrote:waypoints do not work with the mod unified inventory.
the overlay-informations of waypoints disappears on the screen.
is this a feature of the hud or what else?
try the modmenu mod instead of inventory plus
cHyper wrote:try the modmenu mod instead of inventory plus
who made this mod?
is this a GUI for minetest?
Hybrid Dog wrote:cHyper wrote:try the modmenu mod instead of inventory plus
who made this mod?
is this a GUI for minetest?
You can use the unified inventory mod
viewtopic.php?id=3933
or the inventory plus mod
viewtopic.php?id=3100
. Both change the inventory, so inventory_plus doesn't work if unified inventory is used.
inventory plus changes the inventory that people can add their own stuff to it with mods
unified inventory changes the inventory by adding some buttons... but mods can't modify it, I think
modmenu
viewtopic.php?id=5824
shows the stuff of inventory plus with /m, so unified inventory can be used
RealBadAngel wrote:
Mods can easily add own buttons and tabs to UI,
Like this one: https://forum.minetest.net/viewtopic.php?t=8816
Users browsing this forum: No registered users and 36 guests