+ minetest.chat_send_player(name, "Password cleared")
+ end,
+})
+
+minetest.register_chatcommand("teleport", {
+ params = "<X>,<Y>,<Z> | <to_name> | <name> <X>,<Y>,<Z> | <name> <to_name>",
+ description = "teleport to given position",
+ privs = {teleport=true},
+ func = function(name, param)
+ -- Returns (pos, true) if found, otherwise (pos, false)
+ local function find_free_position_near(pos)
+ local tries = {
+ {x=1,y=0,z=0},
+ {x=-1,y=0,z=0},
+ {x=0,y=0,z=1},
+ {x=0,y=0,z=-1},
+ }
+ for _, d in ipairs(tries) do
+ local p = {x = pos.x+d.x, y = pos.y+d.y, z = pos.z+d.z}
+ local n = minetest.env:get_node(p)
+ if not minetest.registered_nodes[n.name].walkable then
+ return p, true
+ end
+ end
+ return pos, false
+ end
+
+ local teleportee = nil
+ local p = {}
+ p.x, p.y, p.z = string.match(param, "^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
+ teleportee = minetest.env:get_player_by_name(name)
+ if teleportee and p.x and p.y and p.z then
+ minetest.chat_send_player(name, "Teleporting to ("..p.x..", "..p.y..", "..p.z..")")
+ teleportee:setpos(p)
+ return
+ end
+
+ local teleportee = nil
+ local p = nil
+ local target_name = nil
+ target_name = string.match(param, "^([^ ]+)$")
+ teleportee = minetest.env:get_player_by_name(name)
+ if target_name then
+ local target = minetest.env:get_player_by_name(target_name)
+ if target then
+ p = target:getpos()
+ end
+ end
+ if teleportee and p then
+ p = find_free_position_near(p)
+ minetest.chat_send_player(name, "Teleporting to "..target_name.." at ("..p.x..", "..p.y..", "..p.z..")")
+ teleportee:setpos(p)
+ return
+ end
+
+ if minetest.check_player_privs(name, {bring=true}) then
+ local teleportee = nil
+ local p = {}
+ local teleportee_name = nil
+ teleportee_name, p.x, p.y, p.z = string.match(param, "^([^ ]+) +([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
+ if teleportee_name then
+ teleportee = minetest.env:get_player_by_name(teleportee_name)
+ end
+ if teleportee and p.x and p.y and p.z then
+ minetest.chat_send_player(name, "Teleporting "..teleportee_name.." to ("..p.x..", "..p.y..", "..p.z..")")
+ teleportee:setpos(p)
+ return
+ end
+
+ local teleportee = nil
+ local p = nil
+ local teleportee_name = nil
+ local target_name = nil
+ teleportee_name, target_name = string.match(param, "^([^ ]+) +([^ ]+)$")
+ if teleportee_name then
+ teleportee = minetest.env:get_player_by_name(teleportee_name)
+ end
+ if target_name then
+ local target = minetest.env:get_player_by_name(target_name)
+ if target then
+ p = target:getpos()
+ end
+ end
+ if teleportee and p then
+ p = find_free_position_near(p)
+ minetest.chat_send_player(name, "Teleporting "..teleportee_name.." to "..target_name.." at ("..p.x..", "..p.y..", "..p.z..")")
+ teleportee:setpos(p)
+ return
+ end
+ end
+
+ minetest.chat_send_player(name, "Invalid parameters (\""..param.."\") or player not found (see /help teleport)")
+ return