summaryrefslogtreecommitdiff
path: root/tool.lua
diff options
context:
space:
mode:
authorTenPlus1 <kinsellaja@yahoo.com>2017-07-03 09:31:42 +0100
committerTenPlus1 <kinsellaja@yahoo.com>2017-07-03 09:31:42 +0100
commit965ac2eaa5ab7f0711a617c4144a760e391c3000 (patch)
treecbb08355c1e22bc7a4ffa206c1baa24bea015ce4 /tool.lua
parent38341294e786634b61af978be3c37deff6489fb5 (diff)
protector tool updated, stand near protector (2 block radius) to work
Diffstat (limited to 'tool.lua')
-rw-r--r--tool.lua35
1 files changed, 21 insertions, 14 deletions
diff --git a/tool.lua b/tool.lua
index 839112d..9c315ae 100644
--- a/tool.lua
+++ b/tool.lua
@@ -2,26 +2,23 @@
-- protector placement tool (thanks to Shara for code and idea)
minetest.register_craftitem("protector:tool", {
- description = "Protector Placer Tool (stand on protector, face direction and use)",
- inventory_image = "protector_display.png",
+ description = "Protector Placer Tool (stand near protector, face direction and use)",
+ inventory_image = "protector_display.png^protector_logo.png",
stack_max = 1,
on_use = function(itemstack, user, pointed_thing)
local name = user:get_player_name()
- -- check node player occupies
+ -- check for protector near player (2 block radius)
local pos = user:getpos()
- local nod = minetest.get_node(pos).name
- if nod ~= "protector:protect2" then
- -- check node under player
- pos.y = pos.y - 1
- nod = minetest.get_node(pos).name
- if nod ~= "protector:protect"
- and nod ~= "protector:protect2" then
- return
- end
- end
+ local pp = minetest.find_nodes_in_area(
+ vector.subtract(pos, 2), vector.add(pos, 2),
+ {"protector:protect", "protector:protect2"})
+
+ if #pp == 0 then return end -- none found
+
+ pos = pp[1] -- take position of first protector found
-- get members on protector
local meta = minetest.get_meta(pos)
@@ -68,6 +65,7 @@ minetest.register_craftitem("protector:tool", {
end
-- do we have protectors to use ?
+ local nod
local inv = user:get_inventory()
if not inv:contains_item("main", "protector:protect")
@@ -76,11 +74,16 @@ minetest.register_craftitem("protector:tool", {
return
end
- -- take protector
+ -- take protector (block first then logo)
if inv:contains_item("main", "protector:protect") then
+
inv:remove_item("main", "protector:protect")
+ nod = "protector:protect"
+
elseif inv:contains_item("main", "protector:protect2") then
+
inv:remove_item("main", "protector:protect2")
+ nod = "protector:protect2"
end
-- place protector
@@ -88,6 +91,7 @@ minetest.register_craftitem("protector:tool", {
-- set protector metadata
local meta = minetest.get_meta(pos)
+
meta:set_string("owner", name)
meta:set_string("infotext", "Protection (owned by " .. name .. ")")
@@ -98,6 +102,9 @@ minetest.register_craftitem("protector:tool", {
meta:set_string("members", "")
end
+ minetest.chat_send_player(name,
+ "Protector placed at " .. minetest.pos_to_string(pos))
+
end,
})