Adapted to integrate the new version of playerfactions (multi-factions mode)
This commit is contained in:
parent
142a723eb2
commit
75a0c60c55
18
api.lua
18
api.lua
|
@ -92,9 +92,21 @@ function areas:canInteract(pos, name)
|
|||
if area.owner == name or area.open then
|
||||
return true
|
||||
elseif areas.factions_available and area.faction_open then
|
||||
local faction_name = factions.get_player_faction(area.owner)
|
||||
if faction_name ~= nil and faction_name == factions.get_player_faction(name) then
|
||||
return true
|
||||
local faction_name = nil
|
||||
if factions.version == nil or factions.version < 2 then
|
||||
faction_name = factions.get_player_faction(area.owner)
|
||||
if faction_name ~= nil and faction_name == factions.get_player_faction(name) then
|
||||
return true
|
||||
end
|
||||
else
|
||||
factions_names = area.factions_names
|
||||
if factions_names ~= nil then
|
||||
for _, fname in ipairs(factions_names) do
|
||||
if factions.player_is_in_faction(fname, name) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
owned = true
|
||||
|
|
|
@ -286,10 +286,11 @@ minetest.register_chatcommand("area_open", {
|
|||
|
||||
if areas.factions_available then
|
||||
minetest.register_chatcommand("area_faction_open", {
|
||||
params = S("<ID>"),
|
||||
params = S("<ID> [faction_name]"),
|
||||
description = S("Toggle an area open/closed for members in your faction."),
|
||||
func = function(name, param)
|
||||
local id = tonumber(param)
|
||||
func = function(name, params)
|
||||
local found, _, id, faction_name = params:find("(%d+)%s-(%S-)$")
|
||||
local id = tonumber(id)
|
||||
if not id then
|
||||
return false, S("Invalid usage, see /help @1.", "area_faction_open")
|
||||
end
|
||||
|
@ -298,12 +299,40 @@ if areas.factions_available then
|
|||
return false, S("Area @1 does not exist"
|
||||
.." or is not owned by you.", id)
|
||||
end
|
||||
local open = not areas.areas[id].faction_open
|
||||
-- Save false as nil to avoid inflating the DB.
|
||||
areas.areas[id].faction_open = open or nil
|
||||
areas:save()
|
||||
return true, open and S("Area opened for faction members.")
|
||||
or S("Area closed for faction members.")
|
||||
if factions.version == nil or factions.version < 2 then
|
||||
local open = not areas.areas[id].faction_open
|
||||
-- Save false as nil to avoid inflating the DB.
|
||||
areas.areas[id].faction_open = open or nil
|
||||
areas:save()
|
||||
return true, open and S("Area opened for faction members.")
|
||||
or S("Area closed for faction members.")
|
||||
else
|
||||
local fnames = areas.areas[id].factions_names
|
||||
if fnames == nil then
|
||||
fnames = {}
|
||||
end
|
||||
local removed = false
|
||||
for i, fac_name in ipairs(fnames) do
|
||||
if fname == fac_name then
|
||||
removed = true
|
||||
table.remove(fnames,i)
|
||||
end
|
||||
end
|
||||
if not removed then
|
||||
table.insert(fnames,fname)
|
||||
end
|
||||
local open = true
|
||||
if #fnames == 0 then
|
||||
open = false
|
||||
fnames = nil
|
||||
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:save()
|
||||
return true, not removed and S("Area opened for faction members.")
|
||||
or S("Area closed for faction members.")
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
||||
|
|
21
hud.lua
21
hud.lua
|
@ -20,8 +20,25 @@ minetest.register_globalstep(function(dtime)
|
|||
local areaStrings = {}
|
||||
|
||||
for id, area in pairs(areas:getAreasAtPos(pos)) do
|
||||
local faction_info = area.faction_open and areas.factions_available and
|
||||
factions.get_player_faction(area.owner)
|
||||
local faction_info = area.faction_open and areas.factions_available
|
||||
if faction_info then
|
||||
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
|
||||
if not factions.get_owner(fac_name) then
|
||||
table.remove(area.factions_names, i)
|
||||
end
|
||||
end
|
||||
if #area.factions_names == 0 then
|
||||
area.factions_names = nil
|
||||
faction_info = nil
|
||||
else
|
||||
faction_info = table.concat(area.factions_names, ", ")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
area.faction_open = faction_info
|
||||
table.insert(areaStrings, ("%s [%u] (%s%s%s)")
|
||||
:format(area.name, id, area.owner,
|
||||
|
|
Loading…
Reference in New Issue