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,12 +98,9 @@ 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 if factions.player_is_in_faction(fname, name) then
for _, fname in ipairs(factions_names) do return true
if factions.player_is_in_faction(fname, name) then
return true
end
end end
end end
end end

View File

@ -303,41 +303,34 @@ 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
local faction_name = params[2]
if not factions.get_owner(faction_name) then
return false, S("Faction doesn't exists")
end
local fnames = areas.areas[id].faction_open
if fnames == nil then
fnames = {}
end
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)
end
if #fnames == 0 then
fnames = nil
end
-- Save {} as nil to avoid inflating the DB.
areas.areas[id].faction_open = fnames
areas:save()
return true, fnames and S("Area is open for members of: @1",table.concat(fnames,", "))
or S("Area closed for faction members.")
end end
local faction_name = params[2]
if not factions.get_owner(faction_name) then
return false, S("Faction doesn't exists")
end
local fnames = areas.areas[id].faction_open or {}
local pos = table.indexof(fnames, faction_name)
if pos < 0 then
-- Add new faction to the list
table.insert(fnames, faction_name)
else
table.remove(fnames, pos)
end
if #fnames == 0 then
fnames = nil
end
-- Save {} as nil to avoid inflating the DB.
areas.areas[id].faction_open = fnames
areas:save()
return true, fnames and S("Area is open for members of: @1",table.concat(fnames,", "))
or S("Area closed for faction members.")
end end
}) })
end end