Improve area_faction_open
This commit is contained in:
parent
04961bee69
commit
b21e1891c2
2
api.lua
2
api.lua
|
@ -99,7 +99,7 @@ function areas:canInteract(pos, name)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
factions_names = area.factions_names
|
factions_names = area.faction_open
|
||||||
if factions_names ~= nil then
|
if factions_names ~= nil then
|
||||||
for _, fname in ipairs(factions_names) do
|
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
|
||||||
|
|
|
@ -303,8 +303,8 @@ 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
|
if factions.version == nil or factions.version < 2 or factions.mode_unique_faction then
|
||||||
local open = not areas.areas[id].faction_open
|
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()
|
||||||
|
@ -315,34 +315,27 @@ if areas.factions_available then
|
||||||
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].factions_names
|
local fnames = areas.areas[id].faction_openf
|
||||||
if fnames == nil then
|
if fnames == nil then
|
||||||
fnames = {}
|
fnames = {}
|
||||||
end
|
end
|
||||||
local removed = false
|
local removed = false
|
||||||
for i, fac_name in ipairs(fnames) do
|
for i, fac_name in ipairs(fnames) do
|
||||||
if fname == fac_name then
|
if faction_name == fac_name then
|
||||||
removed = true
|
removed = true
|
||||||
table.remove(fnames,i)
|
table.remove(fnames,i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not removed then
|
if not removed then
|
||||||
table.insert(fnames,fname)
|
table.insert(fnames,faction_name)
|
||||||
end
|
end
|
||||||
local open = true
|
|
||||||
local accessibility = ""
|
|
||||||
if #fnames == 0 then
|
if #fnames == 0 then
|
||||||
open = false
|
|
||||||
fnames = nil
|
fnames = nil
|
||||||
else
|
|
||||||
accessibility = " It is open for members of : "..table.concat(fnames,", ")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
areas.areas[id].factions_names = fnames
|
|
||||||
-- 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 = fnames
|
||||||
areas:save()
|
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.")
|
or S("Area closed for faction members.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
11
hud.lua
11
hud.lua
|
@ -25,21 +25,20 @@ minetest.register_globalstep(function(dtime)
|
||||||
if factions.version == nil or factions.version < 2 then
|
if factions.version == nil or factions.version < 2 then
|
||||||
faction_info = factions.get_player_faction(area.owner)
|
faction_info = factions.get_player_faction(area.owner)
|
||||||
else
|
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
|
if not factions.get_owner(fac_name) then
|
||||||
table.remove(area.factions_names, i)
|
table.remove(area.faction_open, i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if #area.factions_names == 0 then
|
if #area.faction_open == 0 then
|
||||||
area.factions_names = nil
|
area.faction_open = nil
|
||||||
faction_info = nil
|
faction_info = nil
|
||||||
else
|
else
|
||||||
faction_info = table.concat(area.factions_names, ", ")
|
faction_info = table.concat(area.faction_open, ", ")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
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,
|
||||||
area.open and S(":open") or "",
|
area.open and S(":open") or "",
|
||||||
|
|
6
init.lua
6
init.lua
|
@ -22,10 +22,12 @@ dofile(areas.modpath.."/hud.lua")
|
||||||
areas:load()
|
areas:load()
|
||||||
|
|
||||||
minetest.register_privilege("areas", {
|
minetest.register_privilege("areas", {
|
||||||
description = "Can administer areas."
|
description = "Can administer areas.",
|
||||||
|
give_to_singleplayer = false
|
||||||
})
|
})
|
||||||
minetest.register_privilege("areas_high_limit", {
|
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
|
if not minetest.registered_privileges[areas.config.self_protection_privilege] then
|
||||||
|
|
Loading…
Reference in New Issue