diff options
| author | TenPlus1 <kinsellaja@yahoo.com> | 2015-12-23 16:24:20 +0000 | 
|---|---|---|
| committer | TenPlus1 <kinsellaja@yahoo.com> | 2015-12-23 16:24:20 +0000 | 
| commit | 693bda3f2cd18ba6adda2eb54c22284e983a9a4d (patch) | |
| tree | e8c1bfc99429b09a25fca3c98847ef8ac9f37d8f | |
| parent | c64a7c84ef7f31512fbc3bcea21cb10324a94ed7 (diff) | |
Added protector_drop and protector_hurt settings to minetest.conf to stop players digging through protected areas
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | init.lua | 29 | 
2 files changed, 29 insertions, 3 deletions
| @@ -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) @@ -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 | 
