Improve area_faction_open

This commit is contained in:
Supergoat666 2020-08-18 13:57:18 +02:00
parent 04961bee69
commit b21e1891c2
4 changed files with 19 additions and 25 deletions

View File

@ -99,7 +99,7 @@ function areas:canInteract(pos, name)
return true
end
else
factions_names = area.factions_names
factions_names = area.faction_open
if factions_names ~= nil then
for _, fname in ipairs(factions_names) do
if factions.player_is_in_faction(fname, name) then

View File

@ -298,13 +298,13 @@ if areas.factions_available then
if not id then
return false, S("Invalid usage, see /help @1.", "area_faction_open")
end
if not areas:isAreaOwner(id, name) then
return false, S("Area @1 does not exist"
.." or is not owned by you.", id)
end
if factions.version == nil or factions.version < 2 then
local open = not areas.areas[id].faction_open
if factions.version == nil or factions.version < 2 or factions.mode_unique_faction then
local open = not areas.areas[id].faction_open and factions.get_player_faction(name)
-- Save false as nil to avoid inflating the DB.
areas.areas[id].faction_open = open or nil
areas:save()
@ -315,34 +315,27 @@ if areas.factions_available then
if not factions.get_owner(faction_name) then
return false, S("Faction doesn't exists")
end
local fnames = areas.areas[id].factions_names
local fnames = areas.areas[id].faction_openf
if fnames == nil then
fnames = {}
end
local removed = false
for i, fac_name in ipairs(fnames) do
if fname == fac_name then
if faction_name == fac_name then
removed = true
table.remove(fnames,i)
end
end
if not removed then
table.insert(fnames,fname)
table.insert(fnames,faction_name)
end
local open = true
local accessibility = ""
if #fnames == 0 then
open = false
fnames = nil
else
accessibility = " It is open for members of : "..table.concat(fnames,", ")
end
areas.areas[id].factions_names = fnames
-- Save false as nil to avoid inflating the DB.
areas.areas[id].faction_open = open or nil
areas.areas[id].faction_open = fnames
areas:save()
return true, not removed and S("Area opened for faction members.")
return true, fnames and S("Area is open for members of @1",table.concat(fnames,", "))
or S("Area closed for faction members.")
end
end

13
hud.lua
View File

@ -25,25 +25,24 @@ minetest.register_globalstep(function(dtime)
if factions.version == nil or factions.version < 2 then
faction_info = factions.get_player_faction(area.owner)
else
for i, fac_name in ipairs(area.factions_names) do
for i, fac_name in ipairs(area.faction_open) do
if not factions.get_owner(fac_name) then
table.remove(area.factions_names, i)
table.remove(area.faction_open, i)
end
end
if #area.factions_names == 0 then
area.factions_names = nil
if #area.faction_open == 0 then
area.faction_open = nil
faction_info = nil
else
faction_info = table.concat(area.factions_names, ", ")
faction_info = table.concat(area.faction_open, ", ")
end
end
end
area.faction_open = faction_info
table.insert(areaStrings, ("%s [%u] (%s%s%s)")
:format(area.name, id, area.owner,
area.open and S(":open") or "",
faction_info and ":"..faction_info or ""))
faction_info and ": "..faction_info or ""))
end
for i, area in pairs(areas:getExternalHudEntries(pos)) do

View File

@ -22,10 +22,12 @@ dofile(areas.modpath.."/hud.lua")
areas:load()
minetest.register_privilege("areas", {
description = "Can administer areas."
description = "Can administer areas.",
give_to_singleplayer = false
})
minetest.register_privilege("areas_high_limit", {
description = "Can protect more, bigger areas."
description = "Can protect more, bigger areas.",
give_to_singleplayer = false
})
if not minetest.registered_privileges[areas.config.self_protection_privilege] then