add SmallJoker's modifications
This commit is contained in:
parent
36059b8559
commit
cf862f7ce6
|
@ -10,7 +10,7 @@ read_globals = {
|
||||||
"AreaStore",
|
"AreaStore",
|
||||||
"default",
|
"default",
|
||||||
"factions",
|
"factions",
|
||||||
table = { fields = { "copy", "getn" } }
|
table = { fields = { "copy", "getn", "indexof" } }
|
||||||
}
|
}
|
||||||
|
|
||||||
globals = {
|
globals = {
|
||||||
|
|
14
README.md
14
README.md
|
@ -5,6 +5,12 @@ Dependencies
|
||||||
------------
|
------------
|
||||||
|
|
||||||
Minetest 5.0.0+ is recommended, but 0.4.16+ should work as well.
|
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
|
Configuration
|
||||||
|
@ -107,12 +113,16 @@ Commands
|
||||||
|
|
||||||
* `/area_open <ID>` -- Toggle open/closed the specified area for everyone.
|
* `/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
|
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.
|
Licensed under the GNU LGPL version 2.1 or later.
|
||||||
See LICENSE.txt and http://www.gnu.org/licenses/lgpl-2.1.txt
|
See LICENSE.txt and http://www.gnu.org/licenses/lgpl-2.1.txt
|
||||||
|
|
2
api.lua
2
api.lua
|
@ -92,7 +92,7 @@ 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
|
||||||
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)
|
local 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
|
||||||
|
|
|
@ -302,6 +302,7 @@ if areas.factions_available then
|
||||||
.." or is not owned by you.", id)
|
.." or is not owned by you.", id)
|
||||||
end
|
end
|
||||||
if (factions.version or 0) < 2 or factions.mode_unique_faction then
|
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)}
|
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
|
||||||
|
@ -309,6 +310,7 @@ if areas.factions_available then
|
||||||
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.")
|
||||||
end
|
end
|
||||||
|
-- Multiple factions support
|
||||||
local faction_name = params[2]
|
local faction_name = params[2]
|
||||||
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")
|
||||||
|
@ -322,12 +324,12 @@ if areas.factions_available then
|
||||||
table.remove(fnames, pos)
|
table.remove(fnames, pos)
|
||||||
end
|
end
|
||||||
if #fnames == 0 then
|
if #fnames == 0 then
|
||||||
|
-- Save {} as nil to avoid inflating the DB.
|
||||||
fnames = nil
|
fnames = nil
|
||||||
end
|
end
|
||||||
-- Save {} as nil to avoid inflating the DB.
|
|
||||||
areas.areas[id].faction_open = fnames
|
areas.areas[id].faction_open = fnames
|
||||||
areas:save()
|
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.")
|
or S("Area closed for faction members.")
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
20
hud.lua
20
hud.lua
|
@ -20,28 +20,30 @@ 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
|
local faction_info
|
||||||
if faction_info then
|
if area.faction_open and areas.factions_available then
|
||||||
if factions.version == nil or factions.version < 2 then
|
-- Gather and clean up disbanded factions
|
||||||
|
if (factions.version or 0) < 2 then
|
||||||
faction_info = factions.get_player_faction(area.owner)
|
faction_info = factions.get_player_faction(area.owner)
|
||||||
else
|
else
|
||||||
-- Verify that every displayed faction still exists
|
-- 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
|
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.faction_open, i)
|
table.remove(area.faction_open, i)
|
||||||
faction_open_changed = true
|
changed = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if #area.faction_open == 0 then
|
if #area.faction_open == 0 then
|
||||||
|
-- Prevent DB clutter, remove value
|
||||||
area.faction_open = nil
|
area.faction_open = nil
|
||||||
faction_info = nil
|
|
||||||
faction_open_changed = true
|
|
||||||
else
|
else
|
||||||
faction_info = table.concat(area.faction_open, ", ")
|
faction_info = table.concat(area.faction_open, ", ")
|
||||||
end
|
end
|
||||||
-- Save areas if a faction was disband
|
|
||||||
if faction_open_changed then areas:save() end
|
if changed then
|
||||||
|
areas:save()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue