mirror of
https://github.com/minetest-mods/areas.git
synced 2024-12-21 20:42:21 +01:00
Adapt to the new version of playerfactions (#48)
Enable to open an area to many factions Update to adapt to the new version of playerfactions mod, with its new multi-faction mode
This commit is contained in:
parent
a9c05f0e38
commit
c167b30ebf
@ -10,7 +10,7 @@ read_globals = {
|
||||
"AreaStore",
|
||||
"default",
|
||||
"factions",
|
||||
table = { fields = { "copy", "getn" } }
|
||||
table = { fields = { "copy", "getn", "indexof" } }
|
||||
}
|
||||
|
||||
globals = {
|
||||
|
15
README.md
15
README.md
@ -5,6 +5,11 @@ Dependencies
|
||||
------------
|
||||
|
||||
Minetest 5.0.0+ is recommended, but 0.4.16+ should work as well.
|
||||
Minetest 5.0.0+
|
||||
|
||||
Optional support for following mods:
|
||||
|
||||
* [playerfactions](https://git.leagueh.xyz/katp32/playerfactions/) by [katp32](https://git.leagueh.xyz/katp32) & [Kalio_42](https://git.leagueh.xyz/Kalio_42)
|
||||
|
||||
|
||||
Configuration
|
||||
@ -105,10 +110,18 @@ Commands
|
||||
* `/areas_cleanup` -- Removes all ownerless areas.
|
||||
Useful for cleaning after user deletion, for example using /remove_player.
|
||||
|
||||
* `/area_open <ID>` -- Toggle open/closed the specified area for everyone.
|
||||
|
||||
* `/area_faction_open <ID> <faction>` -- Toggle open/closed the specified
|
||||
area for members of the faction. Factions are created and managed by
|
||||
playerfactions mod.
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
Copyright (C) 2013 ShadowNinja
|
||||
Copyright (C) 2013-2017 ShadowNinja
|
||||
|
||||
Copyright (C) 2015-2020 various contributors
|
||||
|
||||
Licensed under the GNU LGPL version 2.1 or later.
|
||||
See LICENSE.txt and http://www.gnu.org/licenses/lgpl-2.1.txt
|
||||
|
16
api.lua
16
api.lua
@ -92,11 +92,23 @@ 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
|
||||
if (factions.version or 0) < 2 then
|
||||
local faction_name = factions.get_player_faction(name)
|
||||
if faction_name then
|
||||
for _, fname in ipairs(area.faction_open or {}) do
|
||||
if faction_name == fname then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
for _, fname in ipairs(area.faction_open or {}) do
|
||||
if factions.player_is_in_faction(fname, name) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
owned = true
|
||||
end
|
||||
return not owned
|
||||
|
@ -286,11 +286,15 @@ 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)
|
||||
if not id then
|
||||
local params = param:split(" ")
|
||||
|
||||
local id = tonumber(params[1])
|
||||
local faction_name = params[2]
|
||||
|
||||
if not id or not faction_name then
|
||||
return false, S("Invalid usage, see /help @1.", "area_faction_open")
|
||||
end
|
||||
|
||||
@ -298,11 +302,25 @@ 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
|
||||
|
||||
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
|
||||
-- Save {} as nil to avoid inflating the DB.
|
||||
fnames = nil
|
||||
end
|
||||
areas.areas[id].faction_open = fnames
|
||||
areas:save()
|
||||
return true, open 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.")
|
||||
end
|
||||
})
|
||||
|
25
hud.lua
25
hud.lua
@ -20,9 +20,28 @@ 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)
|
||||
area.faction_open = faction_info
|
||||
local faction_info
|
||||
if area.faction_open and areas.factions_available then
|
||||
-- Gather and clean up disbanded factions
|
||||
local changed = false
|
||||
for i, fac_name in ipairs(area.faction_open) do
|
||||
if not factions.get_owner(fac_name) then
|
||||
table.remove(area.faction_open, i)
|
||||
changed = true
|
||||
end
|
||||
end
|
||||
if #area.faction_open == 0 then
|
||||
-- Prevent DB clutter, remove value
|
||||
area.faction_open = nil
|
||||
else
|
||||
faction_info = table.concat(area.faction_open, ", ")
|
||||
end
|
||||
|
||||
if changed then
|
||||
areas:save()
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(areaStrings, ("%s [%u] (%s%s%s)")
|
||||
:format(area.name, id, area.owner,
|
||||
area.open and S(":open") or "",
|
||||
|
8
init.lua
8
init.lua
@ -4,7 +4,7 @@
|
||||
|
||||
areas = {}
|
||||
|
||||
areas.factions_available = minetest.global_exists("factions")
|
||||
areas.factions_available = minetest.get_modpath("playerfactions") and true
|
||||
|
||||
areas.adminPrivs = {areas=true}
|
||||
areas.startTime = os.clock()
|
||||
@ -22,10 +22,12 @@ dofile(areas.modpath.."/hud.lua")
|
||||
areas:load()
|
||||
|
||||
minetest.register_privilege("areas", {
|
||||
description = "Can administer areas."
|
||||
description = "Can administer areas.",
|
||||
give_to_singleplayer = false
|
||||
})
|
||||
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
|
||||
|
@ -12,10 +12,12 @@
|
||||
@1 spanning up to @2x@3x@4.=@1 s’étendant jusqu’à @2x@3x@4.
|
||||
A regular expression is required.=Une expression régulière est requise.
|
||||
Area @1 does not exist or is not owned by you.=La zone @1 n’existe pas ou ne vous appartient pas.
|
||||
Faction doesn't exists=La faction n'existe pas
|
||||
Area closed for faction members.=Zone fermée aux membres de la faction.
|
||||
Area closed.=Zone fermée.
|
||||
Area does not exist.=La zone n’existe pas.
|
||||
Area opened for faction members.=Zone ouverte aux membres de la faction.
|
||||
Area is open for members of: @1=Zone ouverte aux membres de ces factions : @1
|
||||
Area opened.=Zone ouverte.
|
||||
Area protected. ID: @1=Zone protégée. ID : @1
|
||||
Area renamed.=Zone renommée.
|
||||
|
@ -12,10 +12,12 @@
|
||||
@1 spanning up to @2x@3x@4.=@1 si estende fino a @2x@3@4.
|
||||
A regular expression is required.=È necessaria una espressione regolare.
|
||||
Area @1 does not exist or is not owned by you.=L'area @1 non esiste o non è di tua proprietà.
|
||||
Faction doesn't exists=La fazione non esiste
|
||||
Area closed for faction members.=Area chiusa per i membri della fazione.
|
||||
Area closed.=Area chiusa.
|
||||
Area does not exist.=L'area non esiste.
|
||||
Area opened for faction members.=Area aperta per i membri della fazione.
|
||||
Area is open for members of: @1=L'area è aperta ai membri di: @1
|
||||
Area opened.=Area aperta.
|
||||
Area protected. ID: @1=Area protetta. ID: @1
|
||||
Area renamed.=Area rinominata.
|
||||
|
@ -12,10 +12,12 @@
|
||||
@1 spanning up to @2x@3x@4.=
|
||||
A regular expression is required.=
|
||||
Area @1 does not exist or is not owned by you.=
|
||||
Faction doesn't exists=
|
||||
Area closed for faction members.=
|
||||
Area closed.=
|
||||
Area does not exist.=
|
||||
Area opened for faction members.=
|
||||
Area is open for members of: @1=
|
||||
Area opened.=
|
||||
Area protected. ID: @1=
|
||||
Area renamed.=
|
||||
|
Loading…
Reference in New Issue
Block a user