add SmallJoker's modifications

This commit is contained in:
Supergoat666 2020-08-25 10:40:45 +02:00
parent 36059b8559
commit cf862f7ce6
5 changed files with 29 additions and 15 deletions

View File

@ -10,7 +10,7 @@ read_globals = {
"AreaStore",
"default",
"factions",
table = { fields = { "copy", "getn" } }
table = { fields = { "copy", "getn", "indexof" } }
}
globals = {

View File

@ -5,6 +5,12 @@ 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://forum.minetest.net/viewtopic.php?t=23281) by aldenp
* [factions](https://forum.minetest.net/viewtopic.php?t=20949) by Coder12
Configuration
@ -107,12 +113,16 @@ Commands
* `/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.
* `/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

View File

@ -92,7 +92,7 @@ function areas:canInteract(pos, name)
if area.owner == name or area.open then
return true
elseif areas.factions_available and area.faction_open then
if factions.version == nil or factions.version < 2 then
if (factions.version or 0) < 2 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

View File

@ -302,6 +302,7 @@ if areas.factions_available then
.." or is not owned by you.", id)
end
if (factions.version or 0) < 2 or factions.mode_unique_faction then
-- Single faction mode
local open = not areas.areas[id].faction_open and {factions.get_player_faction(name)}
-- Save false as nil to avoid inflating the DB.
areas.areas[id].faction_open = open or nil
@ -309,6 +310,7 @@ if areas.factions_available then
return true, open and S("Area opened for faction members.")
or S("Area closed for faction members.")
end
-- Multiple factions support
local faction_name = params[2]
if not factions.get_owner(faction_name) then
return false, S("Faction doesn't exists")
@ -322,12 +324,12 @@ if areas.factions_available then
table.remove(fnames, pos)
end
if #fnames == 0 then
-- Save {} as nil to avoid inflating the DB.
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,", "))
return true, fnames and S("Area is open for members of: @1", table.concat(fnames, ", "))
or S("Area closed for faction members.")
end
})

20
hud.lua
View File

@ -20,28 +20,30 @@ 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
if faction_info then
if factions.version == nil or factions.version < 2 then
local faction_info
if area.faction_open and areas.factions_available then
-- Gather and clean up disbanded factions
if (factions.version or 0) < 2 then
faction_info = factions.get_player_faction(area.owner)
else
-- Verify that every displayed faction still exists
local faction_open_changed = false
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)
faction_open_changed = true
changed = true
end
end
if #area.faction_open == 0 then
-- Prevent DB clutter, remove value
area.faction_open = nil
faction_info = nil
faction_open_changed = true
else
faction_info = table.concat(area.faction_open, ", ")
end
-- Save areas if a faction was disband
if faction_open_changed then areas:save() end
if changed then
areas:save()
end
end
end