diff --git a/README.md b/README.md index eadafda..0f1ca26 100644 --- 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) diff --git a/init.lua b/init.lua index 311a5a4..42257d7 100644 --- 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