From c409f445d6c9f06f80c3fba1bbac7736db91755b Mon Sep 17 00:00:00 2001 From: TenPlus1 Date: Wed, 19 Aug 2015 11:34:19 +0100 Subject: [PATCH] Added spawn protection from pvp using protector_pvp_spawn setting in minetest.conf --- README.md | 3 ++- init.lua | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index eff8813..e2835f0 100644 --- a/README.md +++ b/README.md @@ -16,4 +16,5 @@ Released under WTFPL 0.8 - Updated to work with Minetest 0.4.12, simplified textures 0.9 - Tweaked code 1.0 - Only owner can remove protector -1.1 - PVP can be disabled for player inside their own protected area using protector_pvp in minetest.conf (requires Minetest 0.4.12 dev and above) \ No newline at end of file +1.1 - Set protector_pvp to true in minetest.conf to disable pvp in player's own area + also setting protector_pvp_spawn will disable pvp in spawn area up to a radius of n blocks \ No newline at end of file diff --git a/init.lua b/init.lua index 31d37ba..e1b70ba 100644 --- a/init.lua +++ b/init.lua @@ -1,9 +1,13 @@ minetest.register_privilege("delprotect","Ignore player protection") +-- get static spawn position +local statspawn = (minetest.setting_get_pos("static_spawnpoint") or {x = 0, y = 2, z = 0}) + protector = {} protector.mod = "redo" protector.radius = (tonumber(minetest.setting_get("protector_radius")) or 5) protector.pvp = minetest.setting_get("protector_pvp") or false +protector.spawn = (tonumber(minetest.setting_get("protector_pvp_spawn")) or 0) protector.get_member_list = function(meta) return meta:get_string("members"):split(" ") @@ -713,7 +717,18 @@ if minetest.setting_getbool("enable_pvp") and protector.pvp == "true" then return false end - if minetest.is_protected(player:getpos(), hitter:get_player_name()) then + -- no pvp at spawn area + local pos = player:getpos() + if pos.x < statspawn.x + protector.spawn + and pos.x > statspawn.x - protector.spawn + and pos.y < statspawn.y + protector.spawn + and pos.y > statspawn.y - protector.spawn + and pos.z < statspawn.z + protector.spawn + and pos.z > statspawn.z - protector.spawn then + return true + end + + if minetest.is_protected(pos, hitter:get_player_name()) then return true else return false