From aca830fd2298980758e09908087a9f5f74dff93f Mon Sep 17 00:00:00 2001 From: Alden Peeters Date: Sat, 21 Sep 2019 09:33:42 -0400 Subject: [PATCH] Add support for playerfactions mod (#37) Add faction indicator to HUD --- api.lua | 8 ++++++-- chatcommands.lua | 24 ++++++++++++++++++++++++ hud.lua | 8 ++++++-- init.lua | 2 ++ mod.conf | 1 + 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/api.lua b/api.lua index 8103b84..40a9841 100644 --- a/api.lua +++ b/api.lua @@ -94,9 +94,13 @@ function areas:canInteract(pos, name) for _, area in pairs(self:getAreasAtPos(pos)) do if area.owner == name or area.open then return true - else - owned = 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 + return true + end end + owned = true end return not owned end diff --git a/chatcommands.lua b/chatcommands.lua index ddff850..faffb03 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -286,6 +286,30 @@ minetest.register_chatcommand("area_open", { }) +if areas.factions_available then + minetest.register_chatcommand("area_faction_open", { + params = "", + description = "Toggle an area open/closed for members in 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/hud.lua b/hud.lua index 24f5414..ffe764e 100644 --- a/hud.lua +++ b/hud.lua @@ -21,9 +21,13 @@ minetest.register_globalstep(function(dtime) local areaStrings = {} for id, area in pairs(areas:getAreasAtPos(pos)) do - table.insert(areaStrings, ("%s [%u] (%s%s)") + local faction_info = area.faction_open and areas.factions_available and + factions.get_player_faction(area.owner) + area.faction_open = faction_info + table.insert(areaStrings, ("%s [%u] (%s%s%s)") :format(area.name, id, area.owner, - area.open and ":open" or "")) + area.open and ":open" or "", + faction_info and ":"..faction_info or "")) end for i, area in pairs(areas:getExternalHudEntries(pos)) do diff --git a/init.lua b/init.lua index 8179b28..53d4eb6 100644 --- a/init.lua +++ b/init.lua @@ -4,6 +4,8 @@ areas = {} +areas.factions_available = minetest.global_exists("factions") + areas.adminPrivs = {areas=true} areas.startTime = os.clock() diff --git a/mod.conf b/mod.conf index 0ca8ec1..e694301 100644 --- a/mod.conf +++ b/mod.conf @@ -1 +1,2 @@ name = areas +optional_depends = playerfactions