Add support for playerfactions mod (#37)

Add faction indicator to HUD
This commit is contained in:
Alden Peeters 2019-09-21 09:33:42 -04:00 committed by SmallJoker
parent 95c1165e28
commit aca830fd22
5 changed files with 39 additions and 4 deletions

@ -94,10 +94,14 @@ function areas:canInteract(pos, name)
for _, area in pairs(self:getAreasAtPos(pos)) do for _, area in pairs(self:getAreasAtPos(pos)) do
if area.owner == name or area.open then if area.owner == name or area.open then
return true return true
else elseif areas.factions_available and area.faction_open then
owned = true 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
end end
owned = true
end
return not owned return not owned
end end

@ -286,6 +286,30 @@ minetest.register_chatcommand("area_open", {
}) })
if areas.factions_available then
minetest.register_chatcommand("area_faction_open", {
params = "<ID>",
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", { minetest.register_chatcommand("move_area", {
params = "<ID>", params = "<ID>",
description = "Move (or resize) an area to the current positions.", description = "Move (or resize) an area to the current positions.",

@ -21,9 +21,13 @@ 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
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, :format(area.name, id, area.owner,
area.open and ":open" or "")) area.open and ":open" or "",
faction_info and ":"..faction_info or ""))
end end
for i, area in pairs(areas:getExternalHudEntries(pos)) do for i, area in pairs(areas:getExternalHudEntries(pos)) do

@ -4,6 +4,8 @@
areas = {} areas = {}
areas.factions_available = minetest.global_exists("factions")
areas.adminPrivs = {areas=true} areas.adminPrivs = {areas=true}
areas.startTime = os.clock() areas.startTime = os.clock()

@ -1 +1,2 @@
name = areas name = areas
optional_depends = playerfactions