summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcheapie <no-email-for-you@example.com>2017-04-03 02:09:51 -0400
committercheapie <no-email-for-you@example.com>2017-04-03 01:09:51 -0500
commit62dcdd85f45385a7fb1a85a7d15a190e4114ba7d (patch)
tree20a5137db74619d85188382e1852b054db7767b9
parentcfc2c779b8d5931558f302d527469afa93f1726a (diff)
downloadareasprotector-62dcdd85f45385a7fb1a85a7d15a190e4114ba7d.tar
areasprotector-62dcdd85f45385a7fb1a85a7d15a190e4114ba7d.tar.gz
areasprotector-62dcdd85f45385a7fb1a85a7d15a190e4114ba7d.tar.bz2
areasprotector-62dcdd85f45385a7fb1a85a7d15a190e4114ba7d.tar.xz
areasprotector-62dcdd85f45385a7fb1a85a7d15a190e4114ba7d.zip
allow sneak+dig to remove the protector (#2)
without removing the area protection it created. In both cases, sneak+dig incurs a deliberate cost, in an effort to prevent a griefer using one protector to go around protecting stuff at random. * In creative mode, one protector is deducted from the player's inventory. * In survival mode, the protector is not returned, and is replaced with 6 steel ingots, unless there's no room for the ingots, then it just behaves as if sneak was not pressed and throws a warning.
-rw-r--r--init.lua35
1 files changed, 28 insertions, 7 deletions
diff --git a/init.lua b/init.lua
index 653f981..370e975 100644
--- a/init.lua
+++ b/init.lua
@@ -1,3 +1,6 @@
+
+local creative_mode = minetest.setting_getbool("creative_mode")
+
local function cyan(str)
return minetest.colorize("#00FFFF",str)
end
@@ -54,13 +57,31 @@ minetest.register_node("areasprotector:protector",{
end
return itemstack
end,
- on_destruct = function(pos)
- local meta = minetest.get_meta(pos)
- local owner = meta:get_string("owner")
- local id = meta:get_int("area_id")
- if areas.areas[id] and areas:isAreaOwner(id,owner) then
- areas:remove(id)
- areas:save()
+ after_dig_node = function(pos, oldnode, oldmetadata, digger)
+ if oldmetadata and oldmetadata.fields then
+ local owner = oldmetadata.fields.owner
+ local id = tonumber(oldmetadata.fields.area_id)
+ local playername = digger:get_player_name()
+ if areas.areas[id] and areas:isAreaOwner(id,owner) then
+ if digger:get_player_control().sneak then
+ local inv = digger:get_inventory()
+ if not creative_mode then
+ if inv:room_for_item("main", "default:steel_ingot 6") then
+ inv:remove_item("main", "areasprotector:protector 1")
+ inv:add_item("main", "default:steel_ingot 6")
+ else
+ minetest.chat_send_player(playername, "No room for the replacement ingots, just digging the protector and deleting the area normally.")
+ areas:remove(id)
+ areas:save()
+ end
+ else
+ inv:remove_item("main", "areasprotector:protector 1")
+ end
+ else
+ areas:remove(id)
+ areas:save()
+ end
+ end
end
end,
on_punch = function(pos, node, puncher)