Postado Maio 31, 2016 8 anos 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. 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> Codigo: Mostrar conteúdo oculto 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 Editado Maio 31, 2016 8 anos por AllanH (veja o histórico de edições)
Postado Maio 31, 2016 8 anos local tb = tables[item.itemid] A variável "item" não existe nesta função, não entendi o que você quis fazer. Se tu me explicar, posso tentar ajudar.
Postado Maio 31, 2016 8 anos Autor Em 31/05/2016 em 15:42, Talesigorvr disse: local tb = tables[item.itemid] A variável "item" não existe nesta função, não entendi o que você quis fazer. Se tu me explicar, posso tentar ajudar. Seria assim. Eu estou tentando fazer um sistema de DayCare, para pokemon ou seja. Checar - Quanto tempo falta para o ovo estiver pronto (Usei storage+os.time) Entregar - Será quando o npc removerá o [item.itemid] e removerá o item + quantidade referente ao preço, setaria a storage e a storage + os.time. Remover - Após o player perde a storage do os.time o npc irá adicionar a ele o pokemon. Sendo que não será só um ovo será varios. local tables = { [Ovo] = {preco = Quantidade, storage = Storage do Os.time, storagese = Storage de Segurança, tempo = Tempo do os.time, pokemon = Nome do Pokemon} }
Postado Maio 31, 2016 8 anos Tu tem que dar um ovo pro NPC? Tu fala o nome do ovo pra ele e ele remove, é isso?
Postado Maio 31, 2016 8 anos Autor Em 31/05/2016 em 16:01, Talesigorvr disse: Tu tem que dar um ovo pro NPC? Tu fala o nome do ovo pra ele e ele remove, é isso? Não exatamente o npc iria checar se o player teria o ovo no bag e de acordo com o id do ovo teria configurações diferentes.
Participe da conversa
Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.