Postado Julho 19, 2015 9 anos Olá galera do Tibiaking Adicionei este NPC no meu servidor e quando algum player vai falar "hi" com ele aparece este erro na distro: Mostrar conteúdo oculto [19/07/2015 20:08:22] [Error - Npc interface] [19/07/2015 20:08:22] data/npc/scripts/tasks.lua:onCreatureSay [19/07/2015 20:08:22] Description: [19/07/2015 20:08:22] data/npc/scripts/tasks.lua:40: attempt to call global 'Player' (a nil value) [19/07/2015 20:08:22] stack traceback: [19/07/2015 20:08:22] data/npc/scripts/tasks.lua:40: in function 'callback' [19/07/2015 20:08:22] data/npc/lib/npcsystem/npchandler.lua:391: in function 'onCreatureSay' [19/07/2015 20:08:22] data/npc/scripts/tasks.lua:8: in function Alguém pode ajudar? Rep+ aqui o arquivo .lua Mostrar conteúdo oculto local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) local xmsg = {} 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 local storage = 62003 local monsters = { ["Weedle"] = {storage = 5010, mstorage = 19000, amount = 10, exp = 5000, items = {{id = 2160, count = 3}}}, } local function getItemsFromTable(itemtable) local text = "" for v = 1, #itemtable do count, info = itemtable[v].count, ItemType(itemtable[v].id) local ret = ", " if v == 1 then ret = "" elseif v == #itemtable then ret = " and " end text = text .. ret text = text .. (count > 1 and count or info:getArticle()).." "..(count > 1 and info:getPluralName() or info:getName()) end return text end local function Cptl(f, r) return f:upper()..r:lower() end function creatureSayCallback(cid, type, msg) local player, cmsg = Player(cid), msg:gsub("(%a)([%w_']*)", Cptl) if not npcHandler:isFocused(cid) then if msg == "hi" or msg == "hello" then npcHandler:addFocus(cid) if player:getStorageValue(storage) == -1 then local text, n = "", 0 for k, x in pairs(monsters) do if player:getStorageValue(x.mstorage) < x.amount then n = n + 1 text = text .. ", " text = text .. ""..x.amount.." {"..k.."}" end end if n > 1 then npcHandler:say("Eu tenho tasks severas para voce matar monstros "..text..", qual voce ira escolher? Eu posso mostrar pra voce uma {list} com recompensas e voce pode {stop} a task se voce quiser.", cid) npcHandler.topic[cid] = 1 xmsg[cid] = msg elseif n == 1 then npcHandler:say("Eu tenho uma ultima task para voce "..text..".", cid) npcHandler.topic[cid] = 1 else npcHandler:say("Voce ja fez todas as tasks, eu nao tenho mais nada pra voce, boa sorte em sua jornada.", cid) end elseif player:getStorageValue(storage) == 1 then for k, x in pairs(monsters) do if player:getStorageValue(x.storage) == 1 then npcHandler:say("Did you kill "..x.amount.." "..k.."?", cid) npcHandler.topic[cid] = 2 xmsg[cid] = k end end end else return false end elseif monsters[cmsg] and npcHandler.topic[cid] == 1 then if player:getStorageValue(monsters[cmsg].storage) == -1 then npcHandler:say("Boa sorte, volte quando voce tiver matado "..monsters[cmsg].amount.." "..cmsg..".", cid) player:setStorageValue(storage, 1) player:setStorageValue(monsters[cmsg].storage, 1) else npcHandler:say("Voce ja fez a "..cmsg.." mission.", cid) end npcHandler.topic[cid] = 0 elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 2 then local x = monsters[xmsg[cid]] if player:getStorageValue(x.mstorage) >= x.amount then npcHandler:say("Parabens, aqui esta sua recompensa, "..getItemsFromTable(x.items)..".", cid) for g = 1, #x.items do player:addItem(x.items[g].id, x.items[g].count) end player:addExperience(x.exp) player:setStorageValue(x.storage, 2) player:setStorageValue(storage, -1) npcHandler.topic[cid] = 3 else npcHandler:say("Voce nao matou todos, voce precisa matar "..x.amount -(player:getStorageValue(x.mstorage) + 1).." "..xmsg[cid]..".", cid) end elseif msgcontains(msg, "task") and npcHandler.topic[cid] == 3 then local text, n = "", 0 for k, x in pairs(monsters) do if player:getStorageValue(x.mstorage) < x.amount then n = n + 1 text = text .. (n == 1 and "" or ", ") text = text .. "{"..k.."}" end end if text ~= "" then npcHandler:say("Quer fazer outra task? Voce pode escolher "..text..".", cid) npcHandler.topic[cid] = 1 else npcHandler:say("Voce ja fez todas as tasks.", cid) end elseif msgcontains(msg, "no") and npcHandler.topic[cid] == 1 then npcHandler:say("Ok then.", cid) npcHandler.topic[cid] = 0 elseif msgcontains(msg, "stop") then local text, n = "", 0 for k, x in pairs(monsters) do if player:getStorageValue(x.mstorage) < x.amount then n = n + 1 text = text .. (n == 1 and "" or ", ") text = text .. "{"..k.."}" if player:getStorageValue(x.storage) == 1 then player:setStorageValue(x.storage, -1) end end end if player:getStorageValue(storage) == 1 then npcHandler:say("Ok, me deixe saber se voce quer comecar alguma outra task, voce pode escolher "..text..".", cid) else npcHandler:say("Voce nao comecou nenhuma task, se voce quiser comecar alguma, voce pode escolher "..text..".", cid) end player:setStorageValue(storage, -1) npcHandler.topic[cid] = 1 elseif msgcontains(msg, "list") then local text = "Tasks\n\n" for k, x in pairs(monsters) do if player:getStorageValue(x.mstorage) < x.amount then text = text ..k .." ["..(player:getStorageValue(x.mstorage) + 1).."/"..x.amount.."]:\n Rewards:\n "..getItemsFromTable(x.items).."\n "..x.exp.." experience \n\n" else text = text .. k .." [DONE]\n" end end player:showTextDialog(1949, "" .. text) npcHandler:say("Ate mais.", cid) elseif msgcontains(msg, "bye") then npcHandler:say("Tchau.", cid) npcHandler:releaseFocus(cid) else npcHandler:say("O que?", cid) end return true end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
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.