Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/minetest-mods/areas into …
Browse files Browse the repository at this point in the history
…HEAD
  • Loading branch information
fluxionary committed Nov 23, 2019
2 parents f512888 + aca830f commit 9f09e23
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
8 changes: 6 additions & 2 deletions api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions chatcommands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,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", {
params = "<ID>",
description = "Move (or resize) an area to the current positions.",
Expand Down
8 changes: 6 additions & 2 deletions hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ minetest.register_globalstep(function(dtime)
local areaStrings = {}

for id, area in pairs(areas:getAreasAtPos(pos)) do
table.insert(areaStrings, ("%s [%u] (%s%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%s)")
:format(area.name, id, area.owner,
area.open and ":open" or "",
area.canPvP and ":PvP" or ""))
faction_info and ":"..faction_info or "",
area.canPvP and ":PvP" or ""))
end

for i, area in pairs(areas:getExternalHudEntries(pos)) do
Expand Down
2 changes: 2 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

areas = {}

areas.factions_available = minetest.global_exists("factions")

areas.adminPrivs = {areas=true}
areas.startTime = os.clock()

Expand Down
1 change: 1 addition & 0 deletions mod.conf
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
name = areas
optional_depends = playerfactions

0 comments on commit 9f09e23

Please sign in to comment.