Ir para conteúdo

Featured Replies

Postado

Boa família, tranquilo? Rapaziada tentei de várias formas, mas não manjo muito.. se vocês puderem ajudar agradeço desde já!
- Preciso que o
NPC peça mais de um Item para poder craftar as recompensas. 
local craft = {
["hiruzen helmet"] = {reward = {{11555, 1}}, items = {{id = 12405, count = 1}}}
Notem que o item que o NPC está pedindo é "12405", queria que vocês adicionem +1 item para ele pedir com uma quantidade também.

Algo desse tipo:
Ex: ["hiruzen helmet"] = {reward = {{11555, 1}}, items = {{id = 12405, count = 1}}, {{id = 12345, count = 10}}}

 

Spoiler

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local npcTopic, 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 craft = {
["hiruzen helmet"] = {reward = {{11555, 1}}, items = {{id = 12405, count = 1}}}

 

local function checkItemsNeeded(cid, items)
local check = {}
for i, v in pairs(items) do
    if getPlayerItemCount(cid, v.id) >= v.count then
        check[#check + 1] = 1
    end
end
return #check
end

 

local function getItemsFromTable(items)
local str = ''
if table.maxn(items) > 0 then
for i = 1, table.maxn(items) do
str = str .. items[i].count .. ' ' .. getItemNameById(items[i].id)
if i ~= table.maxn(items) then str = str .. ', ' end end end
return str
end

 

local function craftingEffects(position, delay)
local text = {"Boom", "Plim", "Paaa!", "BUM!"}
local effects = {15, 12, 13, 10, 32, 97, 1387, 1388, 1389, 1390, 803, 802}
if delay ~= 0 then
doSendAnimatedText(position, text[math.random(1, #text)], math.random(1, 255))
doSendMagicEffect(position, effects[math.random(1, #effects)])
addEvent(craftingEffects, 500, position, delay - 1)
end
end

 

function creatureSayCallback(cid, type, msg)
    local talkUser, msg = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid, string.lower(msg)
    if(not npcHandler:isFocused(cid)) then
        if isInArray({"hi", "hello"}, msg) then
            npcHandler:addFocus(cid)
            npcHandler:say("Oh! Se não é o "..getPlayerName(cid).." meu jovem shinobi. Impressionante ter chego até aqui, trouxe os {itens} que preciso?", cid)
            npcTopic[talkUser] = 1
        else
            return false
        end
    elseif msgcontains(msg, "itens") and npcTopic[talkUser] == 1 then
        local text = ""
        for i, v in pairs(craft) do
            text = text .. " {"..i.."}, "
        end
        npcHandler:say("Possuo " .. text .. " o que quer levar?", cid)
        npcTopic[talkUser] = 2
    elseif craft[msg] and npcTopic[talkUser] == 2 then
        npcHandler:say("Hahaha, mas para conquistar este item eu vou precisar de " .. getItemsFromTable(craft[msg].items) .. ", voce possui?" , cid)
        npcTopic[talkUser] = 3
        xmsg[talkUser] = msg
    elseif not craft[msg] and npcTopic[talkUser] == 2 then    
        npcHandler:say("Não possuo tal item, talvez mais tarde meu jovem.", cid)
        npcTopic[talkUser] = 0
    elseif msgcontains(msg, "yes") and npcTopic[talkUser] == 3 then
        local x = craft[xmsg[talkUser]]
        local delay = 6
        if checkItemsNeeded(cid, x.items) == #x.items then
            craftingEffects(getCreaturePosition(getNpcCid()), delay)
                for i = 1, #x.items do
                    doPlayerRemoveItem(cid, x.items[i].id, x.items[i].count)
                end
            addEvent(function()
                if isPlayer(cid) then
                    for i = 1, #x.reward do
                        doPlayerAddItem(cid, x.reward[i][1], x.reward[i][2])
                    end
                end
            end, delay*500)
            local type = talkUser == 0 and TALKTYPE_SAY or TALKTYPE_PRIVATE_NP
            addEvent(doCreatureSay, delay*500, getNpcCid(), "Uma bela conquista jovem shinobi! Aqui está uma parte da minha armadura.", type, cid)
            npcTopic[talkUser] = 0
        else
            npcHandler:say("Você não possui os itens necessários.", cid)
            npcTopic[talkUser] = 0
        end
    elseif msgcontains(msg, "no") and npcTopic[talkUser] == 3 then
        npcHandler:say("Oh, talvez da próxima então", cid)
        npcTopic[talkUser] = 0
    elseif msgcontains(msg, "bye") then
        npcHandler:say("Até.", cid)
        npcHandler:releaseFocus(cid)
    else
        npcHandler:say("Estou ocupado agora meu jovem, logo te darei atenção.", cid)
        npcTopic[talkUser] = 0
    end
    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

 

Editado por raphadoidera (veja o histórico de edições)

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.

Visitante
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Conteúdo Similar

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.7k

Informação Importante

Confirmação de Termo