local savedPosition = nil local forwardTeleport = MoveEvent() local returnTeleport = MoveEvent() -- Configuración para TP de ida local forwardConfig = { fromPosition = Position(4407, 1346, 7), -- Posición activadora toPosition = Position(3999, 991, 8), -- Destino effect = CONST_ME_TELEPORT, -- Efecto de teletransporte delay = 3000, -- Tiempo de carga (ms) opcode = 125 -- Código de comunicación con OTClient } -- Configuración para TP de vuelta local returnConfig = { fromPositions = { Position(3999, 995, 7), Position(32795, 31248, 7) }, exitPositions = { Position(3999, 996, 8), -- Posición de salida 1 Position(32797, 31247, 7) -- Posición de salida 2 }, delay = 3000, -- Tiempo de carga (ms) opcode = 125 -- Código de comunicación con OTClient } -- Offsets for magic effects local effectOffset = { x = 1, y = 1, z = 0 } -- Standard offset for final (248) effect local disappearOffset = { x = effectOffset.x - 1, y = effectOffset.y - 1, z = effectOffset.z } -- Adjusted offset for effect 244 -- Función de teletransporte de ida function forwardTeleport.onStepIn(creature, item, position, fromPosition) if not creature:isPlayer() then return true end local player = creature:getPlayer() if not player then return true end savedPosition = player:getPosition() print("DEBUG SERVIDOR: Se ha guardado la posición original: " .. tostring(savedPosition)) local success = player:sendExtendedOpcode(forwardConfig.opcode, '{"action": "show_loading"}') if success then print("DEBUG SERVIDOR: Opcode 125 enviado exitosamente a " .. player:getName()) else print("ERROR SERVIDOR: No se pudo enviar opcode 125 a " .. player:getName()) end addEvent(function() if player then if forwardConfig.effect == CONST_ME_TELEPORT then local originalOutfit = player:getOutfit() -- Save current outfit local originalName = player:getName() -- Save current name local pos = player:getPosition() local posOffset = Position(pos.x + disappearOffset.x, pos.y + disappearOffset.y, pos.z + disappearOffset.z) -- Immediately hide the character and its name: posOffset:sendMagicEffect(244) -- Disappear effect at adjusted offset player:setOutfit({lookType = 0}) if player.setName then player:setName("") end -- Hide name -- Teleport the player: player:teleportTo(forwardConfig.toPosition, true) -- After a short delay, play final effect (248) addEvent(function() if player then local newPos = player:getPosition() local newPosOffset = Position(newPos.x + effectOffset.x, newPos.y + effectOffset.y, newPos.z + effectOffset.z) newPosOffset:sendMagicEffect(248) end end, 500) -- Then, after final effect nearly finishes, restore outfit and name: addEvent(function() if player then player:setOutfit(originalOutfit) if player.setName then player:setName(originalName) end end end, 1000) -- Delay increased to ensure invisibility period is hidden addEvent(function() if player then player:sendExtendedOpcode(126, '{"action": "hide_loading"}') print("DEBUG SERVIDOR: Opcode 126 enviado para ocultar loading") end end, 1100) else player:teleportTo(forwardConfig.toPosition, true) player:getPosition():sendMagicEffect(forwardConfig.effect) addEvent(function() if player then player:sendExtendedOpcode(126, '{"action": "hide_loading"}') end end, 500) end end end, forwardConfig.delay) return true end -- Función de teletransporte de regreso function returnTeleport.onStepIn(creature, item, position, fromPosition) if not creature:isPlayer() then return true end local player = creature:getPlayer() if not player then return true end local exits = returnConfig.exitPositions local exitPos = exits[ math.random(#exits) ] print("DEBUG: Regresando a la posición de salida: " .. tostring(exitPos)) player:sendExtendedOpcode(returnConfig.opcode, '{"action": "show_loading"}') addEvent(function() if player then if forwardConfig.effect == CONST_ME_TELEPORT then -- Same condition as forward local originalOutfit = player:getOutfit() local originalName = player:getName() local pos = player:getPosition() local posOffset = Position(pos.x + disappearOffset.x, pos.y + disappearOffset.y, pos.z + disappearOffset.z) posOffset:sendMagicEffect(244) player:setOutfit({lookType = 0}) if player.setName then player:setName("") end player:teleportTo(exitPos, true) addEvent(function() if player then local newPos = player:getPosition() local newPosOffset = Position(newPos.x + effectOffset.x, newPos.y + effectOffset.y, newPos.z + effectOffset.z) newPosOffset:sendMagicEffect(248) end end, 500) addEvent(function() if player then player:setOutfit(originalOutfit) if player.setName then player:setName(originalName) end end end, 1200) addEvent(function() if player then player:sendExtendedOpcode(126, '{"action": "hide_loading"}') end end, 1300) else player:teleportTo(exitPos, true) player:getPosition():sendMagicEffect(returnConfig.effect or CONST_ME_TELEPORT) addEvent(function() if player then player:sendExtendedOpcode(126, '{"action": "hide_loading"}') end end, 500) end savedPosition = nil end end, returnConfig.delay) return true end -- Registrar eventos de teletransporte forwardTeleport:position(forwardConfig.fromPosition) forwardTeleport:register() for _, pos in ipairs(returnConfig.fromPositions) do returnTeleport:position(pos) end returnTeleport:register()