Postado Setembro 22, 2017 7 anos Olá Tk, eu estou com um probleminha em um script, o npc faz todas as açoes corretamente, mas quando ele pede os items e digo "yes" ele diz que não tenho os items e não o pega. Uso tfs 3.7 Esse é o script local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) 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 = 56791 local item1 = {11314, 50} --id do item, quantidade local item2 = {11321, 50} --id do item, quantidade local item3 = {12616, 50} --id do item, quantidade function creatureSayCallback(cid, type, msg) local msg, player = string.lower(msg), Player(cid) if not npcHandler:isFocused(cid) then if isInArray({"hi", "hello"}, msg) then npcHandler:addFocus(cid) if player:getStorageValue(storage) == -1 then npcHandler:say("Hi, ".. player:getName().."! Can I give you {passage} to the basement, would you like it?.", cid) npcHandler.topic[cid] = 1 else npcHandler:say("You already have my permission to enter.", cid) npcHandler.topic[cid] = 0 npcHandler:releaseFocus(cid) end else return false end elseif msgcontains(msg, "passage") and npcHandler.topic[cid] == 1 then npcHandler:say("I need ".. item1[2] .. " " .. getItemName(item1[1])..", ".. item2[2] .. " " .. getItemName(item2[1])..", ".. item3[2] .. " " .. getItemName(item3[1])..". Do you have it?", cid) npcHandler.topic[cid] = 2 elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 2 then if player:removeItem(item1[1], item1[2], item2[1], item2[2], item3[1], item3[2]) then player:setStorageValue(storage, 1) npcHandler:say("Ok, now you can enter.", cid) npcHandler.topic[cid] = 0 else npcHandler:say("Sorry but you don't have the items I need.", cid) npcHandler.topic[cid] = 0 end elseif msgcontains(msg, "no") and npcHandler.topic[cid] == 2 then npcHandler:say("Ok, maybe on the next time.", cid) npcHandler.topic[cid] = 0 elseif msgcontains(msg, "bye") then npcHandler:say("Bye.", cid) npcHandler:releaseFocus(cid) else npcHandler:say("What?", cid) npcHandler.topic[cid] = 0 end return true end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
Postado Setembro 22, 2017 7 anos Solução Não é só adicionando as linhas dos itens que vai funcionar né rsrs Spoiler local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) 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 = 56791 local items = {{11314, 50}, {11321, 50}, {12616, 50}} function Player:checkItemsNeeded(table) local check = {} for i, v in pairs(table) do if self:getItemCount(v[1]) >= v[2] then check[#check+1] = 1 end end return #check end local function getItemsFromTable(itemtable) local text = "" for v = 1, #itemtable do count, info = itemtable[v][2], ItemType(itemtable[v][1]) 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 function creatureSayCallback(cid, type, msg) local msg, player = string.lower(msg), Player(cid) if not npcHandler:isFocused(cid) then if isInArray({"hi", "hello"}, msg) then npcHandler:addFocus(cid) if player:getStorageValue(storage) == -1 then npcHandler:say("Hi, ".. player:getName().."! Can I give you {passage} to the basement, would you like it?.", cid) npcHandler.topic[cid] = 1 else npcHandler:say("You already have my permission to enter.", cid) npcHandler.topic[cid] = 0 npcHandler:releaseFocus(cid) end else return false end elseif msgcontains(msg, "passage") and npcHandler.topic[cid] == 1 then npcHandler:say("I need ".. getItemsFromTable(items) .. ". Do you have them?", cid) npcHandler.topic[cid] = 2 elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 2 then if player:checkItemsNeeded(items) == #items then for i = 1, #items do player:removeItem(items[i][1], items[i][2]) end player:setStorageValue(storage, 1) npcHandler:say("Ok, now you can enter.", cid) npcHandler.topic[cid] = 0 else npcHandler:say("Sorry but you don't have the items I need.", cid) npcHandler.topic[cid] = 0 end elseif msgcontains(msg, "no") and npcHandler.topic[cid] == 2 then npcHandler:say("Ok, maybe on the next time.", cid) npcHandler.topic[cid] = 0 elseif msgcontains(msg, "bye") then npcHandler:say("Bye.", cid) npcHandler:releaseFocus(cid) else npcHandler:say("What?", cid) npcHandler.topic[cid] = 0 end return true end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) Contato: Email: [email protected] Discord: Dwarfer#2715
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.