• 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 send back to temple

Lbtg

Advanced OT User
Joined
Nov 22, 2008
Messages
2,398
Reaction score
165
PHP:
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!
        local travelNode = keywordHandler:addKeyword({'warfare'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to sail to Main Land for free? dont forget to choose vocation'})
            travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = false, level = 0, cost = 0, destination = {x=997, y=997, z=7} })
            travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'We would like to serve you some time.'})
      
        keywordHandler:addKeyword({'captain'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I am the captain of this ship.'})
     

        npcHandler:addModule(FocusModule:new())

Hello, there is a code of sail npc i added and i want to make it that if player has no vocation while trying to sail npc he gets teleproted to certain location and recieves message in middle of game window "choose"

Thanks in advance :)

using 0.3.6

bumpz ;I
 
Last edited by a moderator:
Careful with the bumping. You shouldn't be bumping a thread unless 24 hours have passed.
As for your npc.. your using very outdated methods in that boat npc, and as your picture implies, you should instead be using lua and ot functions to script the npc.
Here is a very very very basic npc, that you can use from now on to start as a base for any npc in 0.3.6
and here is a LINK to 0.3.6 functions.
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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
function greet(cid)     talkState[cid] = 0     return true   end
function getNpcName()     return getCreatureName(getNpcId())   end
   
function creatureSayCallback(cid, type, msg)
  if(not npcHandler:isFocused(cid)) then
  return false
  end
   
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

   -- check for player money
   -- added this just for you!
   local player_gold  = getPlayerItemCount(cid,2148)
  local player_plat  = getPlayerItemCount(cid,2152)*100
  local player_crys  = getPlayerItemCount(cid,2160)*10000
  local player_money  = player_gold + player_plat + player_crys

   if msgcontains(msg, "job") then
     selfSay("My job is to show you a basic npc file!", cid)
   elseif msgcontains(msg, "name") then
     selfSay("My name is " .. getNpcName() .. ".", cid)

   end
   return true   
end

npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

And here is a mostly completed boat npc for you.
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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
function greet(cid)     talkState[cid] = 0     return true   end
function getNpcName()     return getCreatureName(getNpcId())   end
   
function creatureSayCallback(cid, type, msg)
  if(not npcHandler:isFocused(cid)) then
  return false
  end
   
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

   -- check for player money
   -- added this just for you!
   local player_gold  = getPlayerItemCount(cid,2148)
  local player_plat  = getPlayerItemCount(cid,2152)*100
  local player_crys  = getPlayerItemCount(cid,2160)*10000
  local player_money  = player_gold + player_plat + player_crys
   
   local Main_Land = {x=111111, y=111111, z=11}
   local No_Vocation = {x=111111, y=111111, z=11}

   if msgcontains(msg, "job") then
     selfSay("My job is to show you a basic npc file!", cid)
   elseif msgcontains(msg, "name") then
     selfSay("My name is " .. getNpcName() .. ".", cid)
     
   elseif msgcontains(msg, "travel") then
     selfSay("Do you want to sail to Main Land?", cid)
     talkState[talkUser] = 1
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
     if getPlayerVocation(cid) ~= 0 then
       selfSay("Alright! Off we go!", cid)
  doTeleportThing(cid, Main_Land)
       talkState[talkUser] = 0
     else
       selfSay("You need to choose a vocation before going to Main Land!", cid)
       doTeleportThing(cid, No_Vocation)
       talkState[talkUser] = 0
     end
   elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
     selfSay("We would like to serve you some time.", cid)
     talkState[talkUser] = 0
   end
   
   return true   
end

npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Update to the tabbing in the script, which seemed to be broken when I pasted it earlier, and also a slight update to the scripting to optimize it a bit.
When you have multiple lines that need to do the same thing, you can place it outside of the different checks and save yourself, and your script, some time. (although it's rather insignificant in this case, it's good to keep doing it in practice. :p)
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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
function greet(cid) talkState[cid] = 0 return true end
function getNpcName() return getCreatureName(getNpcId()) end
  
function creatureSayCallback(cid, type, msg)
     if(not npcHandler:isFocused(cid)) then
         return false
     end

     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

     -- check for player money
     -- added this just for you!
     local player_gold  = getPlayerItemCount(cid,2148)
     local player_plat  = getPlayerItemCount(cid,2152)*100
     local player_crys  = getPlayerItemCount(cid,2160)*10000
     local player_money  = player_gold + player_plat + player_crys

     local Main_Land = {x=111111, y=111111, z=11}
     local No_Vocation = {x=111111, y=111111, z=11}

     if msgcontains(msg, "job") then
         selfSay("My job is to show you a basic npc file!", cid)
     elseif msgcontains(msg, "name") then
         selfSay("My name is " .. getNpcName() .. ".", cid)
  
     elseif msgcontains(msg, "travel") then
         selfSay("Do you want to sail to Main Land?", cid)
         talkState[talkUser] = 1
     elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
         if getPlayerVocation(cid) ~= 0 then
             selfSay("Alright! Off we go!", cid)
             doTeleportThing(cid, Main_Land)
         else
             selfSay("You need to choose a vocation before going to Main Land!", cid)
             doTeleportThing(cid, No_Vocation)
         end
         talkState[talkUser] = 0
     elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
         selfSay("We would like to serve you some time.", cid)
         talkState[talkUser] = 0
     end

     return true  
end

npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
works nicely :) but how i add that player recieve msg about to choose vocation not from npc but with effect and White letters in middle of windows saying about choose ? :)

Thank you rl much :)
 
works nicely :) but how i add that player recieve msg about to choose vocation not from npc but with effect and White letters in middle of windows saying about choose ? :)

Thank you rl much :)

Replace this,
Code:
selfSay("You need to choose a vocation before going to Main Land!", cid)
doTeleportThing(cid, No_Vocation)
With this.
Code:
doTeleportThing(cid, No_Vocation)
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You need to choose a vocation before going to Main Land!")
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TUTORIALARROW)
H16q19y.png
 
Back
Top