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

NPC help won't focus

robbydeath

Well-Known Member
Joined
Feb 11, 2008
Messages
495
Reaction score
92
Location
washington state
Hello, I recently started working on my server for fun from so many years ago
I know this is probably a very simple fix but I can't figure it out
He will not focus he only responds to Hi and keeps walking
I was editing from several different npc trying to piece this one together
Thanks a lot in advance

Code:
focus = 0
talk_start = 0
target = 0
following = false
attacking = false

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
      if focus == cid then
          selfSay('Good bye then.')
          focus = 0
          talk_start = 0
      end
end


function onCreatureTurn(creature)

end

function msgcontains(txt, str)
      return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end


function onCreatureSay(cid, type, msg)
      msg = string.lower(msg)

      if (msgcontains(msg, 'hi') and focus == 0) and getDistanceToCreature(cid) < 4 then
          selfSay('Hello ' .. creatureGetName(cid) .. '! I need 100 worms for my famous worm soup. Can you help me? Find them in the hole east of here inside the

bank.')
          focus = cid
          talk_start = os.clock()

      elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
          selfSay('Sorry, ' .. creatureGetName(cid) .. '! I talk to you in a minute.')

      elseif focus == cid then
        talk_start = os.clock()

        if msgcontains(msg, 'worms') then
            doPlayerRemoveItem(cid,3976,100)
            doPlayerAddItem(cid,2525,1)
        elseif msgcontains(msg, 'worm') then
            doPlayerRemoveItem(cid,3976,100)
            doPlayerAddItem(cid,2525,1)

        elseif msgcontains(msg, 'bye') and getDistanceToCreature(cid) < 4 then
            selfSay('You saved the day! Thank you, ' .. creatureGetName(cid) .. '!')
            focus = 0
            talk_start = 0
        end
      end
end


function onCreatureChangeOutfit(creature)

end


function onThink()
      if (os.clock() - talk_start) > 500 then
          if focus > 0 then
              selfSay('Next Please...')
          end
         focus = 0
      end
     if focus ~= 0 then
         if getDistanceToCreature(focus) > 5 then
             selfSay('Good bye then.')
             focus = 0
         end
     end
end
 
I really appreciate the help but this didn't fix it :(
He responds to hi with the correct message and then walks away
is this a problem?
<npc name="Rob the Welcomer" script="data/npc/scripts/welcome.lua" autowalk="25" floorchange="0" access="5" level="1" maglevel="1">
<health now="150" max="150"/>
<look type="128" head="20" body="100" legs="50" feet="99" corpse="2212"/>
<parameters>
What should my parameters be??
</parameters>
</npc>
 
ok try this
Code:
focus = 0
talk_start = 0
talkState = {}
target = 0
following = false
attacking = false

function onThingMove(creature, thing, oldpos, oldstackpos)
end


function onCreatureAppear(creature)
end


function onCreatureDisappear(cid, pos)
    if focus == cid then
        selfSay('Good bye then.')
        focus = 0
        talk_start = 0
    end
end


function onCreatureTurn(creature)
end

function msgcontains(txt, str)
    return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end

local player = {
    ['worms'] = {removeItem = 3976, removeAmount = 100, addItem = 2525, addAmount = 1},
    ['worm'] = {removeItem = 3976, removeAmount = 100, addItem = 2525, addAmount = 1}
}

function onCreatureSay(cid, type, msg)
    msg = string.lower(msg)
     
    if (msgcontains(msg, 'hi') and focus == 0) and getDistanceToCreature(cid) < 4 then
        selfSay('Hello ' .. creatureGetName(cid) .. '! I need 100 worms for my famous worm soup. Can you help me? Find them in the hole east of here inside the bank.')
        focus = cid
        talk_start = os.clock()
        talkState[cid] = 1
    else
        if talkState[cid] == 1 and focus == cid then
            talk_start = os.clock()
            if next(player[msg]) then
                if getPlayerItemCount(cid, player[msg].removeItem) >= player[msg].removeAmount then
                    doPlayerRemoveItem(cid, player[msg].removeItem, player[msg].removeAmount)
                    doPlayerAddItem(cid, player[msg].addItem, player[msg].addAmount)
                    selfSay('You saved the day! Thank you, ' .. creatureGetName(cid) .. '!')
                else
                    selfSay('Sorry ' .. creatureGetName(cid) .. ', you don\'t have enough '..msg..'.')
                    focus = 0
                    talk_start = 0
                    talkState[cid] = 0
                end
            end
        else
            if msgcontains(msg, 'hi') and getDistanceToCreature(cid) < 4 then
                selfSay('Sorry, ' .. creatureGetName(cid) .. '! I talk to you in a minute.')
            end
        end
    end
    if msgcontains(msg, 'bye') and getDistanceToCreature(cid) < 4 then
        selfSay('Maybe next time..')
        focus = 0
        talk_start = 0
        talkState[cid] = 0
    end
end


function onCreatureChangeOutfit(creature)
end


function onThink()
      if (os.clock() - talk_start) > 500 then
          if focus > 0 then
              selfSay('Next Please...')
          end
         focus = 0
      end
     if focus ~= 0 then
         if getDistanceToCreature(focus) > 5 then
             selfSay('Good bye then.')
             focus = 0
         end
     end
end
 
It can be a lot of things. What server are you using? Did you changed npc libraries at all? Just this npc has this problem or all? Can you paste a npc that works?
 
Thanks a lot it works, still acts weird, won't face the player, but it does work haha thanks a lot sir
Ya I'm using multiple different types I think that's why it's buggy thanks a lot guys you are helping me a lot take care best wishes
 

Similar threads

  • Question Question
Replies
0
Views
180
Back
Top