Teleport players from a certain area to a new position... Also has the option to teleport offline players.
Usage is simple:
set offlinePlayers to true to enable offline players teleport!!
Usage is simple:
Lua:
doTeleportPlayersFromArea(fromPos, toPos, newPos, offlinePlayers --[[ = false]])
set offlinePlayers to true to enable offline players teleport!!
Lua:
do
-- Function by Colandus!
local validPositionKeys = {"x", "y", "z", "stackpos"}
function isPosition(pos)
local keyAmount = 0
if (type(pos) == "table") then
for key, val in pairs(pos) do
if(not table.find(validPositionKeys, key) or not isNumber(val)) then
return false
end
keyAmount = keyAmount + 1
end
if (keyAmount ~= 3 and keyAmount ~= 4) then
return false
end
return true
end
return false
end
end
function doTeleportPlayersFromArea(fromPos, toPos, newPos, offlinePlayers)
-- Function by Colandus!
if(not (isPosition(fromPos) and isPosition(toPos))) then
return false, error("luaDoTeleportPlayersFromArea: Invalid position!", 2)
end
for _, cid in ipairs(getPlayersOnline()) do
local pos = getCreaturePosition(cid)
if(isInRange(pos, fromPos, toPos)) then
if(getTileInfo(newPos).protection and getCreatureCondition(cid, CONDITION_INFIGHT)) then
doRemoveCondition(cid, CONDITION_INFIGHT)
end
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
doTeleportThing(cid, newPos)
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
end
end
if(offlinePlayers == true) then
db.executeQuery([[
UPDATE players
SET posx = ]].. newPos.x .. [[, posy = ]] .. newPos.y .. [[, posz = ]] .. newPos.z .. [[
WHERE online = 0 AND
posx >= ]] .. fromPos.x .. [[ AND posx <= ]] .. toPos.x .. [[ AND
posy >= ]] .. fromPos.y .. [[ AND posy <= ]] .. toPos.y .. [[ AND
posz >= ]] .. fromPos.z .. [[ AND posz <= ]] .. toPos.z .. [[;
]])
end
return true
end
Last edited: