factions/hud.lua

112 lines
2.8 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-28 04:37:49 +01:00
if player then
local name = player:get_player_name()
local id_name = name .. "factionLand"
if not hud_ids[id_name] then
hud_ids[id_name] = 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-28 02:06:48 +01:00
end
2018-10-15 17:24:58 +02:00
end
2018-10-17 04:58:15 +02:00
function createHudFactionName(player,factionname)
2018-10-28 04:37:49 +01:00
if player and factionname then
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
2018-10-15 17:24:58 +02:00
end
end
2018-10-17 04:58:15 +02:00
function createHudPower(player,faction)
2018-10-28 04:37:49 +01:00
if player and faction then
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},
text = "Power "..faction.power.."/".. faction.usedpower .."/"..faction.maxpower,
scale = {x=1, y=1},
alignment = {x=-1, y=0},
offset = {x = 0, y = 0}
})
end
2018-10-15 17:24:58 +02:00
end
end
2018-10-31 22:15:08 +01:00
function removeHud(player,hudname)
local name = ""
local p = {}
if type(player) ~= "string" then
name = player:get_player_name()
p = player
else
name = player
p = minetest.get_player_by_name(player)
end
local id_name = name .. hudname
if hud_ids[id_name] then
p:hud_remove(hud_ids[id_name])
hud_ids[id_name] = nil
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-31 22:15:08 +01:00
function updateFactionName(player,factionname)
2018-10-22 21:30:11 +02:00
local name = ""
local p = {}
if type(player) ~= "string" then
name = player:get_player_name()
p = player
else
name = player
p = minetest.get_player_by_name(player)
end
2018-10-31 22:15:08 +01:00
local id_name = name .. "factionName"
2018-10-15 17:24:58 +02:00
if hud_ids[id_name] then
2018-10-31 22:15:08 +01:00
p:hud_change(hud_ids[id_name],"text","Faction "..factionname)
2018-10-15 17:24:58 +02:00
end
end
2018-10-17 04:58:15 +02:00
function hudUpdateClaimInfo()
2018-10-27 22:40:17 +02:00
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")
2018-10-15 17:24:58 +02:00
end
2018-10-27 22:40:17 +02:00
end
minetest.after(3,hudUpdateClaimInfo)
2018-10-15 17:24:58 +02:00
end