113 lines
2.5 KiB
Lua
113 lines
2.5 KiB
Lua
local saved_huds = {} -- pl_name = {hud_name = id}
|
|
|
|
|
|
function fbrawl.generate_HUD(arena, pl_name)
|
|
local player = minetest.get_player_by_name(pl_name)
|
|
|
|
local stats_bg
|
|
local kills
|
|
local deaths
|
|
|
|
stats_bg = player:hud_add({
|
|
hud_elem_type = "image",
|
|
position = {x = 1, y = 0.5},
|
|
offset = {x = -25*3 + -25*2/3, y = 0},
|
|
text = "fbrawl_hud_stats.png",
|
|
alignment = { x = 1, y=0.5},
|
|
scale = { x = 3, y = 3},
|
|
number = 0xFFFFFF,
|
|
})
|
|
|
|
kills = player:hud_add({
|
|
hud_elem_type = "text",
|
|
position = {x = 1, y = 0.5},
|
|
offset = {x = -53, y = 27},
|
|
text = 0,
|
|
number = 0xFFFFFF,
|
|
})
|
|
|
|
deaths = player:hud_add({
|
|
hud_elem_type = "text",
|
|
position = {x = 1, y = 0.5},
|
|
offset = {x = -53, y = 107.5},
|
|
text = 0,
|
|
number = 0xFFFFFF,
|
|
})
|
|
|
|
saved_huds[pl_name] = {
|
|
stats_bg = stats_bg,
|
|
kills = kills,
|
|
deaths = deaths
|
|
}
|
|
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 |