82 lines
1.8 KiB
Lua

local saved_huds = {} -- pl_name = {hud_name = id}
-- TODO: ultimate HUD
function fbrawl.generate_HUD(arena, pl_name)
-- Save the huds IDs for each player.
--saved_huds[pl_name] = {
-- backgound = background,
-- timer = timer,
--}
end
function fbrawl.update_hud(pl_name, field, new_value)
if saved_huds[pl_name] and saved_huds[pl_name][field] then
local player = minetest.get_player_by_name(pl_name)
player:hud_change(saved_huds[pl_name][field], "text", new_value)
end
end
function fbrawl.remove_huds(pl_name)
minetest.after(1, function()
local player = minetest.get_player_by_name(pl_name)
if not player or not saved_huds[pl_name] then return end
for name, id in pairs(saved_huds[pl_name]) do
player:hud_remove(id)
end
saved_huds[pl_name] = {}
end)
end
function fbrawl.add_temp_hud(pl_name, hud, time)
local player = minetest.get_player_by_name(pl_name)
hud = player:hud_add(hud)
saved_huds[pl_name] = saved_huds[pl_name] or {}
saved_huds[pl_name][tostring(hud)] = hud
minetest.after(time, function()
-- Removing the hud if the player still has it.
if saved_huds[pl_name] and saved_huds[pl_name][tostring(hud)] then
player:hud_remove(hud)
saved_huds[pl_name][tostring(hud)] = nil
end
end)
return hud
end
function fbrawl.add_hud(pl_name, name, def)
local player = minetest.get_player_by_name(pl_name)
if not player then return end
local hud = player:hud_add(def)
saved_huds[pl_name] = saved_huds[pl_name] or {}
saved_huds[pl_name][name] = hud
return hud
end
function fbrawl.remove_hud(pl_name, name)
local player = minetest.get_player_by_name(pl_name)
if not player or not saved_huds[pl_name] or not saved_huds[pl_name][name] then return end
player:hud_remove(saved_huds[pl_name][name])
saved_huds[pl_name][name] = nil
end