endziu2222
Well-Known Member
- Joined
- Nov 2, 2010
- Messages
- 196
- Solutions
- 1
- Reaction score
- 57
It works very easy you can use it as aid, uid or id. Once on the tile you will be teleported to chosen location after delay.
Can be also used in quests I assume.
Tested on OTX and Canary.
I also add this one:
2 players have to be together on 2 tiles for teleport to occur.
Can be also used in quests I assume.
Tested on OTX and Canary.
LUA:
local teleportLocations = {
Position(2495, 2853, 7),
Position(2497, 2853, 7)
-- add more positions
}
local teleportDelay = 5
local function delayedTeleport(playerId, originalPosition, locations)
local player = Player(playerId)
if not player or not player:isPlayer() then
return
end
if player:getPosition() == originalPosition then
local randomIndex = math.random(1, #locations)
player:teleportTo(locations[randomIndex])
locations[randomIndex]:sendMagicEffect(CONST_ME_TELEPORT)
end
end
local teleportTeleport = MoveEvent()
function teleportTeleport.onStepIn(creature, item, position, fromPosition)
local player = creature:getPlayer()
if not player then
return true
end
addEvent(delayedTeleport, teleportDelay * 1000, player:getId(), position, teleportLocations)
return true
end
teleportTeleport:type("stepin")
teleportTeleport:aid(24334)
teleportTeleport:register()
I also add this one:
2 players have to be together on 2 tiles for teleport to occur.
LUA:
local teleportLocations = {
Position(2496, 2853, 7),
}
local tilePositions = {
Position(2493, 2853, 7),
Position(2499, 2853, 7)
}
local playersOnTiles = {}
local teleportDelay = 10
local function delayedTeleport(playerId, tileId)
local player = Player(playerId)
if not player or not player:isPlayer() then
return
end
for _, pos in pairs(tilePositions) do
if not playersOnTiles[pos] or playersOnTiles[pos] == 0 then
return
end
end
local randomIndex = math.random(1, #teleportLocations)
for _, pos in pairs(tilePositions) do
local tile = Tile(pos)
if tile then
local creatures = tile:getCreatures()
for _, creature in ipairs(creatures) do
if creature:isPlayer() then
creature:teleportTo(teleportLocations[randomIndex])
teleportLocations[randomIndex]:sendMagicEffect(CONST_ME_TELEPORT)
end
end
end
playersOnTiles[pos] = 0
end
end
local teleportTeleport = MoveEvent()
function teleportTeleport.onStepIn(creature, item, position, fromPosition)
local player = creature:getPlayer()
if not player then
return true
end
for _, tilePos in pairs(tilePositions) do
if position == tilePos then
playersOnTiles[tilePos] = (playersOnTiles[tilePos] or 0) + 1
addEvent(delayedTeleport, teleportDelay * 1000, player:getId(), tilePos)
break
end
end
return true
end
teleportTeleport:type("stepin")
teleportTeleport:aid(24335)
teleportTeleport:register()
Last edited: