Add a better error message when trying to teleport another player without bring privileges

master
LeMagnesium 2014-10-05 17:35:10 +02:00 committed by ShadowNinja
parent 741df993ff
commit b98e8d6da8
1 changed files with 40 additions and 38 deletions

View File

@ -327,44 +327,46 @@ core.register_chatcommand("teleport", {
.. " at "..core.pos_to_string(p) .. " at "..core.pos_to_string(p)
end end
if core.check_player_privs(name, {bring=true}) then if not core.check_player_privs(name, {bring=true}) then
local teleportee = nil return false, "You don't have permission to teleport other players (missing bring privilege)"
local p = {} end
local teleportee_name = nil
teleportee_name, p.x, p.y, p.z = param:match(
"^([^ ]+) +([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
p.x, p.y, p.z = tonumber(p.x), tonumber(p.y), tonumber(p.z)
if teleportee_name then
teleportee = core.get_player_by_name(teleportee_name)
end
if teleportee and p.x and p.y and p.z then
teleportee:setpos(p)
return true, "Teleporting " .. teleportee_name
.. " to " .. core.pos_to_string(p)
end
local teleportee = nil local teleportee = nil
local p = nil local p = {}
local teleportee_name = nil local teleportee_name = nil
local target_name = nil teleportee_name, p.x, p.y, p.z = param:match(
teleportee_name, target_name = string.match(param, "^([^ ]+) +([^ ]+)$") "^([^ ]+) +([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
if teleportee_name then p.x, p.y, p.z = tonumber(p.x), tonumber(p.y), tonumber(p.z)
teleportee = core.get_player_by_name(teleportee_name) if teleportee_name then
end teleportee = core.get_player_by_name(teleportee_name)
if target_name then end
local target = core.get_player_by_name(target_name) if teleportee and p.x and p.y and p.z then
if target then teleportee:setpos(p)
p = target:getpos() return true, "Teleporting " .. teleportee_name
end .. " to " .. core.pos_to_string(p)
end end
if teleportee and p then
p = find_free_position_near(p) local teleportee = nil
teleportee:setpos(p) local p = nil
return true, "Teleporting " .. teleportee_name local teleportee_name = nil
.. " to " .. target_name local target_name = nil
.. " at " .. core.pos_to_string(p) teleportee_name, target_name = string.match(param, "^([^ ]+) +([^ ]+)$")
if teleportee_name then
teleportee = core.get_player_by_name(teleportee_name)
end
if target_name then
local target = core.get_player_by_name(target_name)
if target then
p = target:getpos()
end end
end end
if teleportee and p then
p = find_free_position_near(p)
teleportee:setpos(p)
return true, "Teleporting " .. teleportee_name
.. " to " .. target_name
.. " at " .. core.pos_to_string(p)
end
return false, 'Invalid parameters ("' .. param return false, 'Invalid parameters ("' .. param
.. '") or player not found (see /help teleport)' .. '") or player not found (see /help teleport)'