1local savedPosition = nil
2
3local forwardTeleport = MoveEvent()
4local returnTeleport = MoveEvent()
5
6-- Configuración para TP de ida
7local forwardConfig = {
8 fromPosition = Position(4407, 1346, 7), -- Posición activadora
9 toPosition = Position(3999, 991, 8), -- Destino
10 effect = CONST_ME_TELEPORT, -- Efecto de teletransporte
11 delay = 3000, -- Tiempo de carga (ms)
12 opcode = 125 -- Código de comunicación con OTClient
13}
14
15-- Configuración para TP de vuelta
16local returnConfig = {
17 fromPositions = {
18 Position(3999, 995, 7),
19 Position(32795, 31248, 7)
20 },
21 exitPositions = {
22 Position(3999, 996, 8), -- Posición de salida 1
23 Position(32797, 31247, 7) -- Posición de salida 2
24 },
25 delay = 3000, -- Tiempo de carga (ms)
26 opcode = 125 -- Código de comunicación con OTClient
27}
28
29-- Offsets for magic effects
30local effectOffset = { x = 1, y = 1, z = 0 } -- Standard offset for final (248) effect
31local disappearOffset = { x = effectOffset.x - 1, y = effectOffset.y - 1, z = effectOffset.z } -- Adjusted offset for effect 244
32
33-- Función de teletransporte de ida
34function forwardTeleport.onStepIn(creature, item, position, fromPosition)
35 if not creature:isPlayer() then return true end
36 local player = creature:getPlayer()
37 if not player then return true end
38
39 savedPosition = player:getPosition()
40 print("DEBUG SERVIDOR: Se ha guardado la posición original: " .. tostring(savedPosition))
41
42 local success = player:sendExtendedOpcode(forwardConfig.opcode, '{"action": "show_loading"}')
43 if success then
44 print("DEBUG SERVIDOR: Opcode 125 enviado exitosamente a " .. player:getName())
45 else
46 print("ERROR SERVIDOR: No se pudo enviar opcode 125 a " .. player:getName())
47 end
48
49 addEvent(function()
50 if player then
51 if forwardConfig.effect == CONST_ME_TELEPORT then
52 local originalOutfit = player:getOutfit() -- Save current outfit
53 local originalName = player:getName() -- Save current name
54 local pos = player:getPosition()
55 local posOffset = Position(pos.x + disappearOffset.x, pos.y + disappearOffset.y, pos.z + disappearOffset.z)
56 -- Immediately hide the character and its name:
57 posOffset:sendMagicEffect(244) -- Disappear effect at adjusted offset
58 player:setOutfit({lookType = 0})
59 if player.setName then player:setName("") end -- Hide name
60 -- Teleport the player:
61 player:teleportTo(forwardConfig.toPosition, true)
62 -- After a short delay, play final effect (248)
63 addEvent(function()
64 if player then
65 local newPos = player:getPosition()
66 local newPosOffset = Position(newPos.x + effectOffset.x, newPos.y + effectOffset.y, newPos.z + effectOffset.z)
67 newPosOffset:sendMagicEffect(248)
68 end
69 end, 500)
70 -- Then, after final effect nearly finishes, restore outfit and name:
71 addEvent(function()
72 if player then
73 player:setOutfit(originalOutfit)
74 if player.setName then player:setName(originalName) end
75 end
76 end, 1000) -- Delay increased to ensure invisibility period is hidden
77 addEvent(function()
78 if player then
79 player:sendExtendedOpcode(126, '{"action": "hide_loading"}')
80 print("DEBUG SERVIDOR: Opcode 126 enviado para ocultar loading")
81 end
82 end, 1100)
83 else
84 player:teleportTo(forwardConfig.toPosition, true)
85 player:getPosition():sendMagicEffect(forwardConfig.effect)
86 addEvent(function()
87 if player then
88 player:sendExtendedOpcode(126, '{"action": "hide_loading"}')
89 end
90 end, 500)
91 end
92 end
93 end, forwardConfig.delay)
94 return true
95end
96
97-- Función de teletransporte de regreso
98function returnTeleport.onStepIn(creature, item, position, fromPosition)
99 if not creature:isPlayer() then return true end
100 local player = creature:getPlayer()
101 if not player then return true end
102 local exits = returnConfig.exitPositions
103 local exitPos = exits[ math.random(#exits) ]
104 print("DEBUG: Regresando a la posición de salida: " .. tostring(exitPos))
105 player:sendExtendedOpcode(returnConfig.opcode, '{"action": "show_loading"}')
106
107 addEvent(function()
108 if player then
109 if forwardConfig.effect == CONST_ME_TELEPORT then -- Same condition as forward
110 local originalOutfit = player:getOutfit()
111 local originalName = player:getName()
112 local pos = player:getPosition()
113 local posOffset = Position(pos.x + disappearOffset.x, pos.y + disappearOffset.y, pos.z + disappearOffset.z)
114 posOffset:sendMagicEffect(244)
115 player:setOutfit({lookType = 0})
116 if player.setName then player:setName("") end
117 player:teleportTo(exitPos, true)
118 addEvent(function()
119 if player then
120 local newPos = player:getPosition()
121 local newPosOffset = Position(newPos.x + effectOffset.x, newPos.y + effectOffset.y, newPos.z + effectOffset.z)
122 newPosOffset:sendMagicEffect(248)
123 end
124 end, 500)
125 addEvent(function()
126 if player then
127 player:setOutfit(originalOutfit)
128 if player.setName then player:setName(originalName) end
129 end
130 end, 1200)
131 addEvent(function()
132 if player then
133 player:sendExtendedOpcode(126, '{"action": "hide_loading"}')
134 end
135 end, 1300)
136 else
137 player:teleportTo(exitPos, true)
138 player:getPosition():sendMagicEffect(returnConfig.effect or CONST_ME_TELEPORT)
139 addEvent(function()
140 if player then
141 player:sendExtendedOpcode(126, '{"action": "hide_loading"}')
142 end
143 end, 500)
144 end
145 savedPosition = nil
146 end
147 end, returnConfig.delay)
148 return true
149end
150
151-- Registrar eventos de teletransporte
152forwardTeleport:position(forwardConfig.fromPosition)
153forwardTeleport:register()
154
155for _, pos in ipairs(returnConfig.fromPositions) do
156 returnTeleport:position(pos)
157end
158returnTeleport:register()