Resolve comments

This commit is contained in:
Supergoat666 2020-08-25 02:21:05 +02:00
parent a615b80a22
commit aced077da7
2 changed files with 24 additions and 34 deletions

View File

@ -98,16 +98,13 @@ function areas:canInteract(pos, name)
return true return true
end end
else else
local factions_names = area.faction_open for _, fname in ipairs(area.faction_open or {}) do
if factions_names ~= nil then
for _, fname in ipairs(factions_names) do
if factions.player_is_in_faction(fname, name) then if factions.player_is_in_faction(fname, name) then
return true return true
end end
end end
end end
end end
end
owned = true owned = true
end end
return not owned return not owned

View File

@ -303,31 +303,25 @@ if areas.factions_available then
return false, S("Area @1 does not exist" return false, S("Area @1 does not exist"
.." or is not owned by you.", id) .." or is not owned by you.", id)
end end
if factions.version == nil or factions.version < 2 or factions.mode_unique_faction then if (factions.version or 0) < 2 or factions.mode_unique_faction then
local open = not areas.areas[id].faction_open and {factions.get_player_faction(name)} local open = not areas.areas[id].faction_open and {factions.get_player_faction(name)}
-- Save false as nil to avoid inflating the DB. -- Save false as nil to avoid inflating the DB.
areas.areas[id].faction_open = open or nil areas.areas[id].faction_open = open or nil
areas:save() areas:save()
return true, open and S("Area opened for faction members.") return true, open and S("Area opened for faction members.")
or S("Area closed for faction members.") or S("Area closed for faction members.")
else end
local faction_name = params[2] local faction_name = params[2]
if not factions.get_owner(faction_name) then if not factions.get_owner(faction_name) then
return false, S("Faction doesn't exists") return false, S("Faction doesn't exists")
end end
local fnames = areas.areas[id].faction_open local fnames = areas.areas[id].faction_open or {}
if fnames == nil then local pos = table.indexof(fnames, faction_name)
fnames = {} if pos < 0 then
end -- Add new faction to the list
local removed = false
for i, fac_name in ipairs(fnames) do
if faction_name == fac_name then
table.remove(fnames,i)
removed = true
end
end
if not removed then
table.insert(fnames, faction_name) table.insert(fnames, faction_name)
else
table.remove(fnames, pos)
end end
if #fnames == 0 then if #fnames == 0 then
fnames = nil fnames = nil
@ -338,7 +332,6 @@ if areas.factions_available then
return true, fnames and S("Area is open for members of: @1",table.concat(fnames,", ")) return true, fnames and S("Area is open for members of: @1",table.concat(fnames,", "))
or S("Area closed for faction members.") or S("Area closed for faction members.")
end end
end
}) })
end end