summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTai <dch tai gmail com>2016-12-25 08:58:31 +0000
committerTai <dch tai gmail com>2016-12-25 08:58:31 +0000
commit59d811e8b66dc868f67b950ff9667f667d54e343 (patch)
tree5bd9d37a48fd0ad51d7e6181d98fbe38f077a8ed
parent2243b177b5a8c30051420e0c116b17dc0a0cf731 (diff)
parent88fa3316bf0ab9189a05b1c9d040d00589ffb300 (diff)
Add support for areas hud and toggle settings
-rw-r--r--.gitignore1
-rw-r--r--README.md28
-rwxr-xr-xinit.lua110
-rw-r--r--settingtypes.txt2
4 files changed, 119 insertions, 22 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..1377554
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.swp
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..fc6ffc3
--- /dev/null
+++ b/README.md
@@ -0,0 +1,28 @@
+# PvP Areas
+
+Sets an area for PvP control.
+
+Use safemode to make areas be safe zones; otherwise they are killzones by default.
+
+## Config
+
+* `pvp_areas.safemode`
+ * safemode = true --> PvP Control areas are safe zones
+ * default is `false`, making PvP Control areas kill zones
+
+* `pvp_areas.label`
+ * if ShadowNinja's `areas` mod is also present with HUD registration feature, this label will be displayed anywhere
+ a PvP Control area has been set.
+
+## Commands
+
+* `/pvp_areas`
+ * without arguments lists areas, if any.
+* `/pvp_areas pos1`
+ * selects the players current position as the area minimum.
+* `/pvp_areas pos2`
+ * selects the players current position as the area maximum.
+* `/pvp_areas set`
+ * adds an entry using pos1 and pos2 values.
+* `/pvp_areas remove n`
+ * removes an area entry.
diff --git a/init.lua b/init.lua
index 7e34647..8864b52 100755
--- a/init.lua
+++ b/init.lua
@@ -1,11 +1,46 @@
-- 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 = {}
local pvp_areas_store = AreaStore()
-pvp_areas_store:from_file(minetest.get_worldpath() .. "/pvp_areas_store.dat")
+pvp_areas_store:from_file(pvp_areas_worlddir .. "/pvp_areas_store.dat")
+
+local pvp_default = minetest.is_yes(minetest.setting_getbool("pvp_areas_enable_pvp"))
+minetest.log("action", "[" .. pvp_areas_modname .. "] PvP by Default: " .. tostring(pvp_default))
+
+local pvp_areas_players = {}
+local pvp_areas = {}
+
+local function update_pvp_areas()
+ local counter = 0
+ pvp_areas = {}
+ while pvp_areas_store:get_area(counter) do
+ table.insert(pvp_areas, pvp_areas_store:get_area(counter))
+ counter = counter + 1
+ end
+end
+update_pvp_areas()
+
+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.")
@@ -17,33 +52,56 @@ minetest.register_chatcommand("pvp_areas", {
func = function(name, param)
local pos = vector.round(minetest.get_player_by_name(name):getpos())
if param == "pos1" then
- if not pvp_areas[name] then
- pvp_areas[name] = {pos1 = pos}
+ if not pvp_areas_players[name] then
+ pvp_areas_players[name] = {pos1 = pos}
else
- pvp_areas[name].pos1 = pos
+ pvp_areas_players[name].pos1 = pos
end
minetest.chat_send_player(name, "Position 1: " .. minetest.pos_to_string(pos))
elseif param == "pos2" then
- if not pvp_areas[name] then
- pvp_areas[name] = {pos2 = pos}
+ if not pvp_areas_players[name] then
+ pvp_areas_players[name] = {pos2 = pos}
else
- pvp_areas[name].pos2 = pos
+ pvp_areas_players[name].pos2 = pos
end
minetest.chat_send_player(name, "Position 2: " .. minetest.pos_to_string(pos))
elseif param == "set" then
- if not pvp_areas[name] or not pvp_areas[name].pos1 then
+ if not pvp_areas_players[name] or not pvp_areas_players[name].pos1 then
minetest.chat_send_player(name, "Position 1 missing, use \"/pvp_areas pos1\" to set.")
- elseif not pvp_areas[name].pos2 then
+ elseif not pvp_areas_players[name].pos2 then
minetest.chat_send_player(name, "Position 2 missing, use \"/pvp_areas pos2\" to set.")
else
- minetest.chat_send_player(name, "Setting.")
- pvp_areas_store:insert_area(pvp_areas[name].pos1, pvp_areas[name].pos2, "pvp_areas")
- pvp_areas_store:to_file(minetest.get_worldpath() .. "/pvp_areas_store.dat")
+ pvp_areas_store:insert_area(pvp_areas_players[name].pos1, pvp_areas_players[name].pos2, "pvp_areas", #pvp_areas)
+ table.insert(pvp_areas, pvp_areas_store:get_area(#pvp_areas))
+ update_pvp_areas()
+ save_pvp_areas()
+ pvp_areas_players[name] = nil
+ minetest.chat_send_player(name, "Area set.")
end
- elseif param == "remove" then
- minetest.chat_send_player(name, "Removing.")
- else
+ elseif param:sub(1, 6) == "remove" then
+ local n = tonumber(param:sub(8, -1))
+ if n and pvp_areas_store:get_area(n) then
+ pvp_areas_store:remove_area(n)
+ if pvp_areas_store:get_area(n + 1) then
+ -- Insert last entry in new empty (removed) slot.
+ local a = pvp_areas_store:get_area(#pvp_areas - 1)
+ pvp_areas_store:remove_area(#pvp_areas - 1)
+ pvp_areas_store:insert_area(a.min, a.max, "pvp_areas", n)
+ end
+ update_pvp_areas()
+ save_pvp_areas()
+ minetest.chat_send_player(name, "Removed " .. tostring(n))
+ else
+ minetest.chat_send_player(name, "Invalid argument. You must enter a valid area identifier.")
+ end
+ elseif param ~= "" then
minetest.chat_send_player(name, "Invalid usage. Type \"/help pvp_areas\" for more information.")
+ else
+ for k, v in pairs(pvp_areas) do
+ minetest.chat_send_player(name, k - 1 .. ": " ..
+ minetest.pos_to_string(v.min) .. " " ..
+ minetest.pos_to_string(v.max))
+ end
end
end
})
@@ -51,6 +109,14 @@ minetest.register_chatcommand("pvp_areas", {
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)
for k, v in pairs(pvp_areas_store:get_areas_for_pos(player:getpos())) do
@@ -61,15 +127,15 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch,
return KILL_OK
end)
-if areas then
+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(player:getpos())) do
+ for k, v in pairs(pvp_areas_store:get_areas_for_pos(pos)) do
if k then
- list:insert( {
- id = "pvp_areas:"..tostring(k),
- name = k,
+ table.insert(list, {
+ id = "PvP Control Area "..tostring(k),
+ name = area_label,
} )
return
end
diff --git a/settingtypes.txt b/settingtypes.txt
new file mode 100644
index 0000000..d0c30d5
--- /dev/null
+++ b/settingtypes.txt
@@ -0,0 +1,2 @@
+# Allow PvP by default.
+pvp_areas_enable_pvp (PvP by Default) bool false