3371dfcb2b1e8b13028cf64d9073a82f9f57b410
[protector_trans.git] / init.lua
1 -- This small mod transitions the protector_redo mod to the areas.
2 local r = 7
3 minetest.register_abm({
4 nodenames = {"protector:protect", "protector:protect2", "protector:protect_sell"},
5 interval = 8,
6 chance = 1,
7 catch_up = false,
8 action = function(pos, node)
9 local meta = minetest.get_meta(pos)
10 local name = meta:get_string("owner")
11 local pos1 = {x = pos.x - r, y = pos.y - r, z = pos.z - r}
12 local pos2 = {x = pos.x + r, y = pos.y + r, z = pos.z + r}
13 if not (pos1 and pos2) then
14 return false, "You need to select an area first."
15 end
16
17 minetest.log("action", "/protect invoked, owner="..name..
18 " AreaName=".."Converted from protectors"..
19 " StartPos="..minetest.pos_to_string(pos1)..
20 " EndPos=" ..minetest.pos_to_string(pos2))
21 local id = areas:add(name, "Converted from Protectors", pos1, pos2, nil)
22 areas:save()
23 minetest.chat_send_all("Area protected. ID: "..id)
24 minetest.set_node(pos, {name = "markers:stone"})
25 return true
26 end
27 })