Meu ot está dando um erro no npc. Quando eu digo hi ele nao vira pro lado que o player está. E fica dando esse seguinte erro no distro:
[Error - Npc interface]
data/npc/scripts/edoBank.lua:onThink
Description:
data/npc/scripts/edoBank.lua:196: attempt to call global 'lookAtPlayer' (a nil v
alue)
stack traceback:
data/npc/scripts/edoBank.lua:196: in function <data/npc/scripts/edoBank.
lua:178>
Olha o script do NPC:
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
-- Makes sure the npc reacts when you say hi, bye etc.
npcHandler:addModule(FocusModule:new())
local state = 0
local focus = 0
local count = 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 getCount(msg)
b, e = string.find(msg, "%d+")
if b == nil or e == nil then
count = 1
else
count = tonumber(string.sub(msg, b, e))
end
return count
end
function onCreatureSay(cid, type, msg)
msg = string.lower(msg)
if state == 0 then
if msgcontains(msg, 'hi') and getDistanceTo(cid) < 4 then
selfSay('Ola! Você quer \'depositar\' ou \'sacar\' dinheiro?')
focus = cid
state = 1
talk_start = os.clock()
end
elseif state == 1 then --depositar ou sacar
if msgcontains(msg, 'depositar') then
selfSay('Quanto você quer depositar?')
state = 2
talk_start = os.clock()
elseif msgcontains(msg, 'sacar') then
selfSay('Quanto você quer sacar?')
state = 4
talk_start = os.clock()
end
elseif state == 2 then --depositar
count = getCount(msg)
if count >= 10 and count <= 1000000 then
selfSay('Você tem certeza que vai depositar '..count..'gp?')
state = 3
talk_start = os.clock()
else
selfSay('Você pode depositar no máximo 1kk por vez')
state = 2
talk_start = os.clock()
end
elseif state == 3 then --depositar confirma
if msgcontains(msg, 'sim') or msgcontains(msg, 'yes') then
local balAtual = 0
balAtual = getPlayerBalance(focus)
local granaBolso = 0
granaBolso = getPlayerMoney(focus)
if granaBolso >= count then
if doPlayerRemoveMoney(focus,count) == TRUE then
if ( doPlayerSetBalance(focus, balAtual + count) == TRUE ) then
selfSay('Feito! Você pode consultar seu saldo atraves do comando !stats')
state = 0
focus = 0
count = 0
else
selfSay('Você não tem esse dinheiro.')
state = 1
count = 0
end
else
selfSay('Jogador não encontrado.')
state = 0
focus = 0
count = 0
end
else
selfSay('Voce não tem esse dinheiro.')
state = 1
count = 0
end
elseif msgcontains(msg, 'não') or msgcontains(msg, 'no') then
selfSay('Então quanto você quer depositar?')
talk_start = os.clock()
state = 2
end
elseif state == 4 then --sacar
count = getCount(msg)
if count >= 10 and count <= 1000000 then
selfSay('Você tem certeza que vai sacar '..count..'gp?')
state = 5
talk_start = os.clock()
else
selfSay('Quantidade inválida, escolha outro valor')
state = 4
count = 0
end
elseif state == 5 then --sacar confirma
if msgcontains(msg, 'sim') or msgcontains(msg, 'yes') then
local atual = 0
atual = getPlayerBalance(focus)
if atual >= count then
if ( doPlayerSetBalance(focus, atual - count) == TRUE ) then
doPlayerAddMoney(focus, count)
selfSay('Feito! Você pode consultar seu saldo atraves do comando !stats')
state = 0
focus = 0
count = 0
else
selfSay('Erro 11.')
state = 1
count = 0
focus = 0
end
else
selfSay('Você nao tem essa quantia na sua conta bancaria.')
state = 1
count = 0
end
elseif msgcontains(msg, 'não') or msgcontains(msg, 'no') then
selfSay('Então quanto você quer sacar?')
state = 4
talk_start = os.clock()
end
end
end
function onCreatureDisappear(cid)
if focus == cid then
focus = 0
state = 0
count = 0
end
end
function onThink()
if (os.clock() - talk_start) > 20 then
if focus > 0 then
selfSay('Até mais senhor ' .. getCreatureName(focus) .. '.')
focus = 0
end
state = 0
end
if focus > 0 then
if getDistanceTo(focus) > 3 then
selfSay('Até mais senhor ' .. getCreatureName(focus) .. '.')
focus = 0
state = 0
else
lookAtPlayer(focus)
end
end
end