protector tool updated, stand near protector (2 block radius) to work
This commit is contained in:
parent
38341294e7
commit
965ac2eaa5
|
@ -48,6 +48,7 @@ Change log:
|
|||
Protectors and chest cannot be moved by mesecon pistons or machines.
|
||||
2.1 - Added 'protector_night_pvp' setting so night-time becomes a free for all and
|
||||
players can hurt one another even inside protected areas (not spawn protected)
|
||||
2.2 - Updated protector tool so that player only needs to stand nearby (2 block radius)
|
||||
|
||||
Lucky Blocks: 6
|
||||
|
||||
|
|
35
tool.lua
35
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,
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue