Olá pessoal eu estava fazendo um sisteminha aqui para meu servidor porém eu tive um erro relacionado a tabela, gostaria da ajuda de vocês para conseguir concerta-lo se possivel uma explicação do motivo desse erro.
[31/05/2016 09:19:18] [Error - Npc interface] [31/05/2016 09:19:18] data/npc/scripts/DayCarre.lua:onCreatureSay[31/05/2016 09:19:18] Description: [31/05/2016 09:19:18] data/npc/scripts/DayCarre.lua:20: attempt to index global 'item' (a nil value)[31/05/2016 09:19:18] stack traceback:[31/05/2016 09:19:18] data/npc/scripts/DayCarre.lua:20: in function <data/npc/scripts/DayCarre.lua:12>
Spoiler
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 talkState = {} local focus = 0 local talk_start = 0
function onCreatureSay(cid, type, msg) local msg = string.lower(msg) local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
local tb = tables[item.itemid] local temp = os.time() + tb.tempo
if not (getDistanceToCreature(cid) <= 3) then return true end
if msgcontains(string.lower(msg), 'hi') then if focus ~= 0 and focus ~= cid then selfSay(getCreatureName(cid) .. ' aguarde...') return true else focus = cid talk_start = os.clock() end end
if msgcontains(string.lower(msg), 'hi') then selfSay('Oi! Voce deseja {checar}, {entregar} ou {retirar}?') talkState[talkUser] = 1 elseif msgcontains(string.lower(msg), 'checar') and talkState[talkUser] == 1 then if getPlayerStorageValue(cid, tb.storage) < temp then selfSay('Seu pokemon ja esta pronto.') else selfSay('Ainda falta [' .. getPlayerStorageValue(cid, tb.storage) < temp ..'], Para seu pokemon esta pronto') talkState[talkUser] = 0 focus = 0 tchau = true end elseif msgcontains(string.lower(msg), 'entregar') and talkState[talkUser] == 1 then if getPlayerStorageValue(cid, tb.storagese) > 1 then selfSay('Voce já tem um ovo comigo, espere terminar') return true end if getPlayerItemCount(cid, 2160) < tb.preco then selfSay('Voce nao tem dinheiro necessesario para compeltar essa acao') return true end if getPlayerItemCount(cid, tb) < 1 then selfSay('Voce nao tem nenhum ovo listado') return true end doPlayerRemoveItem(cid, tb, 1) setPlayerStorageValue(cid, tb.storage, temp) setPlayerStorageValue(cid, tb.storagese, 1) selfSay('Seu ovo estara pronto em breve, toda vez que possivel cheque o ovo para acompanhar o progresso!') talkState[talkUser] = 0 focus = 0 tchau = true elseif msgcontains(string.lower(msg), 'retirar') and talkState[talkUser] == 1 then if getPlayerStorageValue(cid, tb.storage) < temp then setPlayerStorageValue(cid, tb.storagese, -1) addPokeToPlayer(cid, tb.pokemon, 0) selfSay('Uau, seu ovo foi chocado parabens agora voce tem um ' ..tb.pokemon..'.') talkState[talkUser] = 0 focus = 0 tchau = true return true end if tchau then tchau = false doCreatureSetLookDir(getThis(), lookNpcDir) selfSay('Tchau.') end end end
function onThink() if focus ~= 0 then if getDistanceToCreature(focus) > 3 then tchau = true focus = 0 end
if (os.clock() - talk_start) > 15 then if focus > 0 then tchau = true focus = 0 end end doNpcSetCreatureFocus(focus) end
if tchau then tchau = false selfSay('Tchau.') end end
Pergunta
kttallan 319
Olá pessoal eu estava fazendo um sisteminha aqui para meu servidor porém eu tive um erro relacionado a tabela, gostaria da ajuda de vocês para conseguir concerta-lo se possivel uma explicação do motivo desse erro.
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 talkState = {}
local focus = 0
local talk_start = 0
function onCreatureSay(cid, type, msg)
local msg = string.lower(msg)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
local tables = {
[12127] = {preco = 10, storage = 1212, storagese = 1213, tempo = 24 * 60 * 60, pokemon = "Arcanine"}
}
local tb = tables[item.itemid]
local temp = os.time() + tb.tempo
if not (getDistanceToCreature(cid) <= 3) then
return true
end
if msgcontains(string.lower(msg), 'hi') then
if focus ~= 0 and focus ~= cid then
selfSay(getCreatureName(cid) .. ' aguarde...')
return true
else
focus = cid
talk_start = os.clock()
end
end
if msgcontains(string.lower(msg), 'hi') then
selfSay('Oi! Voce deseja {checar}, {entregar} ou {retirar}?')
talkState[talkUser] = 1
elseif msgcontains(string.lower(msg), 'checar') and talkState[talkUser] == 1 then
if getPlayerStorageValue(cid, tb.storage) < temp then
selfSay('Seu pokemon ja esta pronto.')
else
selfSay('Ainda falta [' .. getPlayerStorageValue(cid, tb.storage) < temp ..'], Para seu pokemon esta pronto')
talkState[talkUser] = 0
focus = 0
tchau = true
end
elseif msgcontains(string.lower(msg), 'entregar') and talkState[talkUser] == 1 then
if getPlayerStorageValue(cid, tb.storagese) > 1 then
selfSay('Voce já tem um ovo comigo, espere terminar')
return true end
if getPlayerItemCount(cid, 2160) < tb.preco then
selfSay('Voce nao tem dinheiro necessesario para compeltar essa acao')
return true end
if getPlayerItemCount(cid, tb) < 1 then
selfSay('Voce nao tem nenhum ovo listado')
return true end
doPlayerRemoveItem(cid, tb, 1)
setPlayerStorageValue(cid, tb.storage, temp)
setPlayerStorageValue(cid, tb.storagese, 1)
selfSay('Seu ovo estara pronto em breve, toda vez que possivel cheque o ovo para acompanhar o progresso!')
talkState[talkUser] = 0
focus = 0
tchau = true
elseif msgcontains(string.lower(msg), 'retirar') and talkState[talkUser] == 1 then
if getPlayerStorageValue(cid, tb.storage) < temp then
setPlayerStorageValue(cid, tb.storagese, -1)
addPokeToPlayer(cid, tb.pokemon, 0)
selfSay('Uau, seu ovo foi chocado parabens agora voce tem um ' ..tb.pokemon..'.')
talkState[talkUser] = 0
focus = 0
tchau = true
return true
end
if tchau then
tchau = false
doCreatureSetLookDir(getThis(), lookNpcDir)
selfSay('Tchau.')
end
end
end
function onThink()
if focus ~= 0 then
if getDistanceToCreature(focus) > 3 then
tchau = true
focus = 0
end
if (os.clock() - talk_start) > 15 then
if focus > 0 then
tchau = true
focus = 0
end
end
doNpcSetCreatureFocus(focus)
end
if tchau then
tchau = false
selfSay('Tchau.')
end
end
Link para o comentário
https://xtibia.com/forum/topic/240944-erro-npc/Compartilhar em outros sites
21 respostass a esta questão
Posts Recomendados