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

[ERROR] logout while talking with a NPC

lordrai

New Member
Joined
Sep 16, 2012
Messages
5
Reaction score
0
I'm getting a console error when someone dies or logout while talking with this npc

THE ERROR:
Code:
Lua Script Error: [Npc interface]
data/npc/scripts/quest.lua:onThink
luaCreatureGetPos(). Creature not found

NPC.lua:
Code:
local focus = 0
local talk_start = 0

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 onCreatureDisappear(cid, pos)
      if focus == cid then
          selfSay('...')
          focus = 0
          talk_start = 0
      end
end


function onCreatureSay(cid, type, text)
    local msg = string.lower(text)
    if msgcontains(msg, 'hi') and (focus == 0) and getDistanceToCreature(cid) < 4 then
                    selfSay('Hello ' .. getCreatureName(cid) .. '! Voce quer ir para a quest?')
                    focus = cid
                    talk_start = os.clock()
    elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
                    selfSay('Desculpe, '..getCreatureName(cid).. '! Somente 1 por vez na quest, aguarde sua vez.')
    elseif focus == cid then
                    talk_start = os.clock()
                    if msgcontains(msg, 'yes') then
                                    if pay(cid,0) then
                                                    travel(cid, 876, 60, 0)
                                                    selfSay('Que o poder saiyajin esteja com voce!')
                                    else
                                                    selfSay('Sorry, you don\'t have enough money.')
                                    end
                    elseif msgcontains(msg, 'bye') and getDistanceToCreature(cid) < 4 then
                                    selfSay('Good bye, ' .. getCreatureName(cid) .. '!')
                                    focus = 0
                                    talk_start = os.clock()
                    end
    end
end

function onThink()

    if focus == 0 then return true end
    if not isCreature(focus) then focus = 0 selfSay("Próximo por favor...") return true end

    doNpcSetCreatureFocus(focus)
    if not getDistanceToCreature(focus) or getDistanceToCreature(focus) > 30 then
                    selfSay('Próximo por favor...')
                    focus = 0
    end
  
end

Can someone help me, please?

I want the NPC to stop talk with someone only when someone walk more then 30 sqm or logout/die.
 
Code:
local focus = 0
local talk_start = 0
local distance = 30

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 onCreatureDisappear(cid, pos)
      if focus == cid then
          selfSay('...')
          focus = 0
          talk_start = 0
      end
end


function onCreatureSay(cid, type, text)
    local msg = text:lower()
    if msgcontains(msg, 'hi') and focus == 0 and getDistanceToCreature(cid) < distance then
        selfSay('Hello ' .. getCreatureName(cid) .. '! Voce quer ir para a quest?')
        focus = cid
        talk_start = os.clock()
    end
    if msgcontains(msg, 'hi') and focus ~= cid and getDistanceToCreature(cid) < distance then
        selfSay('Desculpe, '..getCreatureName(cid).. '! Somente 1 por vez na quest, aguarde sua vez.')
    end
    if focus == cid then
        talk_start = os.clock()
        if msgcontains(msg, 'yes') then
            if pay(cid,0) then
                travel(cid, 876, 60, 0)
                selfSay('Que o poder saiyajin esteja com voce!')
            else
                selfSay('Sorry, you don\'t have enough money.')
            end
        elseif msgcontains(msg, 'bye') and getDistanceToCreature(cid) < distance then
            selfSay('Good bye, ' .. getCreatureName(cid) .. '!')
            focus = 0
            talk_start = os.clock()
        end
    end
end

function onThink()
    if focus == 0 or not isCreature(focus) or getDistanceToCreature(focus) > distance then
        focus = 0
        selfSay("Próximo por favor...")
        return true
    end
end
 
Did you try not using getcreatedistance(Cid) on the condition statement? I think is useless since you already assignment focus to the player, and the next one will only work if focus is set. Also I believe NPC handler would take care of the distance thing. Just try and see what happens
 
It didn't work =/

organizing better, the problem is here

Code:
function onThink()
    doNpcSetCreatureFocus(focus)

if not isCreature(focus) then
focus = 0
selfSay("message 1")
end


     if focus ~= 0 then
         if not getDistanceToCreature(focus) then
             selfSay('message 2')
             focus = 0
return true
         end
     end


     if focus ~= 0 then
         if getDistanceToCreature(focus) > 30 then
             selfSay('message 3')
             focus = 0
         end
     end

end


the condition on message 2 is the main condition to dont happen a error when someone logout/die
If I dont have this condition before the condition 3, I will get a error about nil.
this condition works, but when someone die/logout I still get a error on console, but the npc stills works...
the error is: LuaCreatureGetPos(). Creature Not Found

anyone know how to dont get this error?
 
Back
Top