summaryrefslogtreecommitdiff
path: root/init.lua
diff options
context:
space:
mode:
Diffstat (limited to 'init.lua')
-rwxr-xr-x[-rw-r--r--]init.lua61
1 files changed, 46 insertions, 15 deletions
diff --git a/init.lua b/init.lua
index 8068154..8864b52 100644..100755
--- a/init.lua
+++ b/init.lua
@@ -1,10 +1,16 @@
-- pvp_areas
--- Copyright 2016 James Stevenson (everamzah)
+-- Original : Copyright 2016 James Stevenson (everamzah)
+-- Additional : Copyright Tai Kedzierski (DuCake)
-- LGPL v2.1+
local pvp_areas_worlddir = minetest.get_worldpath()
local pvp_areas_modname = minetest.get_current_modname()
+local hasareasmod = minetest.get_modpath("areas")
+
+local safemode = minetest.setting_getbool("pvp_areas.safemode") or false
+local area_label = minetest.setting_get("pvp_areas.label") or "Defined area."
+
local pvp_areas_store = AreaStore()
pvp_areas_store:from_file(pvp_areas_worlddir .. "/pvp_areas_store.dat")
@@ -28,6 +34,13 @@ local function save_pvp_areas()
pvp_areas_store:to_file(pvp_areas_worlddir .. "/pvp_areas_store.dat")
end
+local function areas_entity(pos,num)
+ if hasareasmod then
+ local obj = minetest.add_entity(pos, "areas:pos"..tostring(num))
+ local ent = obj:get_luaentity()
+ ent.active = true
+ end
+end
-- Register privilege and chat command.
minetest.register_privilege("pvp_areas_admin", "Can set and remove PvP areas.")
@@ -93,26 +106,44 @@ minetest.register_chatcommand("pvp_areas", {
end
})
+local KILL_NO = true
+local KILL_OK = false
+
+local AREA_ACTIVATE = KILL_OK
+local AREA_NOACTIVATE = KILL_NO
+
+if safemode then
+ AREA_ACTIVATE = KILL_NO
+ AREA_NOACTIVATE = KILL_OK
+end
+
-- Register punchplayer callback.
minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage)
- if damage < 1 then
- return false
- end
-
for k, v in pairs(pvp_areas_store:get_areas_for_pos(player:getpos())) do
if k then
- if pvp_default then
- return true
- else
- return false
- end
+ return KILL_NO
end
end
+ return KILL_OK
+end)
+
+if hasareasmod then
+ if areas.registerHudHandler then
+
+ local function advertise_nokillzone(pos, list)
+ for k, v in pairs(pvp_areas_store:get_areas_for_pos(pos)) do
+ if k then
+ table.insert(list, {
+ id = "PvP Control Area "..tostring(k),
+ name = area_label,
+ } )
+ return
+ end
+ end
+ end
- -- player is not in a pvp_areas_store area.
- if pvp_default then
- return false
+ areas:registerHudHandler(advertise_nokillzone)
else
- return true
+ minetest.log("info","Your version of `areas` does not support registering hud handlers.")
end
-end)
+end