factions/hud.lua

82 lines
2.1 KiB
Lua
Raw Normal View History

2018-10-15 17:24:58 +02:00
hud_ids = {}
2018-10-17 04:58:15 +02:00
function createHudfactionLand(player)
2018-10-15 17:24:58 +02:00
local name = player:get_player_name()
hud_ids[name .. "factionLand"] = player:hud_add({
hud_elem_type = "text",
name = "factionLand",
number = 0xFFFFFF,
position = {x=0.1, y = .98},
text = "Wilderness",
scale = {x=1, y=1},
alignment = {x=0, y=0},
})
end
2018-10-17 04:58:15 +02:00
function createHudFactionName(player,factionname)
2018-10-15 17:24:58 +02:00
local name = player:get_player_name()
local id_name = name .. "factionName"
if not hud_ids[id_name] then
hud_ids[id_name] = player:hud_add({
hud_elem_type = "text",
name = "factionName",
number = 0xFFFFFF,
position = {x=1, y = 0},
text = "Faction "..factionname,
scale = {x=1, y=1},
alignment = {x=-1, y=0},
offset = {x = -20, y = 20}
})
end
end
2018-10-17 04:58:15 +02:00
function createHudPower(player,faction)
2018-10-15 17:24:58 +02:00
local name = player:get_player_name()
local id_name = name .. "powerWatch"
if not hud_ids[id_name] then
hud_ids[id_name] = player:hud_add({
hud_elem_type = "text",
name = "powerWatch",
number = 0xFFFFFF,
position = {x=0.9, y = .98},
2018-10-17 04:58:15 +02:00
text = "Power "..faction.power.."/".. faction.usedpower .."/"..faction.maxpower,
2018-10-15 17:24:58 +02:00
scale = {x=1, y=1},
alignment = {x=-1, y=0},
offset = {x = 0, y = 0}
})
end
end
2018-10-17 04:58:15 +02:00
function updateHudPower(player,faction)
2018-10-15 17:24:58 +02:00
local name = player:get_player_name()
local id_name = name .. "powerWatch"
if hud_ids[id_name] then
2018-10-17 04:58:15 +02:00
player:hud_change(hud_ids[id_name],"text","Power "..faction.power.."/".. faction.usedpower .."/"..faction.maxpower)
2018-10-15 17:24:58 +02:00
end
end
2018-10-17 04:58:15 +02:00
function removeHud(player,hudname)
2018-10-15 17:24:58 +02:00
local name = player:get_player_name()
local id_name = name .. hudname
if hud_ids[id_name] then
player:hud_remove(hud_ids[id_name])
hud_ids[id_name] = nil
end
end
2018-10-17 04:58:15 +02:00
function hudUpdateClaimInfo()
2018-10-15 17:24:58 +02:00
minetest.after(3,
function()
local playerslist = minetest.get_connected_players()
for i in pairs(playerslist) do
local player = playerslist[i]
local name = player:get_player_name()
local faction = factions.get_faction_at(player:getpos())
local id_name = name .. "factionLand"
if hud_ids[id_name] then
player:hud_change(hud_ids[id_name],"text",(faction and faction.name) or "Wilderness")
end
end
2018-10-17 04:58:15 +02:00
hudUpdateClaimInfo()
2018-10-15 17:24:58 +02:00
end)
end