Added protector_drop and protector_hurt settings to minetest.conf to stop players...
authorTenPlus1 <kinsellaja@yahoo.com>
Wed, 23 Dec 2015 16:24:20 +0000 (16:24 +0000)
committerTenPlus1 <kinsellaja@yahoo.com>
Wed, 23 Dec 2015 16:24:20 +0000 (16:24 +0000)
README.md
init.lua

index eadafda..0f1ca26 100644 (file)
--- a/README.md
+++ b/README.md
@@ -31,6 +31,9 @@ Released under WTFPL
       to interface, tweaked and tidied code, added admin command /delprot to remove
       protectors in bulk from banned/old players
 1.5 - Added much requested protected trapdoor
+1.6 - Added protector_drop (true or false) and protector_hurt (hurt by this num)
+      variables to minetest.conf settings to stop players breaking protected
+      areas by dropping tools and hurting player.
 
 Usage: (requires server privelage)
 
index 311a5a4..42257d7 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -3,6 +3,8 @@ minetest.register_privilege("delprotect","Ignore player protection")
 protector = {}
 protector.mod = "redo"
 protector.radius = (tonumber(minetest.setting_get("protector_radius")) or 5)
+protector.drop = minetest.setting_getbool("protector_drop") or false
+protector.hurt = (tonumber(minetest.setting_get("protector_hurt")) or 0)
 
 protector.get_member_list = function(meta)
 
@@ -210,9 +212,30 @@ function minetest.is_protected(pos, digger)
 
        if not protector.can_dig(protector.radius, pos, digger, false, 1) then
 
-               -- hurt player here if required
-               --player = minetest.get_player_by_name(digger)
-               --player:set_hp(player:get_hp() - 2)
+               local player = minetest.get_player_by_name(digger)
+
+               if protector.hurt > 0 then
+                       player:set_hp(player:get_hp() - protector.hurt)
+               end
+
+               if protector.drop == true then
+                       -- drop tool/item if protection violated
+                       local tool = player:get_wielded_item()
+                       local wear = tool:get_wear()
+                       local num = player:get_wield_index()
+                       local player_inv = player:get_inventory()
+                       local inv = player_inv:get_stack("main", num)
+                       local sta = inv:take_item(inv:get_count())
+                       local obj = minetest.add_item(player:getpos(), sta)
+
+                       if obj then
+                               obj:setvelocity({x = 0, y = 5, z = 0})
+                               player:set_wielded_item(nil)
+                               minetest.after(0.1, function()
+                                       player_inv:set_stack("main", num, nil)
+                               end)
+                       end
+               end
 
                return true
        end