mirror of
https://notabug.org/TenPlus1/protector.git
synced 2025-01-10 03:17:34 +01:00
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.
|
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
|
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)
|
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
|
Lucky Blocks: 6
|
||||||
|
|
||||||
|
35
tool.lua
35
tool.lua
@ -2,26 +2,23 @@
|
|||||||
-- protector placement tool (thanks to Shara for code and idea)
|
-- protector placement tool (thanks to Shara for code and idea)
|
||||||
|
|
||||||
minetest.register_craftitem("protector:tool", {
|
minetest.register_craftitem("protector:tool", {
|
||||||
description = "Protector Placer Tool (stand on protector, face direction and use)",
|
description = "Protector Placer Tool (stand near protector, face direction and use)",
|
||||||
inventory_image = "protector_display.png",
|
inventory_image = "protector_display.png^protector_logo.png",
|
||||||
stack_max = 1,
|
stack_max = 1,
|
||||||
|
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
|
|
||||||
local name = user:get_player_name()
|
local name = user:get_player_name()
|
||||||
|
|
||||||
-- check node player occupies
|
-- check for protector near player (2 block radius)
|
||||||
local pos = user:getpos()
|
local pos = user:getpos()
|
||||||
local nod = minetest.get_node(pos).name
|
local pp = minetest.find_nodes_in_area(
|
||||||
if nod ~= "protector:protect2" then
|
vector.subtract(pos, 2), vector.add(pos, 2),
|
||||||
-- check node under player
|
{"protector:protect", "protector:protect2"})
|
||||||
pos.y = pos.y - 1
|
|
||||||
nod = minetest.get_node(pos).name
|
if #pp == 0 then return end -- none found
|
||||||
if nod ~= "protector:protect"
|
|
||||||
and nod ~= "protector:protect2" then
|
pos = pp[1] -- take position of first protector found
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- get members on protector
|
-- get members on protector
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
@ -68,6 +65,7 @@ minetest.register_craftitem("protector:tool", {
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- do we have protectors to use ?
|
-- do we have protectors to use ?
|
||||||
|
local nod
|
||||||
local inv = user:get_inventory()
|
local inv = user:get_inventory()
|
||||||
|
|
||||||
if not inv:contains_item("main", "protector:protect")
|
if not inv:contains_item("main", "protector:protect")
|
||||||
@ -76,11 +74,16 @@ minetest.register_craftitem("protector:tool", {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- take protector
|
-- take protector (block first then logo)
|
||||||
if inv:contains_item("main", "protector:protect") then
|
if inv:contains_item("main", "protector:protect") then
|
||||||
|
|
||||||
inv:remove_item("main", "protector:protect")
|
inv:remove_item("main", "protector:protect")
|
||||||
|
nod = "protector:protect"
|
||||||
|
|
||||||
elseif inv:contains_item("main", "protector:protect2") then
|
elseif inv:contains_item("main", "protector:protect2") then
|
||||||
|
|
||||||
inv:remove_item("main", "protector:protect2")
|
inv:remove_item("main", "protector:protect2")
|
||||||
|
nod = "protector:protect2"
|
||||||
end
|
end
|
||||||
|
|
||||||
-- place protector
|
-- place protector
|
||||||
@ -88,6 +91,7 @@ minetest.register_craftitem("protector:tool", {
|
|||||||
|
|
||||||
-- set protector metadata
|
-- set protector metadata
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
|
||||||
meta:set_string("owner", name)
|
meta:set_string("owner", name)
|
||||||
meta:set_string("infotext", "Protection (owned by " .. name .. ")")
|
meta:set_string("infotext", "Protection (owned by " .. name .. ")")
|
||||||
|
|
||||||
@ -98,6 +102,9 @@ minetest.register_craftitem("protector:tool", {
|
|||||||
meta:set_string("members", "")
|
meta:set_string("members", "")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
minetest.chat_send_player(name,
|
||||||
|
"Protector placed at " .. minetest.pos_to_string(pos))
|
||||||
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user