----------------------------------- -- func: send ( ') end local function getBytePos(s, needle) for i = 1, string.len(s), 1 do if string.byte(s, i) == needle then return i end end return nil end ----------------------------------- -- func: onTrigger -- desc: Called when this command is invoked. ----------------------------------- commandObj.onTrigger = function(player, bytes) local x = 0 local y = 0 local z = 0 local rot = 0 local zone if bytes == nil then error(player, 'You must provide the name of a player to send and a destination.') return end bytes = string.sub(bytes, 6) local atpos = getBytePos(bytes, 253) local sppos = getBytePos(bytes, 32) -- validate player to send local target local targ if sppos == nil then error(player, 'You must provide the name of a player to send and a destination.') return else target = string.sub(bytes, 1, sppos-1) targ = GetPlayerByName(target) if targ == nil then error(player, string.format('Player named "%s" not found!', target)) return end end -- validate destination if atpos ~= nil then -- destination is an auto-translate phrase local groupId = string.byte(bytes, atpos + 3) local messageId = string.byte(bytes, atpos + 4) for k, v in pairs(zoneList) do if v[1] == groupId and v[2] == messageId then x = v[4] or 0 y = v[5] or 0 z = v[6] or 0 rot = 0 zone = v[3] break end end if zone == nil then error(player, 'Auto-translated phrase is not a zone.') return end else local dest = string.sub(bytes, sppos + 1) if tonumber(dest) ~= nil then -- destination is a zone ID. zone = tonumber(dest) if zone < 0 or zone >= xi.zone.MAX_ZONE then error(player, 'Invalid zone ID.') return end for k, v in pairs(zoneList) do if v[3] == zone then x = v[4] or 0 y = v[5] or 0 z = v[6] or 0 rot = 0 zone = v[3] break end end else -- destination is a player name. target = dest local playerObj = GetPlayerByName(dest) if playerObj == nil then error(player, string.format('Player named "%s" not found!', target)) return end x = playerObj:getXPos() y = playerObj:getYPos() z = playerObj:getZPos() rot = playerObj:getRotPos() zone = playerObj:getZoneID() end end -- send target to destination targ:setPos(x, y, z, rot, zone) if targ:getID() ~= player:getID() then player:printToPlayer(string.format('Sent %s to zone %i.', targ:getName(), zone)) end end return commandObj