From f5dd6da5635e67e3c44ed3530d19a29a6ee16083 Mon Sep 17 00:00:00 2001 From: TenPlus1 Date: Wed, 20 Jul 2016 16:23:12 +0100 Subject: [PATCH] Added protector_flip bool for .conf settings --- README.md | 4 +++- init.lua | 25 ++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1af3e91..74f8976 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,8 @@ Released under WTFPL 1.7 - Included an edited version of WTFPL doors mod since protected doors didn't work with the doors mod in the latest daily build... Now it's fine :) added support for "protection_bypass" privelage. +1.8 - Added 'protector_flip' setting to stop players using lag to grief into + another players house, it flips them around to stop them digging. Usage: (requires server privelage) @@ -53,4 +55,4 @@ remove all names from list /delprot - Whenever a player is near any protectors with name1 or name2 then it will be -replaced by an air block. \ No newline at end of file +replaced by an air block. diff --git a/init.lua b/init.lua index 3c977b3..3a366c0 100644 --- a/init.lua +++ b/init.lua @@ -5,6 +5,7 @@ protector = {} protector.mod = "redo" protector.radius = (tonumber(minetest.setting_get("protector_radius")) or 5) protector.drop = minetest.setting_getbool("protector_drop") or false +protector.flip = minetest.setting_getbool("protector_flip") or false protector.hurt = (tonumber(minetest.setting_get("protector_hurt")) or 0) -- Intllib @@ -246,6 +247,29 @@ function minetest.is_protected(pos, digger) player:set_hp(player:get_hp() - protector.hurt) end + -- flip player around when protection violated + if protector.flip + and player then + + local pla_pos = player:getpos() + local vec = { + x = pos.x - pla_pos.x, + y = pos.y - pla_pos.y, + z = pos.z - pla_pos.z + } + if vec.x ~= 0 + and vec.z ~= 0 then + + local yaw = math.atan(vec.z / vec.x) + 3 * math.pi / 2 + + if pos.x > pla_pos.x then + yaw = yaw + math.pi + end + + player:set_look_yaw(yaw) + end + end + -- drop tool/item if protection violated if protector.drop == true and player then @@ -270,7 +294,6 @@ function minetest.is_protected(pos, digger) end) end - end return true