on_use now inside nodes, code tidy, changed zone display from 10 to 5 seconds
This commit is contained in:
parent
54ab443c57
commit
59d034e88a
|
@ -25,3 +25,5 @@ Released under WTFPL
|
||||||
disable pvp around spawn area with the radius you entered
|
disable pvp around spawn area with the radius you entered
|
||||||
1.2 - Shift and click support added with Minetest 0.4.13 to quickly copy stacks
|
1.2 - Shift and click support added with Minetest 0.4.13 to quickly copy stacks
|
||||||
to and from protected chest
|
to and from protected chest
|
||||||
|
1.3 - Moved protector on_place into node itself, protector zone display changed
|
||||||
|
from 10 to 5 seconds, general code tidy
|
45
init.lua
45
init.lua
|
@ -118,6 +118,7 @@ protector.can_dig = function(r, pos, digger, onlyowner, infolevel)
|
||||||
|
|
||||||
if owner ~= digger then
|
if owner ~= digger then
|
||||||
if onlyowner or not protector.is_member(meta, digger) then
|
if onlyowner or not protector.is_member(meta, digger) then
|
||||||
|
|
||||||
if infolevel == 1 then
|
if infolevel == 1 then
|
||||||
minetest.chat_send_player(digger,
|
minetest.chat_send_player(digger,
|
||||||
"This area is owned by " .. owner .. " !")
|
"This area is owned by " .. owner .. " !")
|
||||||
|
@ -131,6 +132,7 @@ protector.can_dig = function(r, pos, digger, onlyowner, infolevel)
|
||||||
"Members: " .. members .. ".")
|
"Members: " .. members .. ".")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -139,12 +141,13 @@ protector.can_dig = function(r, pos, digger, onlyowner, infolevel)
|
||||||
minetest.chat_send_player(digger,
|
minetest.chat_send_player(digger,
|
||||||
"This area is owned by " .. owner .. ".")
|
"This area is owned by " .. owner .. ".")
|
||||||
minetest.chat_send_player(digger,
|
minetest.chat_send_player(digger,
|
||||||
"Protection located at: " .. minetest.pos_to_string(positions[1]))
|
"Protection located at: " .. minetest.pos_to_string(pos))
|
||||||
if members ~= "" then
|
if members ~= "" then
|
||||||
minetest.chat_send_player(digger,
|
minetest.chat_send_player(digger,
|
||||||
"Members: " .. members .. ".")
|
"Members: " .. members .. ".")
|
||||||
end
|
end
|
||||||
break
|
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -167,36 +170,36 @@ protector.old_is_protected = minetest.is_protected
|
||||||
function minetest.is_protected(pos, digger)
|
function minetest.is_protected(pos, digger)
|
||||||
|
|
||||||
if not protector.can_dig(protector.radius, pos, digger, false, 1) then
|
if not protector.can_dig(protector.radius, pos, digger, false, 1) then
|
||||||
-- hurt here
|
|
||||||
|
-- hurt player here if required
|
||||||
--player = minetest.get_player_by_name(digger)
|
--player = minetest.get_player_by_name(digger)
|
||||||
--player:set_hp(player:get_hp() - 2)
|
--player:set_hp(player:get_hp() - 2)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
return protector.old_is_protected(pos, digger)
|
return protector.old_is_protected(pos, digger)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Make sure protection block doesn't overlap another protector's area
|
-- Make sure protection block doesn't overlap another protector's area
|
||||||
|
|
||||||
protector.old_node_place = minetest.item_place
|
function protector.check_overlap(itemstack, placer, pointed_thing)
|
||||||
|
|
||||||
function minetest.item_place(itemstack, placer, pointed_thing)
|
if pointed_thing.type ~= "node" then
|
||||||
|
return itemstack
|
||||||
if itemstack:get_name() == "protector:protect"
|
|
||||||
or itemstack:get_name() == "protector:protect2" then
|
|
||||||
local user = placer:get_player_name()
|
|
||||||
local pos = pointed_thing.under
|
|
||||||
if not protector.can_dig(protector.radius * 2, pos, user, true, 3) then
|
|
||||||
minetest.chat_send_player(user,
|
|
||||||
"Overlaps into another protected area")
|
|
||||||
return protector.old_node_place(itemstack, placer, pos)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return protector.old_node_place(itemstack, placer, pointed_thing)
|
if not protector.can_dig(protector.radius * 2, pointed_thing.under,
|
||||||
|
placer:get_player_name(), true, 3) then
|
||||||
|
minetest.chat_send_player(placer:get_player_name(),
|
||||||
|
"Overlaps into above players protected area")
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- END
|
return minetest.item_place(itemstack, placer, pointed_thing, param2)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
--= Protection Block
|
--= Protection Block
|
||||||
|
|
||||||
|
@ -221,6 +224,8 @@ minetest.register_node("protector:protect", {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
on_place = protector.check_overlap,
|
||||||
|
|
||||||
after_place_node = function(pos, placer)
|
after_place_node = function(pos, placer)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("owner", placer:get_player_name() or "")
|
meta:set_string("owner", placer:get_player_name() or "")
|
||||||
|
@ -285,6 +290,8 @@ minetest.register_node("protector:protect2", {
|
||||||
},
|
},
|
||||||
selection_box = {type = "wallmounted"},
|
selection_box = {type = "wallmounted"},
|
||||||
|
|
||||||
|
on_place = protector.check_overlap,
|
||||||
|
|
||||||
after_place_node = function(pos, placer)
|
after_place_node = function(pos, placer)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("owner", placer:get_player_name() or "")
|
meta:set_string("owner", placer:get_player_name() or "")
|
||||||
|
@ -327,6 +334,7 @@ minetest.register_craft({
|
||||||
})
|
})
|
||||||
|
|
||||||
-- If name entered or button press
|
-- If name entered or button press
|
||||||
|
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
|
|
||||||
if string.sub(formname, 0, string.len("protector:node_")) == "protector:node_" then
|
if string.sub(formname, 0, string.len("protector:node_")) == "protector:node_" then
|
||||||
|
@ -359,6 +367,8 @@ minetest.register_on_player_receive_fields(function(player,formname,fields)
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- Display entity shown when protector node is punched
|
||||||
|
|
||||||
minetest.register_entity("protector:display", {
|
minetest.register_entity("protector:display", {
|
||||||
physical = false,
|
physical = false,
|
||||||
collisionbox = {0, 0, 0, 0, 0, 0},
|
collisionbox = {0, 0, 0, 0, 0, 0},
|
||||||
|
@ -382,6 +392,7 @@ minetest.register_entity("protector:display", {
|
||||||
|
|
||||||
-- Display-zone node, Do NOT place the display as a node,
|
-- Display-zone node, Do NOT place the display as a node,
|
||||||
-- it is made to be used as an entity (see above)
|
-- it is made to be used as an entity (see above)
|
||||||
|
|
||||||
local x = protector.radius
|
local x = protector.radius
|
||||||
minetest.register_node("protector:display_node", {
|
minetest.register_node("protector:display_node", {
|
||||||
tiles = {"protector_display.png"},
|
tiles = {"protector_display.png"},
|
||||||
|
|
Loading…
Reference in New Issue