Additional checks for tool drop
This commit is contained in:
parent
693bda3f2c
commit
0679ada27d
1 changed files with 6 additions and 4 deletions
10
init.lua
10
init.lua
|
|
@ -214,14 +214,16 @@ function minetest.is_protected(pos, digger)
|
||||||
|
|
||||||
local player = minetest.get_player_by_name(digger)
|
local player = minetest.get_player_by_name(digger)
|
||||||
|
|
||||||
if protector.hurt > 0 then
|
if protector.hurt > 0
|
||||||
|
and player then
|
||||||
player:set_hp(player:get_hp() - protector.hurt)
|
player:set_hp(player:get_hp() - protector.hurt)
|
||||||
end
|
end
|
||||||
|
|
||||||
if protector.drop == true then
|
if protector.drop == true
|
||||||
|
and player then
|
||||||
-- drop tool/item if protection violated
|
-- drop tool/item if protection violated
|
||||||
local tool = player:get_wielded_item()
|
local tool = player:get_wielded_item()
|
||||||
local wear = tool:get_wear()
|
--local wear = tool:get_wear()
|
||||||
local num = player:get_wield_index()
|
local num = player:get_wield_index()
|
||||||
local player_inv = player:get_inventory()
|
local player_inv = player:get_inventory()
|
||||||
local inv = player_inv:get_stack("main", num)
|
local inv = player_inv:get_stack("main", num)
|
||||||
|
|
@ -231,7 +233,7 @@ function minetest.is_protected(pos, digger)
|
||||||
if obj then
|
if obj then
|
||||||
obj:setvelocity({x = 0, y = 5, z = 0})
|
obj:setvelocity({x = 0, y = 5, z = 0})
|
||||||
player:set_wielded_item(nil)
|
player:set_wielded_item(nil)
|
||||||
minetest.after(0.1, function()
|
minetest.after(0.2, function()
|
||||||
player_inv:set_stack("main", num, nil)
|
player_inv:set_stack("main", num, nil)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue