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