new areas systeme

This commit is contained in:
crabman77 2016-06-18 19:12:57 +02:00
parent e96e52f358
commit 28a913a925
9 changed files with 54 additions and 22 deletions

View File

@ -3,42 +3,74 @@
areas.hud = {}
local function tick()
minetest.after(1, tick)
for _, player in pairs(minetest.get_connected_players()) do
local name = player:get_player_name()
local pos = vector.round(player:getpos())
local areaStrings = {}
local area_text = "no areas\n\n"
local area_owner_name = ""
local mod_owner = 0
local mod_open = 0
local mod_farming = 0
local area_name = ""
local nb_areas = 0
for id, area in pairs(areas:getAreasAtPos(pos)) do
table.insert(areaStrings, ("%s [%u] (%s%s)")
:format(area.name, id, area.owner,
area.open and ":open" or area.openfarming and ":open to farming" or ""))
nb_areas = nb_areas+1
if areas:isAreaOwner(id, name) then
mod_owner = 1
end
if area.open then
mod_open = 1
end
if area.openfarming then
mod_farming = 1
end
if not area.parent then
area_owner_name = area.owner
area_name = area.name
end
end
local areaString = "Areas:"
if #areaStrings > 0 then
areaString = areaString.."\n"..
table.concat(areaStrings, "\n")
local icon = "areas_1_0_1.png"
if nb_areas > 0 then
area_text = ("nb area:%u\nowner:%s\nname:%s"):format(nb_areas, area_owner_name, area_name)
icon = ("areas_%u_%u_%u.png"):format(mod_owner, mod_open, mod_farming)
end
local hud = areas.hud[name]
if not hud then
hud = {}
areas.hud[name] = hud
hud.areasId = player:hud_add({
if not areas.hud[name] then
areas.hud[name] = {}
areas.hud[name].icon = player:hud_add({
hud_elem_type = "image",
position = {x=0,y=1},
scale = {x=1,y=1},
offset = {x=26,y=-60},
text = icon,
})
areas.hud[name].areas_id = player:hud_add({
hud_elem_type = "text",
name = "Areas",
number = 0xFFFFFF,
position = {x=0, y=1},
offset = {x=8, y=-8},
text = areaString,
scale = {x=200, y=60},
offset = {x=48, y=-40},
text = area_text,
scale = {x=1, y=1},
alignment = {x=1, y=-1},
})
hud.oldAreas = areaString
return
elseif hud.oldAreas ~= areaString then
player:hud_change(hud.areasId, "text", areaString)
hud.oldAreas = areaString
areas.hud[name].old_area_text = area_text
areas.hud[name].old_icon = icon
else
if areas.hud[name].old_area_text ~= area_text then
player:hud_change(areas.hud[name].areas_id, "text", area_text)
areas.hud[name].old_area_text = area_text
end
if areas.hud[name].old_icon ~= icon then
player:hud_change(areas.hud[name].icon, "text", icon)
areas.hud[name].old_icon = icon
end
end
end
minetest.after(1.5, tick)
end
tick()

Binary file not shown.

After

Width:  |  Height:  |  Size: 365 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 668 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 669 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 669 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 499 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 385 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 383 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 792 B