From c4820a810629df0021f221966b8b87c29af43ae9 Mon Sep 17 00:00:00 2001 From: Alden Peeters Date: Mon, 9 Sep 2019 15:55:24 -0400 Subject: [PATCH] Add factions support --- api.lua | 5 +++++ chatcommands.lua | 24 ++++++++++++++++++++++++ mod.conf | 1 + 3 files changed, 30 insertions(+) diff --git a/api.lua b/api.lua index 8103b84..c98d262 100644 --- a/api.lua +++ b/api.lua @@ -94,6 +94,11 @@ function areas:canInteract(pos, name) for _, area in pairs(self:getAreasAtPos(pos)) do if area.owner == name or area.open then return true + elseif factions 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 + end else owned = true end diff --git a/chatcommands.lua b/chatcommands.lua index ddff850..9bc5c9c 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -286,6 +286,30 @@ minetest.register_chatcommand("area_open", { }) +if factions then + minetest.register_chatcommand("area_faction_open", { + params = "", + description = "Toggle an area open (anyone can interact) or closed to your faction", + func = function(name, param) + local id = tonumber(param) + if not id then + return false, "Invalid usage, see /help area_faction_open." + end + + if not areas:isAreaOwner(id, name) then + return false, "Area "..id.." does not exist" + .." or is not owned by you." + 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 + areas:save() + return true, ("Area %s for faction members."):format(open and "opened" or "closed") + end + }) +end + + minetest.register_chatcommand("move_area", { params = "", description = "Move (or resize) an area to the current positions.", diff --git a/mod.conf b/mod.conf index 0ca8ec1..2bee191 100644 --- a/mod.conf +++ b/mod.conf @@ -1 +1,2 @@ name = areas +optional_depends = factions