• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Canary bring me to function error in console

ForgottenNot

Banned User
Joined
Feb 10, 2023
Messages
303
Reaction score
29
As title says im trying to add this function but im getting error

got this script
Code:
local internalNpcName = "Captain Bluebear"
local npcType = Game.createNpcType(internalNpcName)
local npcConfig = {}


npcConfig.name = internalNpcName
npcConfig.description = internalNpcName


npcConfig.health = 100
npcConfig.maxHealth = npcConfig.health
npcConfig.walkInterval = 2000
npcConfig.walkRadius = 2


npcConfig.outfit = {
    lookType = 129,
    lookHead = 19,
    lookBody = 69,
    lookLegs = 125,
    lookFeet = 50,
    lookAddons = 0,
}


npcConfig.flags = {
    floorchange = false,
}


npcConfig.voices = {
    interval = 15000,
    chance = 50,
    { text = "Passages to Carlin, Ab'Dendriel, Edron, Venore, Port Hope, Liberty Bay, Yalahar, Roshamuul, Krailos, Oramond and Svargrond." },
}


local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)


npcType.onThink = function(npc, interval)
    npcHandler:onThink(npc, interval)
end


npcType.onAppear = function(npc, creature)
    npcHandler:onAppear(npc, creature)
end


npcType.onDisappear = function(npc, creature)
    npcHandler:onDisappear(npc, creature)
end


npcType.onMove = function(npc, creature, fromPosition, toPosition)
    npcHandler:onMove(npc, creature, fromPosition, toPosition)
end


npcType.onSay = function(npc, creature, type, message)
    npcHandler:onSay(npc, creature, type, message)
end


npcType.onCloseChannel = function(npc, creature)
    npcHandler:onCloseChannel(npc, creature)
end
local function addInstantTravel(keywordHandler, destination, cost, position)
    local keywords = {"bring me to " .. destination:lower()}
    keywordHandler:addKeyword(keywords, function(player, message, keywords, parameters, node)
        if player:getBalance() < cost then
            npcHandler:say("I'm sorry, but you don't have enough money to pay for the trip.", npc, player)
            return true
        end
        player:removeMoneyBank(cost)
        player:teleportTo(position)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        npcHandler:say("Have a nice trip!", npc, player)
        return true
    end, {npcHandler = npcHandler})
end


-- Add instant travel options
addInstantTravel(keywordHandler, "Ab'Dendriel", 130, Position(32734, 31668, 6))
addInstantTravel(keywordHandler, "Edron", 160, Position(33175, 31764, 6))
addInstantTravel(keywordHandler, "Venore", 170, Position(32954, 32022, 6))
addInstantTravel(keywordHandler, "Port Hope", 160, Position(32527, 32784, 6))
addInstantTravel(keywordHandler, "Roshamuul", 210, Position(33494, 32567, 7))
addInstantTravel(keywordHandler, "Svargrond", 180, Position(32341, 31108, 6))
addInstantTravel(keywordHandler, "Liberty Bay", 180, Position(32285, 32892, 6))
addInstantTravel(keywordHandler, "Oramond", 150, Position(33479, 31985, 7))
addInstantTravel(keywordHandler, "Krailos", 230, Position(33492, 31712, 6))


-- Special case for Yalahar with condition
keywordHandler:addKeyword({"bring me to yalahar"}, function(player, message, keywords, parameters, node)
    if player:getStorageValue(Storage.SearoutesAroundYalahar.Thais) == 1 or player:getStorageValue(Storage.SearoutesAroundYalahar.TownsCounter) >= 5 then
        npcHandler:say("I'm sorry, but I can't take you to Yalahar at the moment.", npc, player)
        return true
    end
    if player:getBalance() < 200 then
        npcHandler:say("I'm sorry, but you don't have enough money to pay for the trip.", npc, player)
        return true
    end
    player:removeMoneyBank(200)
    player:teleportTo(Position(32816, 31272, 6))
    player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    npcHandler:say("Have a nice trip!", npc, player)
    return true
end, {npcHandler = npcHandler})


-- Travel
local function addTravelKeyword(keyword, cost, destination, action, condition)
    if condition then
        keywordHandler:addKeyword({ keyword }, StdModule.say, { npcHandler = npcHandler, text = "I'm sorry but I don't sail there." }, condition)
    end


    local travelKeyword = keywordHandler:addKeyword({ keyword }, StdModule.say, { npcHandler = npcHandler, text = "Do you seek a passage to " .. keyword:titleCase() .. " for |TRAVELCOST|?", cost = cost, discount = "postman" })
    travelKeyword:addChildKeyword({ "yes" }, StdModule.travel, { npcHandler = npcHandler, premium = false, cost = cost, discount = "postman", destination = destination }, nil, action)
    travelKeyword:addChildKeyword({ "no" }, StdModule.say, { npcHandler = npcHandler, text = "We would like to serve you some time.", reset = true })
end


addTravelKeyword("carlin", 110, Position(32387, 31820, 6), function(player)
    if player:getStorageValue(Storage.Postman.Mission01) == 1 then
        player:setStorageValue(Storage.Postman.Mission01, 2)
    end
end)


addTravelKeyword("ab'dendriel", 130, Position(32734, 31668, 6))
addTravelKeyword("edron", 160, Position(33175, 31764, 6))
addTravelKeyword("venore", 170, Position(32954, 32022, 6))
addTravelKeyword("port hope", 160, Position(32527, 32784, 6))
addTravelKeyword("roshamuul", 210, Position(33494, 32567, 7))
addTravelKeyword("svargrond", 180, Position(32341, 31108, 6))
addTravelKeyword("liberty bay", 180, Position(32285, 32892, 6))
addTravelKeyword("yalahar", 200, Position(32816, 31272, 6), nil, function(player)
    return player:getStorageValue(Storage.SearoutesAroundYalahar.Thais) ~= 1 and player:getStorageValue(Storage.SearoutesAroundYalahar.TownsCounter) < 5
end)
addTravelKeyword("oramond", 150, Position(33479, 31985, 7))
addTravelKeyword("krailos", 230, Position(33492, 31712, 6))


-- Kick
keywordHandler:addKeyword({ "kick" }, StdModule.kick, { npcHandler = npcHandler, destination = { Position(32320, 32219, 6), Position(32321, 32210, 6) } })


-- Basic
keywordHandler:addKeyword({ "name" }, StdModule.say, { npcHandler = npcHandler, text = "My name is Captain Bluebear from the Royal Tibia Line." })
keywordHandler:addKeyword({ "job" }, StdModule.say, { npcHandler = npcHandler, text = "I am the captain of this sailing-ship." })
keywordHandler:addKeyword({ "captain" }, StdModule.say, { npcHandler = npcHandler, text = "I am the captain of this sailing-ship." })
keywordHandler:addKeyword({ "ship" }, StdModule.say, { npcHandler = npcHandler, text = "The Royal Tibia Line connects all seaside towns of Tibia." })
keywordHandler:addKeyword({ "line" }, StdModule.say, { npcHandler = npcHandler, text = "The Royal Tibia Line connects all seaside towns of Tibia." })
keywordHandler:addKeyword({ "company" }, StdModule.say, { npcHandler = npcHandler, text = "The Royal Tibia Line connects all seaside towns of Tibia." })
keywordHandler:addKeyword({ "tibia" }, StdModule.say, { npcHandler = npcHandler, text = "The Royal Tibia Line connects all seaside towns of Tibia." })
keywordHandler:addKeyword({ "good" }, StdModule.say, { npcHandler = npcHandler, text = "We can transport everything you want." })
keywordHandler:addKeyword({ "passenger" }, StdModule.say, { npcHandler = npcHandler, text = "We would like to welcome you on board." })
keywordHandler:addKeyword({ "trip" }, StdModule.say, { npcHandler = npcHandler, text = "Where do you want to go? To {Carlin}, {Ab'Dendriel}, {Venore}, {Port Hope}, {Liberty Bay}, {Svargrond}, {Yalahar}, {Roshamuul}, {Oramond} or {Edron}?" })
keywordHandler:addKeyword({ "route" }, StdModule.say, { npcHandler = npcHandler, text = "Where do you want to go? To {Carlin}, {Ab'Dendriel}, {Venore}, {Port Hope}, {Liberty Bay}, {Svargrond}, {Yalahar}, {Roshamuul}, {Oramond} or {Edron}?" })
keywordHandler:addKeyword({ "passage" }, StdModule.say, { npcHandler = npcHandler, text = "Where do you want to go? To {Carlin}, {Ab'Dendriel}, {Venore}, {Port Hope}, {Liberty Bay}, {Svargrond}, {Yalahar}, {Roshamuul}, {Oramond} or {Edron}?" })
keywordHandler:addKeyword({ "town" }, StdModule.say, { npcHandler = npcHandler, text = "Where do you want to go? To {Carlin}, {Ab'Dendriel}, {Venore}, {Port Hope}, {Liberty Bay}, {Svargrond}, {Yalahar}, {Roshamuul}, {Oramond} or {Edron}?" })
keywordHandler:addKeyword({ "destination" }, StdModule.say, { npcHandler = npcHandler, text = "Where do you want to go? To {Carlin}, {Ab'Dendriel}, {Venore}, {Port Hope}, {Liberty Bay}, {Svargrond}, {Yalahar}, {Roshamuul}, {Oramond} or {Edron}?" })
keywordHandler:addKeyword({ "sail" }, StdModule.say, { npcHandler = npcHandler, text = "Where do you want to go? To {Carlin}, {Ab'Dendriel}, {Venore}, {Port Hope}, {Liberty Bay}, {Svargrond}, {Yalahar}, {Roshamuul}, {Oramond} or {Edron}?" })
keywordHandler:addKeyword({ "go" }, StdModule.say, { npcHandler = npcHandler, text = "Where do you want to go? To {Carlin}, {Ab'Dendriel}, {Venore}, {Port Hope}, {Liberty Bay}, {Svargrond}, {Yalahar}, {Roshamuul}, {Oramond} or {Edron}?" })
keywordHandler:addKeyword({ "ice" }, StdModule.say, { npcHandler = npcHandler, text = "I'm sorry, but we don't serve the routes to the Ice Islands." })
keywordHandler:addKeyword({ "senja" }, StdModule.say, { npcHandler = npcHandler, text = "I'm sorry, but we don't serve the routes to the Ice Islands." })
keywordHandler:addKeyword({ "folda" }, StdModule.say, { npcHandler = npcHandler, text = "I'm sorry, but we don't serve the routes to the Ice Islands." })
keywordHandler:addKeyword({ "vega" }, StdModule.say, { npcHandler = npcHandler, text = "I'm sorry, but we don't serve the routes to the Ice Islands." })
keywordHandler:addKeyword({ "darashia" }, StdModule.say, { npcHandler = npcHandler, text = "I'm not sailing there. This route is afflicted by a ghostship! However I've heard that Captain Fearless from Venore sails there." })
keywordHandler:addKeyword({ "darama" }, StdModule.say, { npcHandler = npcHandler, text = "I'm not sailing there. This route is afflicted by a ghostship! However I've heard that Captain Fearless from Venore sails there." })
keywordHandler:addKeyword({ "ghost" }, StdModule.say, { npcHandler = npcHandler, text = "Many people who sailed to Darashia never returned because they were attacked by a ghostship! I'll never sail there!" })
keywordHandler:addKeyword({ "thais" }, StdModule.say, { npcHandler = npcHandler, text = "This is Thais. Where do you want to go?" })


npcHandler:setMessage(MESSAGE_GREET, "Welcome on board, |PLAYERNAME|. Where can I {sail} you today?")
npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye. Recommend us if you were satisfied with our service.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye then.")


npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true)


-- npcType registering the npcConfig table
npcType:register(npcConfig) i have added this code local function addInstantTravel(keywordHandler, destination, cost, position)
    local keywords = {"bring me to " .. destination:lower()}
    keywordHandler:addKeyword(keywords, function(player, message, keywords, parameters, node)
        if player:getBalance() < cost then
            npcHandler:say("I'm sorry, but you don't have enough money to pay for the trip.", npc, player)
            return true
        end
        player:removeMoneyBank(cost)
        player:teleportTo(position)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        npcHandler:say("Have a nice trip!", npc, player)
        return true
    end, {npcHandler = npcHandler})
end


-- Add instant travel options
addInstantTravel(keywordHandler, "Ab'Dendriel", 130, Position(32734, 31668, 6))
addInstantTravel(keywordHandler, "Edron", 160, Position(33175, 31764, 6))
addInstantTravel(keywordHandler, "Venore", 170, Position(32954, 32022, 6))
addInstantTravel(keywordHandler, "Port Hope", 160, Position(32527, 32784, 6))
addInstantTravel(keywordHandler, "Roshamuul", 210, Position(33494, 32567, 7))
addInstantTravel(keywordHandler, "Svargrond", 180, Position(32341, 31108, 6))
addInstantTravel(keywordHandler, "Liberty Bay", 180, Position(32285, 32892, 6))
addInstantTravel(keywordHandler, "Oramond", 150, Position(33479, 31985, 7))
addInstantTravel(keywordHandler, "Krailos", 230, Position(33492, 31712, 6))


-- Special case for Yalahar with condition
keywordHandler:addKeyword({"bring me to yalahar"}, function(player, message, keywords, parameters, node)
    if player:getStorageValue(Storage.SearoutesAroundYalahar.Thais) == 1 or player:getStorageValue(Storage.SearoutesAroundYalahar.TownsCounter) >= 5 then
        npcHandler:say("I'm sorry, but I can't take you to Yalahar at the moment.", npc, player)
        return true
    end
    if player:getBalance() < 200 then
        npcHandler:say("I'm sorry, but you don't have enough money to pay for the trip.", npc, player)
        return true
    end
    player:removeMoneyBank(200)
    player:teleportTo(Position(32816, 31272, 6))
    player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    npcHandler:say("Have a nice trip!", npc, player)
    return true
end, {npcHandler = npcHandler})
so if player says bring me to (city destination) it wont require to say hi first and confirm the travel would like that if player has the money it will be teleport right away but when i say for example "bring me to venore" got this error in console Interface: Scripts Interface
LUA:
Script ID: C:\Users\felip\Documents\GitHub\canary\data-otservbr-global/npc\captain_bluebear.lua:callback
Error Description: ...Hub\canary\data-otservbr-global/npc\captain_bluebear.lua:61: attempt to call method 'getBalance' (a nil value)
stack traceback:
        [C]: in function 'getBalance'
        ...Hub\canary\data-otservbr-global/npc\captain_bluebear.lua:61: in function 'callback'
        data/npclib/npc_system/keyword_handler.lua:30: in function 'processMessage'
        data/npclib/npc_system/keyword_handler.lua:187: in function 'processNodeMessage'
        data/npclib/npc_system/keyword_handler.lua:152: in function 'processMessage'
        data/npclib/npc_system/npc_handler.lua:448: in function 'onSay'
        ...Hub\canary\data-otservbr-global/npc\captain_bluebear.lua:52: in function <...Hub\canary\data-otservbr-global/npc\captain_bluebear.lua:51>
-----------------------------------
if i say hi, city, yes have no problem the problem is when i say bring me to
can somebody help?
Post automatically merged:

edit okey i have remove the error
but im not being teleported right away when say bring me to i have to say hi first and then confirm the travel i want it to be teleport right away if param bring me to is used
local internalNpcName = "Captain Bluebear"local npcType = Game.createNpcType(i - Pastebin.com (https://pastebin.com/zH92a5QX) < script
 
Last edited:
now i have no errors in console but npc does not teleport me when i use the parameters bring me to
LUA:
local internalNpcName = "Captain Bluebear"
local npcType = Game.createNpcType(internalNpcName)
local npcConfig = {}

npcConfig.name = internalNpcName
npcConfig.description = internalNpcName

npcConfig.health = 100
npcConfig.maxHealth = npcConfig.health
npcConfig.walkInterval = 2000
npcConfig.walkRadius = 2

npcConfig.outfit = {
    lookType = 129,
    lookHead = 19,
    lookBody = 69,
    lookLegs = 125,
    lookFeet = 50,
    lookAddons = 0,
}

npcConfig.flags = {
    floorchange = false,
}

npcConfig.voices = {
    interval = 15000,
    chance = 50,
    { text = "Passages to Carlin, Ab'Dendriel, Edron, Venore, Port Hope, Liberty Bay, Yalahar, Roshamuul, Krailos, Oramond and Svargrond." },
}

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)

npcType.onThink = function(npc, interval)
    npcHandler:onThink(npc, interval)
end

npcType.onAppear = function(npc, creature)
    npcHandler:onAppear(npc, creature)
end

npcType.onDisappear = function(npc, creature)
    npcHandler:onDisappear(npc, creature)
end

npcType.onMove = function(npc, creature, fromPosition, toPosition)
    npcHandler:onMove(npc, creature, fromPosition, toPosition)
end

npcType.onSay = function(npc, creature, type, message)
    npcHandler:onSay(npc, creature, type, message)
end

npcType.onCloseChannel = function(npc, creature)
    npcHandler:onCloseChannel(npc, creature)
end
local function addInstantTravel(keywordHandler, destination, cost, position)
    local keywords = {"bring me to " .. destination:lower()}
    keywordHandler:addKeyword(keywords, function(npc, player, message, keywords, parameters, node)
        if player:isPlayer() then
            return true
        end

        if player:getBankBalance() < cost then
            npcHandler:say("I'm sorry, but you don't have enough money to pay for the trip.", npc, player)
            return true
        end

        player:removeMoneyBank(cost)
        player:teleportTo(position)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        npcHandler:say("Have a nice trip!", npc, player)
        return true
    end, {npcHandler = npcHandler})
end
-- Add instant travel options
-- Add travel options
addInstantTravel(keywordHandler, "Ab'Dendriel", 130, Position(32734, 31668, 6))
addInstantTravel(keywordHandler, "Edron", 160, Position(33175, 31764, 6))
addInstantTravel(keywordHandler, "Venore", 170, Position(32954, 32022, 6))
addInstantTravel(keywordHandler, "Port Hope", 160, Position(32527, 32784, 6))
addInstantTravel(keywordHandler, "Roshamuul", 210, Position(33494, 32567, 7))
addInstantTravel(keywordHandler, "Svargrond", 180, Position(32341, 31108, 6))
addInstantTravel(keywordHandler, "Liberty Bay", 180, Position(32285, 32892, 6))
addInstantTravel(keywordHandler, "Oramond", 150, Position(33479, 31985, 7))
addInstantTravel(keywordHandler, "Krailos", 230, Position(33492, 31712, 6))


-- Special case for Yalahar with condition
addInstantTravel(keywordHandler,"Yalahar", 200, Position(32816, 31272, 6), nil, function(player)
    return player:getStorageValue(Storage.SearoutesAroundYalahar.Thais) ~= 1 and player:getStorageValue(Storage.SearoutesAroundYalahar.TownsCounter) < 5
end)
local function addTravelKeyword(keyword, cost, destination, action, condition)
    if condition then
        keywordHandler:addKeyword({"bring me to " .. keyword:lower()}, StdModule.say, { npcHandler = npcHandler, text = "I'm sorry but I don't sail there." }, condition)
    end

    local travelKeyword = keywordHandler:addKeyword({"bring me to " .. keyword:lower()}, StdModule.say, { npcHandler = npcHandler, text = "Do you seek a passage to " .. keyword:titleCase() .. " for |TRAVELCOST|?", cost = cost, discount = "postman" })
    travelKeyword:addChildKeyword({"yes"}, StdModule.travel, { npcHandler = npcHandler, premium = false, cost = cost, discount = "postman", destination = destination }, nil, action)
    travelKeyword:addChildKeyword({"no"}, StdModule.say, { npcHandler = npcHandler, text = "We would like to serve you some time.", reset = true })
end

addTravelKeyword("carlin", 110, Position(32387, 31820, 6), function(player)
    if player:getStorageValue(Storage.Postman.Mission01) == 1 then
        player:setStorageValue(Storage.Postman.Mission01, 2)
    end
end)

addTravelKeyword("ab'dendriel", 130, Position(32734, 31668, 6))
addTravelKeyword("edron", 160, Position(33175, 31764, 6))
addTravelKeyword("venore", 170, Position(32954, 32022, 6))
addTravelKeyword("port hope", 160, Position(32527, 32784, 6))
addTravelKeyword("roshamuul", 210, Position(33494, 32567, 7))
addTravelKeyword("svargrond", 180, Position(32341, 31108, 6))
addTravelKeyword("liberty bay", 180, Position(32285, 32892, 6))
addTravelKeyword("yalahar", 200, Position(32816, 31272, 6), nil, function(player)
    return player:getStorageValue(Storage.SearoutesAroundYalahar.Thais) ~= 1 and player:getStorageValue(Storage.SearoutesAroundYalahar.TownsCounter) < 5
end)
addTravelKeyword("oramond", 150, Position(33479, 31985, 7))
addTravelKeyword("krailos", 230, Position(33492, 31712, 6))

-- Kick
keywordHandler:addKeyword({ "kick" }, StdModule.kick, { npcHandler = npcHandler, destination = { Position(32320, 32219, 6), Position(32321, 32210, 6) } })

-- Basic
keywordHandler:addKeyword({ "name" }, StdModule.say, { npcHandler = npcHandler, text = "My name is Captain Bluebear from the Royal Tibia Line." })
keywordHandler:addKeyword({ "job" }, StdModule.say, { npcHandler = npcHandler, text = "I am the captain of this sailing-ship." })
keywordHandler:addKeyword({ "captain" }, StdModule.say, { npcHandler = npcHandler, text = "I am the captain of this sailing-ship." })
keywordHandler:addKeyword({ "ship" }, StdModule.say, { npcHandler = npcHandler, text = "The Royal Tibia Line connects all seaside towns of Tibia." })
keywordHandler:addKeyword({ "line" }, StdModule.say, { npcHandler = npcHandler, text = "The Royal Tibia Line connects all seaside towns of Tibia." })
keywordHandler:addKeyword({ "company" }, StdModule.say, { npcHandler = npcHandler, text = "The Royal Tibia Line connects all seaside towns of Tibia." })
keywordHandler:addKeyword({ "tibia" }, StdModule.say, { npcHandler = npcHandler, text = "The Royal Tibia Line connects all seaside towns of Tibia." })
keywordHandler:addKeyword({ "good" }, StdModule.say, { npcHandler = npcHandler, text = "We can transport everything you want." })
keywordHandler:addKeyword({ "passenger" }, StdModule.say, { npcHandler = npcHandler, text = "We would like to welcome you on board." })
keywordHandler:addKeyword({ "trip" }, StdModule.say, { npcHandler = npcHandler, text = "Where do you want to go? To {Carlin}, {Ab'Dendriel}, {Venore}, {Port Hope}, {Liberty Bay}, {Svargrond}, {Yalahar}, {Roshamuul}, {Oramond} or {Edron}?" })
keywordHandler:addKeyword({ "route" }, StdModule.say, { npcHandler = npcHandler, text = "Where do you want to go? To {Carlin}, {Ab'Dendriel}, {Venore}, {Port Hope}, {Liberty Bay}, {Svargrond}, {Yalahar}, {Roshamuul}, {Oramond} or {Edron}?" })
keywordHandler:addKeyword({ "passage" }, StdModule.say, { npcHandler = npcHandler, text = "Where do you want to go? To {Carlin}, {Ab'Dendriel}, {Venore}, {Port Hope}, {Liberty Bay}, {Svargrond}, {Yalahar}, {Roshamuul}, {Oramond} or {Edron}?" })
keywordHandler:addKeyword({ "town" }, StdModule.say, { npcHandler = npcHandler, text = "Where do you want to go? To {Carlin}, {Ab'Dendriel}, {Venore}, {Port Hope}, {Liberty Bay}, {Svargrond}, {Yalahar}, {Roshamuul}, {Oramond} or {Edron}?" })
keywordHandler:addKeyword({ "destination" }, StdModule.say, { npcHandler = npcHandler, text = "Where do you want to go? To {Carlin}, {Ab'Dendriel}, {Venore}, {Port Hope}, {Liberty Bay}, {Svargrond}, {Yalahar}, {Roshamuul}, {Oramond} or {Edron}?" })
keywordHandler:addKeyword({ "sail" }, StdModule.say, { npcHandler = npcHandler, text = "Where do you want to go? To {Carlin}, {Ab'Dendriel}, {Venore}, {Port Hope}, {Liberty Bay}, {Svargrond}, {Yalahar}, {Roshamuul}, {Oramond} or {Edron}?" })
keywordHandler:addKeyword({ "go" }, StdModule.say, { npcHandler = npcHandler, text = "Where do you want to go? To {Carlin}, {Ab'Dendriel}, {Venore}, {Port Hope}, {Liberty Bay}, {Svargrond}, {Yalahar}, {Roshamuul}, {Oramond} or {Edron}?" })
keywordHandler:addKeyword({ "ice" }, StdModule.say, { npcHandler = npcHandler, text = "I'm sorry, but we don't serve the routes to the Ice Islands." })
keywordHandler:addKeyword({ "senja" }, StdModule.say, { npcHandler = npcHandler, text = "I'm sorry, but we don't serve the routes to the Ice Islands." })
keywordHandler:addKeyword({ "folda" }, StdModule.say, { npcHandler = npcHandler, text = "I'm sorry, but we don't serve the routes to the Ice Islands." })
keywordHandler:addKeyword({ "vega" }, StdModule.say, { npcHandler = npcHandler, text = "I'm sorry, but we don't serve the routes to the Ice Islands." })
keywordHandler:addKeyword({ "darashia" }, StdModule.say, { npcHandler = npcHandler, text = "I'm not sailing there. This route is afflicted by a ghostship! However I've heard that Captain Fearless from Venore sails there." })
keywordHandler:addKeyword({ "darama" }, StdModule.say, { npcHandler = npcHandler, text = "I'm not sailing there. This route is afflicted by a ghostship! However I've heard that Captain Fearless from Venore sails there." })
keywordHandler:addKeyword({ "ghost" }, StdModule.say, { npcHandler = npcHandler, text = "Many people who sailed to Darashia never returned because they were attacked by a ghostship! I'll never sail there!" })
keywordHandler:addKeyword({ "thais" }, StdModule.say, { npcHandler = npcHandler, text = "This is Thais. Where do you want to go?" })

npcHandler:setMessage(MESSAGE_GREET, "Welcome on board, |PLAYERNAME|. Where can I {sail} you today?")
npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye. Recommend us if you were satisfied with our service.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye then.")

npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true)

-- npcType registering the npcConfig table
npcType:register(npcConfig)
 
LUA:
local internalNpcName = "Captain Bluebear"
local npcType = Game.createNpcType(internalNpcName)
local npcConfig = {}

npcConfig.name = internalNpcName
npcConfig.description = internalNpcName

npcConfig.health = 100
npcConfig.maxHealth = npcConfig.health
npcConfig.walkInterval = 2000
npcConfig.walkRadius = 2

npcConfig.outfit = {
    lookType = 129,
    lookHead = 19,
    lookBody = 69,
    lookLegs = 125,
    lookFeet = 50,
    lookAddons = 0,
}

npcConfig.flags = {
    floorchange = false,
}

npcConfig.voices = {
    interval = 15000,
    chance = 50,
    { text = "Passages to Carlin, Ab'Dendriel, Edron, Venore, Port Hope, Liberty Bay, Yalahar, Roshamuul, Krailos, Oramond and Svargrond." },
}

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)

npcType.onThink = function(npc, interval)
    npcHandler:onThink(npc, interval)
end

npcType.onAppear = function(npc, creature)
    npcHandler:onAppear(npc, creature)
end

npcType.onDisappear = function(npc, creature)
    npcHandler:onDisappear(npc, creature)
end

npcType.onMove = function(npc, creature, fromPosition, toPosition)
    npcHandler:onMove(npc, creature, fromPosition, toPosition)
end

npcType.onSay = function(npc, creature, type, message)
    npcHandler:onSay(npc, creature, type, message)
end

npcType.onCloseChannel = function(npc, creature)
    npcHandler:onCloseChannel(npc, creature)
end

local function addInstantTravel(keywordHandler, destination, cost, position, action, condition)
    local keywords = {"bring me to " .. destination:lower()}
    keywordHandler:addKeyword(keywords, function(npc, player, message, keywords, parameters, node)
        if player:isPlayer() and (not condition or condition(player)) then
            if player:getBankBalance() < cost then
                npcHandler:say("I'm sorry, but you don't have enough money to pay for the trip.", npc, player)
            else
                player:removeMoneyBank(cost)
                player:teleportTo(position)
                player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
                npcHandler:say("Have a nice trip!", npc, player)
                if action then
                    action(player)
                end
            end
        end
        return true
    end, {npcHandler = npcHandler})
end

-- Add instant travel options
addInstantTravel(keywordHandler, "Ab'Dendriel", 130, Position(32734, 31668, 6))
addInstantTravel(keywordHandler, "Edron", 160, Position(33175, 31764, 6))
addInstantTravel(keywordHandler, "Venore", 170, Position(32954, 32022, 6))
addInstantTravel(keywordHandler, "Port Hope", 160, Position(32527, 32784, 6))
addInstantTravel(keywordHandler, "Roshamuul", 210, Position(33494, 32567, 7))
addInstantTravel(keywordHandler, "Svargrond", 180, Position(32341, 31108, 6))
addInstantTravel(keywordHandler, "Liberty Bay", 180, Position(32285, 32892, 6))
addInstantTravel(keywordHandler, "Oramond", 150, Position(33479, 31985, 7))
addInstantTravel(keywordHandler, "Krailos", 230, Position(33492, 31712, 6))

-- Special case for Yalahar with condition
addInstantTravel(keywordHandler, "Yalahar", 200, Position(32816, 31272, 6), nil, function(player)
    return player:getStorageValue(Storage.SearoutesAroundYalahar.Thais) ~= 1 and player:getStorageValue(Storage.SearoutesAroundYalahar.TownsCounter) < 5
end)

local function addTravelKeyword(keyword, cost, destination, action, condition)
    if condition then
        keywordHandler:addKeyword({"bring me to " .. keyword:lower()}, StdModule.say, { npcHandler = npcHandler, text = "I'm sorry but I don't sail there." }, condition)
    end

    local travelKeyword = keywordHandler:addKeyword({"bring me to " .. keyword:lower()}, StdModule.say, { npcHandler = npcHandler, text = "Do you seek a passage to " .. keyword:titleCase() .. " for |TRAVELCOST|?", cost = cost, discount = "postman" })
    travelKeyword:addChildKeyword({"yes"}, StdModule.travel, { npcHandler = npcHandler, premium = false, cost = cost, discount = "postman", destination = destination }, nil, action)
    travelKeyword:addChildKeyword({"no"}, StdModule.say, { npcHandler = npcHandler, text = "We would like to serve you some time.", reset = true })
end

addTravelKeyword("carlin", 110, Position(32387, 31820, 6), function(player)
    if player:getStorageValue(Storage.Postman.Mission01) == 1 then
        player:setStorageValue(Storage.Postman.Mission01, 2)
    end
end)

