Update inventory icon each second
This commit is contained in:
parent
7f9af415bb
commit
c3cd4e8589
28
init.lua
28
init.lua
@ -33,7 +33,7 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
offset = {x=-32,y=-32},
|
offset = {x=-32,y=-32},
|
||||||
text = icon,
|
text = icon,
|
||||||
})
|
})
|
||||||
inventory_icon.hudids[name].icon = player:hud_add({
|
inventory_icon.hudids[name].text = player:hud_add({
|
||||||
hud_elem_type = "text",
|
hud_elem_type = "text",
|
||||||
position = {x=1,y=1},
|
position = {x=1,y=1},
|
||||||
scale = {x=1,y=1},
|
scale = {x=1,y=1},
|
||||||
@ -43,3 +43,29 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
text = string.format("%d/%d", occupied, size)
|
text = string.format("%d/%d", occupied, size)
|
||||||
})
|
})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
minetest.register_on_leaveplayer(function(player)
|
||||||
|
inventory_icon.hudids[player:get_player_name()] = nil
|
||||||
|
end)
|
||||||
|
|
||||||
|
inventory_icon.timer = 0
|
||||||
|
minetest.register_globalstep(function(dtime)
|
||||||
|
inventory_icon.timer = inventory_icon.timer + dtime
|
||||||
|
if inventory_icon.timer > 1 then
|
||||||
|
for playername,hudids in pairs(inventory_icon.hudids) do
|
||||||
|
local player = minetest.get_player_by_name(playername)
|
||||||
|
local occupied, size = inventory_icon.get_inventory_state(player)
|
||||||
|
local icon, color
|
||||||
|
if occupied >= size then
|
||||||
|
icon = "inventory_icon_backpack_full.png"
|
||||||
|
color = "0xFF0000"
|
||||||
|
else
|
||||||
|
icon = "inventory_icon_backpack_free.png"
|
||||||
|
color = "0xFFFFFF"
|
||||||
|
end
|
||||||
|
player:hud_change(hudids.icon, "text", icon)
|
||||||
|
player:hud_change(hudids.text, "text", string.format("%d/%d", occupied, size))
|
||||||
|
player:hud_change(hudids.text, "number", color)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user