Update areas part 2

This commit is contained in:
LeMagnesium 2015-01-08 22:28:47 +01:00
parent 21d96a9f00
commit fb4a56f9ac
1 changed files with 21 additions and 22 deletions

View File

@ -6,37 +6,36 @@ minetest.register_globalstep(function(dtime)
for _, player in pairs(minetest.get_connected_players()) do
local name = player:get_player_name()
local pos = vector.round(player:getpos())
local areaString = ""
local first = true
local areaStrings = {}
for id, area in pairs(areas:getAreasAtPos(pos)) do
if not first then
areaString = areaString..", "
else
first = false
end
areaString = areaString .. ("%s [%u] (%s%s)")
table.insert(areaStrings, ("%s [%u] (%s%s)")
:format(area.name, id, area.owner,
area.open and ":open" or "")
area.open and ":open" or ""))
end
if not areas.hud[name] then
areas.hud[name] = {}
areas.hud[name].areasId = player:hud_add({
hud_elem_type = "text",
local areaString = "Areas:"
if #areaStrings > 0 then
areaString = areaString.."\n"..
table.concat(areaStrings, "\n")
end
local hud = areas.hud[name]
if not hud then
hud = {}
areas.hud[name] = hud
hud.areasId = player:hud_add({
hud_elem_type = "text",
name = "Areas",
number = 0xFFFFFF,
position = {x=0, y=1},
offset = {x=5, y=-85},
direction = 0,
text = "Areas: "..areaString,
offset = {x=8, y=-8},
text = areaString,
scale = {x=200, y=60},
alignment = {x=1, y=1},
alignment = {x=1, y=-1},
})
areas.hud[name].oldAreas = areaString
hud.oldAreas = areaString
return
elseif areas.hud[name].oldAreas ~= areaString then
player:hud_change(areas.hud[name].areasId, "text",
"Areas: "..areaString)
areas.hud[name].oldAreas = areaString
elseif hud.oldAreas ~= areaString then
player:hud_change(hud.areasId, "text", areaString)
hud.oldAreas = areaString
end
end
end)