• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

[SOLVED] [NPC] Boat Travel with RIGHT Vocation [1.0]

Eldin

Eldin Projects
Joined
Jun 12, 2008
Messages
1,334
Reaction score
615
Location
Sweden
I would like my boat NPC to only allow the right vocations to travel to a city as I work with Races.

This code works and is from my Ab'Dendriel boat NPC making it possible to travel from Ab to Venore.
My problem is that Venore is a Neutral Town, so Humans from Carlin can also travel there.

Right now, none can travel back, it must stay that way UNLESS Humans (Voc 1,2,3,4) allows to only travel to Carlin and Elfs (Voc 5,6,7) allows to get to Ab only. Anyone? :)

The Script:
Code:
local keywordHandler = KeywordHandler:new()
  local npcHandler = NpcHandler:new(keywordHandler)
  NpcSystem.parseParameters(npcHandler)

  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

local travelNode = keywordHandler:addKeyword({'venore'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Would you like to travel to Venore for 100 gold?'})
   travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = true, level = 20, cost = 100, destination = {x=1081, y=1047, z=6} })

   travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Then what are you doing on my ship?'})
  keywordHandler:addKeyword({'sail'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can take you to Venore.'})
keywordHandler:addKeyword({'passage'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can take you to Venore.'})
keywordHandler:addKeyword({'travel'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can take you to Venore.'})
  keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I\'m the captain of this ship!'})
keywordHandler:addKeyword({'captain'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I\'m the captain of this ship!'})

  npcHandler:addModule(FocusModule:new())

Thanks in Advance.

Kind Regards,
Eldin.
 
Hey Eldin, try this out. It's totally untested and I haven't written scripts in long time, but I believe it should work. If it doesn't, post the errors and I can help out :)

(for all advanced scripters out there, I'm aware this could have been done much easier directly via nodes, but I believe this is a better way to learn because functions that are used like this are prone to easier further customization)

Code:
local keywordHandler = KeywordHandler:new()
  local npcHandler = NpcHandler:new(keywordHandler)
  NpcSystem.parseParameters(npcHandler)

  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
 
  local elves = {1,2,3,4} -- IDS of all elf vocations
  local humans = {5,6,7} -- IDs of all human vocations
  local coords1 = {x = 100, y = 100, z = 100} -- Put coordinates of Carlin here
  local coords2 = {x = 100, y = 100, z = 100} -- Put coordinates of Ab'dendriel here
  local price1 = 120 -- Price to travel to Carlin
  local price2 = 120 -- Price to travel to Abdendriel
 
 
-- Function for travelling to Carlin --
function CarlinTrip(cid, message, keywords, parameters, node)

    if(not npcHandler:isFocused(cid)) then
        return false
    end

        if isInArray(humans, getPlayerVocation(cid)) then 
       
                    if getPlayerMoney(cid) >= price1 then
                    doPlayerRemoveMoney(cid, price1)
                    doTeleportThing(cid, coords1, TRUE)
                    doSendMagicEffect(getCreaturePosition(cid),12)
                    npcHandler:say('Here we go, hold on tight!',cid)
                    else
                    npcHandler:say('You don\'t have enough money.',cid)
                    end
       
        else
                    doSendMagicEffect(getCreaturePosition(cid),2)
                    npcHandler:say('Sorry, I can only sail humans there!',cid) 
        end
end
 
-- Function for travelling to Ab'dendriel --
function AbTrip(cid, message, keywords, parameters, node)

    if(not npcHandler:isFocused(cid)) then
        return false
    end

        if isInArray(elves, getPlayerVocation(cid)) then 
       
                    if getPlayerMoney(cid) >= price2 then
                    doPlayerRemoveMoney(cid, price2)
                    doTeleportThing(cid, coords2, TRUE)
                    doSendMagicEffect(getCreaturePosition(cid),14)
                    npcHandler:say('Here we go, hold on tight!',cid)     
                    else
                    npcHandler:say('You don\'t have enough money.',cid)
                    end
        else
                    doSendMagicEffect(getCreaturePosition(cid),2)
                    npcHandler:say('Sorry, I can only sail elves there!',cid) 
        end
end

local node1 = keywordHandler:addKeyword({'ab\'dendriel'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to travel to Ab\'dendriel for xxx gold?'})
    node1:addChildKeyword({'yes'}, AbTrip, {})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'As you wish!', reset = true})

local node2 = keywordHandler:addKeyword({'carlin'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to travel to Carlin for xxx gold?'})
    node2:addChildKeyword({'yes'}, CarlinTrip, {})
    node2:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'As you wish!', reset = true})
       
local travelNode = keywordHandler:addKeyword({'venore'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Would you like to travel to Venore for 100 gold?'})
  travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = true, level = 20, cost = 100, destination = {x=1081, y=1047, z=6} })

  travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Then what are you doing on my ship?'})
  keywordHandler:addKeyword({'sail'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can take you to Venore.'})
keywordHandler:addKeyword({'passage'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can take you to Venore.'})
keywordHandler:addKeyword({'travel'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can take you to Venore.'})
  keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I\'m the captain of this ship!'})
keywordHandler:addKeyword({'captain'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I\'m the captain of this ship!'})

  npcHandler:addModule(FocusModule:new())
 
Thank You! You missunderstood the vocation so it didn't work at first, but I fixed that, no problem!

Only one thing left now, it says "xxx" as the price instead of 120. Tryed to have a look at the functions etc, can't find it.
It will work once that is done :D

Code:
local keywordHandler = KeywordHandler:new()
  local npcHandler = NpcHandler:new(keywordHandler)
  NpcSystem.parseParameters(npcHandler)

  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
 
  local humans = {1,2,3,4} -- IDS of all human vocations
  local elves = {5,6,7} -- IDs of all elf vocations
  local coords1 = {x = 515, y = 846, z = 6} -- Put coordinates of Carlin here
  local coords2 = {x = 862, y = 694, z = 6} -- Put coordinates of Ab'dendriel here
  local price1 = 120 -- Price to travel to Carlin
  local price2 = 120 -- Price to travel to Abdendriel
 
-- Function for travelling to Carlin --
function CarlinTrip(cid, message, keywords, parameters, node)

  if(not npcHandler:isFocused(cid)) then
  return false
  end

  if isInArray(humans, getPlayerVocation(cid)) then 
  
  if getPlayerMoney(cid) >= price1 then
  doPlayerRemoveMoney(cid, price1)
  doTeleportThing(cid, coords1, TRUE)
  doSendMagicEffect(getCreaturePosition(cid),12)
  npcHandler:say('Here we go, hold on tight!',cid)
  else
  npcHandler:say('You don\'t have enough money.',cid)
  end
  
  else
  doSendMagicEffect(getCreaturePosition(cid),2)
  npcHandler:say('Sorry, I can only sail humans there!',cid) 
  end
end
 
-- Function for travelling to Ab'dendriel --
function AbTrip(cid, message, keywords, parameters, node)

  if(not npcHandler:isFocused(cid)) then
  return false
  end

  if isInArray(elves, getPlayerVocation(cid)) then 
  
  if getPlayerMoney(cid) >= price2 then
  doPlayerRemoveMoney(cid, price2)
  doTeleportThing(cid, coords2, TRUE)
  doSendMagicEffect(getCreaturePosition(cid),14)
  npcHandler:say('Here we go, hold on tight!',cid)  
  else
  npcHandler:say('You don\'t have enough money.',cid)
  end
  else
  doSendMagicEffect(getCreaturePosition(cid),2)
  npcHandler:say('Sorry, I can only sail elves there!',cid) 
  end
end

local node1 = keywordHandler:addKeyword({'ab\'dendriel'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to travel to Ab\'dendriel for xxx gold?'})
  node1:addChildKeyword({'yes'}, AbTrip, {})
  node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'As you wish!', reset = true})

local node2 = keywordHandler:addKeyword({'carlin'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to travel to Carlin for xxx gold?'})
  node2:addChildKeyword({'yes'}, CarlinTrip, {})
  node2:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'As you wish!', reset = true})
  
local travelNode = keywordHandler:addKeyword({'venore'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Would you like to travel to Venore for 100 gold?'})
  travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = true, level = 20, cost = 100, destination = {x=1081, y=1047, z=6} })

  travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Then what are you doing on my ship?'})
  keywordHandler:addKeyword({'sail'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can take you to Venore.'})
keywordHandler:addKeyword({'passage'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can take you to Venore.'})
keywordHandler:addKeyword({'travel'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can take you to Venore.'})
  keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I\'m the captain of this ship!'})
keywordHandler:addKeyword({'captain'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I\'m the captain of this ship!'})

  npcHandler:addModule(FocusModule:new())

Kind Regards,
Eldin.
 
It is in these lines:

local node1 = keywordHandler:addKeyword({'ab\'dendriel'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to travel to Ab\'dendriel for xxx gold?'})

local node2 = keywordHandler:addKeyword({'carlin'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to travel to Carlin for xxx gold?'})

Edit textually where it says xxx to actual price, because I didn't know how to put a variable here. And glad I could help :]
 
Back
Top