Why this no work, help pls thank.
It loads modal window, everything works apart from the actual teleporting of the player.
I may or may not be using some form of robot to assist in making this, and that's more than likely why it isn't working, but maybe a human can troubleshoot what the robot cannot.


Seems to be failing here?
Login.lua
Creaturescripts.xml
Is this due to an order issue?
Thanks!
Solved it, was an issue with on the login.lua not reading the event since it was a double up.
Thanks!
It loads modal window, everything works apart from the actual teleporting of the player.
I may or may not be using some form of robot to assist in making this, and that's more than likely why it isn't working, but maybe a human can troubleshoot what the robot cannot.


LUA:
local destinations = {
-- City Caravans
[1] = {
name = "East Caravan",
position = Position(1124, 1208, 4),
cost = 50,
type = "caravan"
},
[2] = {
name = "West Caravan",
position = Position(2000, 2000, 7),
cost = 50,
type = "caravan"
},
[3] = {
name = "North Caravan",
position = Position(3000, 3000, 7),
cost = 50,
type = "caravan"
},
[4] = {
name = "South Caravan",
position = Position(4000, 4000, 7),
cost = 50,
type = "caravan"
},
-- Outposts
[5] = {
name = "Frosthaven Outpost",
position = Position(1000, 1000, 7),
cost = 80,
type = "outpost",
storageKey = 50001
},
[6] = {
name = "Arabian Sands Outpost",
position = Position(1548, 1408, 7),
cost = 80,
type = "outpost",
storageKey = 50002
},
[7] = {
name = "Magma Plateau Outpost",
position = Position(3000, 3000, 7),
cost = 80,
type = "outpost",
storageKey = 50003
},
[8] = {
name = "TestLocation",
position = Position(4000, 4000, 7),
cost = 80,
type = "outpost",
storageKey = 50004
}
}
-- Function to check if a position is an outpost
local function isOutpostPosition(pos)
for _, dest in pairs(destinations) do
if dest.type == "outpost" and
dest.position.x == pos.x and
dest.position.y == pos.y and
dest.position.z == pos.z then
return dest
end
end
return nil
end
-- Function to create and show the travel window
local function showTravelWindow(player)
local window = ModalWindow(1000, "Travel System", "Select your destination:")
-- Add caravans section
window:addChoice(0, "--- City Caravans ---")
for id, dest in pairs(destinations) do
if dest.type == "caravan" then
window:addChoice(id, string.format("%s (%d gold)", dest.name, dest.cost))
end
end
-- Add outposts section
local hasOutposts = false
for id, dest in pairs(destinations) do
if dest.type == "outpost" and player:getStorageValue(dest.storageKey) == 1 then
if not hasOutposts then
window:addChoice(100, "--- Discovered Outposts ---")
hasOutposts = true
end
window:addChoice(id, string.format("%s (%d gold)", dest.name, dest.cost))
end
end
-- Add buttons
window:addButton(1, "Travel")
window:addButton(2, "Cancel")
-- Set callbacks
window:setDefaultEnterButton(1)
window:setDefaultEscapeButton(2)
-- Send to player
window:sendToPlayer(player)
end
-- Step In event handler
function onStepIn(creature, item, position, fromPosition)
local player = creature:getPlayer()
if not player then
return true
end
-- Check if this is an outpost position
local outpost = isOutpostPosition(position)
if outpost and player:getStorageValue(outpost.storageKey) ~= 1 then
-- Discover the outpost
player:setStorageValue(outpost.storageKey, 1)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("You have discovered the %s! You can now travel here from any caravan.", outpost.name))
return true
end
-- Show travel window
showTravelWindow(player)
return true
end
-- Modal Window event handler
function onModalWindow(player, modalWindowId, buttonId, choiceId)
if modalWindowId ~= 1000 then
return false
end
-- Handle button clicks
if buttonId == 2 then -- Cancel
return true
end
-- Skip section headers
if choiceId == 0 or choiceId == 100 then
return true
end
-- Get selected destination
local destination = destinations[choiceId]
if not destination then
return true
end
-- Check if player has enough money
if player:getMoney() < destination.cost then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("You need %d gold coins for this trip.", destination.cost))
return true
end
-- Remove money and teleport
player:removeMoney(destination.cost)
player:teleportTo(destination.position)
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("Welcome to %s!", destination.name))
return true
end
Seems to be failing here?
LUA:
-- Remove money and teleport
player:removeMoney(destination.cost)
player:teleportTo(destination.position)
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
LUA:
<!-- Outpost Travel System -->
<movevent event="StepIn" itemid="18002" actionid="15100" script="outpost_travel.lua"/>
Login.lua
LUA:
function onLogin(player)
player:registerEvent("TravelWindowHandler")
return true
end
Creaturescripts.xml
LUA:
<event type="modalwindow" name="TravelWindowHandler" script="outpost_travel.lua"/>
Is this due to an order issue?
Thanks!

Post automatically merged:
Solved it, was an issue with on the login.lua not reading the event since it was a double up.
Thanks!

Last edited: