• 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!

Lua NPC travel without speaking yes

VitorElias12

New Member
Joined
Jul 30, 2017
Messages
17
Reaction score
1
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)



-- OTServ event handling functions start
function onCreatureAppear(cid) npcHandler:eek:nCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:eek:nCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:eek:nCreatureSay(cid, type, msg) end
function onThink() npcHandler:eek:nThink() end
-- OTServ event handling functions end



-- Don't forget npcHandler = npcHandler in the parameters. It is required for all StdModule functions!
local travelNode = keywordHandler:addKeyword({'old city'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to go to Old City in exchange for 400 gps?'})
travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = false, level = 0, cost = 400, destination = {x=211, y=1016, z=6} })
travelNode:addChildKeyword({'sim'}, StdModule.travel, {npcHandler = npcHandler, premium = false, level = 0, cost = 400, destination = {x=211, y=1016, z=6} })




-- Makes sure the npc reacts when you say hi, bye etc.
npcHandler:addModule(FocusModule:new())




if possible I wanted the player to travel without saying 'yes' player just say the name of the city 'old city' and already travel directly
 
Untitled.png
Make sure to display your code properly, to avoid the above issue.

Additionally, please (Support Rule #5) make sure to include your server version, when posting.
---

Onto your issue, you'd want to use the creatureSayCallback function, and when the npc is not focused on the player, check if they are wanting to go somewhere. RL tibia uses/used "bring me to |cityname|"
Lua:
if not npcHandler:isFocused(cid) then
    -- check what they are saying
    return false
end
 
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
-- OTServ event handling functions end

-- Don't forget npcHandler = npcHandler in the parameters. It is required for all StdModule functions!
keywordHandler:addKeyword({"old city"}, StdModule.travel, {npcHandler = npcHandler, premium = false, level = 0, cost = 400, destination = {x = 211, y = 1016, z = 6}})

-- Makes sure the npc reacts when you say hi, bye etc.
npcHandler:addModule(FocusModule:new())
 
Back
Top