addTravelKeyword("ab'dendriel", 130, Position(32734, 31668, 6))
addTravelKeyword("edron", 160, Position(33175, 31764, 6))
addTravelKeyword("venore", 170, Position(32954, 32022, 6))
addTravelKeyword("port hope", 160, Position(32527, 32784, 6))
addTravelKeyword("roshamuul", 210, Position(33494, 32567, 7))
addTravelKeyword("svargrond", 180, Position(32341, 31108, 6))
addTravelKeyword("liberty bay", 180, Position(32285, 32892, 6))
addTravelKeyword("yalahar", 200, Position(32816, 31272, 6), nil, function(player)
    return player:getStorageValue(Storage.SearoutesAroundYalahar.Thais) ~= 1 and player:getStorageValue(Storage.SearoutesAroundYalahar.TownsCounter) < 5
end)
addTravelKeyword("oramond", 150, Position(33479, 31985, 7))
addTravelKeyword("krailos", 230, Position(33492, 31712, 6))

-- Kick
keywordHandler:addKeyword({ "kick" }, StdModule.kick, { npcHandler = npcHandler, destination = { Position(32320, 32219, 6), Position(32321, 32210, 6) } })

-- Basic
keywordHandler:addKeyword({ "name" }, StdModule.say, { npcHandler = npcHandler, text = "My name is Captain Bluebear from the Royal Tibia Line." })
keywordHandler:addKeyword({ "job" }, StdModule.say, { npcHandler = npcHandler, text = "I am the captain of this sailing-ship." })
keywordHandler:addKeyword({ "captain" }, StdModule.say, { npcHandler = npcHandler, text = "I am the captain of this sailing-ship." })
keywordHandler:addKeyword({ "ship" }, StdModule.say, { npcHandler = npcHandler, text = "The Royal Tibia Line connects all seaside towns of Tibia." })
keywordHandler:addKeyword({ "line" }, StdModule.say, { npcHandler = npcHandler, text = "The Royal Tibia Line connects all seaside towns of Tibia." })
keywordHandler:addKeyword({ "company" }, StdModule.say, { npcHandler = npcHandler, text = "The Royal Tibia Line connects all seaside towns of Tibia." })
keywordHandler:addKeyword({ "tibia" }, StdModule.say, { npcHandler = npcHandler, text = "The Royal Tibia Line connects all seaside towns of Tibia." })
keywordHandler:addKeyword({ "good" }, StdModule.say, { npcHandler = npcHandler, text = "We can transport everything you want." })
keywordHandler:addKeyword({ "passenger" }, StdModule.say, { npcHandler = npcHandler, text = "We would like to welcome you on board." })
keywordHandler:addKeyword({ "trip" }, StdModule.say, { npcHandler = npcHandler, text = "Where do you want to go? To {Carlin}, {Ab'Dendriel}, {Venore}, {Port Hope}, {Liberty Bay}, {Svargrond}, {Yalahar}, {Roshamuul}, {Oramond} or {Edron}?" })
keywordHandler:addKeyword({ "route" }, StdModule.say, { npcHandler = npcHandler, text = "Where do you want to go? To {Carlin}, {Ab'Dendriel}, {Venore}, {Port Hope}, {Liberty Bay}, {Svargrond}, {Yalahar}, {Roshamuul},
Post automatically merged:

try
Post automatically merged:

LUA:
local internalNpcName = "Captain Bluebear"
local npcType = Game.createNpcType(internalNpcName)
local npcConfig = {}

npcConfig.name = internalNpcName
npcConfig.description = internalNpcName

npcConfig.health = 100
npcConfig.maxHealth = npcConfig.health
npcConfig.walkInterval = 2000
npcConfig.walkRadius = 2

npcConfig.outfit = {
    lookType = 129,
    lookHead = 19,
    lookBody = 69,
    lookLegs = 125,
    lookFeet = 50,
    lookAddons = 0,
}

npcConfig.flags = {
    floorchange = false,
}

npcConfig.voices = {
    interval = 15000,
    chance = 50,
    { text = "Passages to Carlin, Ab'Dendriel, Edron, Venore, Port Hope, Liberty Bay, Yalahar, Roshamuul, Krailos, Oramond and Svargrond." },
}

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)

npcType.onThink = function(npc, interval)
    npcHandler:onThink(npc, interval)
end

npcType.onAppear = function(npc, creature)
    npcHandler:onAppear(npc, creature)
end

npcType.onDisappear = function(npc, creature)
    npcHandler:onDisappear(npc, creature)
end

npcType.onMove = function(npc, creature, fromPosition, toPosition)
    npcHandler:onMove(npc, creature, fromPosition, toPosition)
end

npcType.onSay = function(npc, creature, type, message)
    npcHandler:onSay(npc, creature, type, message)
end

npcType.onCloseChannel = function(npc, creature)
    npcHandler:onCloseChannel(npc, creature)
end

local function addInstantTravel(keywordHandler, destination, cost, position)
    local keywords = {"bring me to " .. destination:lower()}
    keywordHandler:addKeyword(keywords, function(player, message, keywords, parameters, node)
        if player:getBankBalance() < cost then
            npcHandler:say("I'm sorry, but you don't have enough money to pay for the trip.", npc, player)
            return true
        end
        player:removeMoneyBank(cost)
        player:teleportTo(position)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        npcHandler:say("Have a nice trip!", npc, player)
        return true
    end, {npcHandler = npcHandler})
end

-- Add instant travel options
addInstantTravel(keywordHandler, "Ab'Dendriel", 130, Position(32734, 31668, 6))
addInstantTravel(keywordHandler, "Edron", 160, Position(33175, 31764, 6))
addInstantTravel(keywordHandler, "Venore", 170, Position(32954, 32022, 6))
addInstantTravel(keywordHandler, "Port Hope", 160, Position(32527, 32784, 6))
addInstantTravel(keywordHandler, "Roshamuul", 210, Position(33494, 32567, 7))
addInstantTravel(keywordHandler, "Svargrond", 180, Position(32341, 31108, 6))
addInstantTravel(keywordHandler, "Liberty Bay", 180, Position(32285, 32892, 6))
addInstantTravel(keywordHandler, "Oramond", 150, Position(33479, 31985, 7))
addInstantTravel(keywordHandler, "Krailos", 230, Position(33492, 31712, 6))

-- Special case for Yalahar with condition
keywordHandler:addKeyword({"bring me to yalahar"}, function(player, message, keywords, parameters, node)
    if player:getStorageValue(Storage.SearoutesAroundYalahar.Thais) == 1 or player:getStorageValue(Storage.SearoutesAroundYalahar.TownsCounter) >= 5 then
        npcHandler:say("I'm sorry, but I can't take you to Yalahar at the moment.", npc, player)
        return true
    end
    if player:getBankBalance() < 200 then
        npcHandler:say("I'm sorry, but you don't have enough money to pay for the trip.", npc, player)
        return true
    end
    player:removeMoneyBank(200)
    player:teleportTo(Position(32816, 31272, 6))
    player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    npcHandler:say("Have a nice trip!", npc, player)
    return true
end, {npcHandler = npcHandler})

-- Travel
local function addTravelKeyword(keyword, cost, destination, action, condition)
    if condition then
        keywordHandler:addKeyword({ keyword }, StdModule.say, { npcHandler = npcHandler, text = "I'm sorry but I don't sail there." }, condition)
    end

    local travelKeyword = keywordHandler:addKeyword({ keyword }, StdModule.say, { npcHandler = npcHandler, text = "Do you seek a passage to " .. keyword:titleCase() .. " for |TRAVELCOST|?", cost = cost, discount = "postman" })
    travelKeyword:addChildKeyword({ "yes" }, StdModule.travel, { npcHandler = npcHandler, premium = false, cost = cost, discount = "postman", destination = destination }, nil, action)
    travelKeyword:addChildKeyword({ "no" }, StdModule.say, { npcHandler = npcHandler, text = "We would like to serve you some time.", reset = true })
end

addTravelKeyword("carlin", 110, Position(32387, 31820, 6), function(player)
    if player:getStorageValue(Storage.Postman.Mission01) == 1 then
        player:setStorageValue(Storage.Postman.Mission01, 2)
    end
end)

addTravelKeyword("ab'dendriel", 130, Position(32734, 31668, 6))
addTravelKeyword("edron", 160, Position(33175, 31764, 6))
addTravelKeyword("venore", 170, Position(32954, 32022, 6))
addTravelKeyword("port hope", 160, Position(32527, 32784, 6))
addTravelKeyword("roshamuul", 210, Position(33494, 32567, 7))
addTravelKeyword("svargrond", 180, Position(32341, 31108, 6))
addTravelKeyword("liberty bay", 180, Position(32285, 32892, 6))
addTravelKeyword("yalahar", 200, Position(32816, 31272, 6), nil, function(player)
    return player:getStorageValue(Storage.SearoutesAroundYalahar.Thais) ~= 1 and player:getStorageValue(Storage.SearoutesAroundYalahar.TownsCounter) < 5
end)
addTravelKeyword("oramond", 150, Position(33479, 31985, 7))
addTravelKeyword("krailos", 230, Position(33492, 31712, 6))

-- Kick
keywordHandler:addKeyword({ "kick" }, StdModule.kick, { npcHandler = npcHandler, destination = { Position(32320, 32219, 6), Position(32321, 32210, 6) } })

-- Basic
keywordHandler:addKeyword({ "name" }, StdModule.say, { npcHandler = npcHandler, text = "My name is Captain Bluebear from the Royal Tibia Line." })
keywordHandler:addKeyword({ "job" }, StdModule.say, { npcHandler = npcHandler, text = "I am the captain of this sailing-ship." })
keywordHandler:addKeyword({ "captain" }, StdModule.say, { npcHandler = npcHandler, text = "I am the captain of this sailing-ship." })
keywordHandler:addKeyword({ "ship" }, StdModule.say, { npcHandler = npcHandler, text = "The Royal Tibia Line connects all seaside towns of Tibia." })
keywordHandler:addKeyword({ "line" }, StdModule.say, { npcHandler = npcHandler, text = "The Royal Tibia Line connects all seaside towns of Tibia." })
keywordHandler:addKeyword({ "company" }, StdModule.say, { npcHandler = npcHandler, text = "The Royal Tibia Line connects all seaside towns of Tibia." })
keywordHandler:addKeyword({ "tibia" }, StdModule.say, { npcHandler = npcHandler, text = "The Royal Tibia Line connects all seaside towns of Tibia." })
keywordHandler:addKeyword({ "good" }, StdModule.say, { npcHandler = npcHandler, text = "We can transport everything you want." })
keywordHandler:addKeyword({ "passenger" }, StdModule.say, { npcHandler = npcHandler, text = "We would like to welcome you on board." })
keywordHandler:addKeyword({ "trip" }, StdModule.say, { npcHandler = npcHandler, text = "Where
 
Last edited:
Back
Top