Postado Janeiro 16, 2021 4 anos Alguém me ajuda quero um NPC, que pede 3 itens e dar 1! id dos itens pedidos: 13386, 12713, 13400. id do item que ele dar em troca: 12714. Obrigado!
Postado Janeiro 18, 2021 4 anos Solução @isac001 Spoiler -- by dwarfer local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) local npcTopic = {} 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 t = { costItems = {{13386, 1}, {12713, 1}, {13400, 1}}, -- {id do item, quantidade} rewardItems = {{12714, 1}}, } 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("Olá, "..getPlayerName(cid)..". Posso te dar {itens} especiais se você me der o que preciso.", cid) npcTopic[talkUser] = 1 else return false end elseif msgcontains(msg, "itens") and npcTopic[talkUser] == 1 then local textcost, textrwd, tmp = "", "", {} for k = 1, #t.rewardItems do tmp = t.rewardItems[k] textrwd = textrwd .. tmp[2] .. "x " .. getItemNameById(tmp[1]) .. ((k+1) == #t.rewardItems and " e " or (k ~= #t.rewardItems and ", " or "")) end if #t.costItems > 0 then for i = 1, #t.costItems do tmp = t.costItems[i] textcost = textcost .. tmp[2] .. "x " .. getItemNameById(tmp[1]) .. (i ~= #t.costItems and ", " or "") end npcHandler:say("Você quer me dar "..textcost.." em troca de "..textrwd.."?", cid) npcTopic[talkUser] = 2 else npcHandler:say("Você quer "..textrwd.." grátis?", cid) npcTopic[talkUser] = 2 end elseif msgcontains(msg, "yes") and npcTopic[talkUser] == 2 then local check, tmp = true, {} if #t.costItems > 0 then for i = 1, #t.costItems do tmp = t.costItems[i] if getPlayerItemCount(cid, tmp[1]) < tmp[2] then check = false break end end end if not check then npcHandler:say("Você não tem todos os itens que preciso. Volte quando estiver com todos eles.", cid) npcTopic[talkUser] = 0 npcHandler:releaseFocus(cid) else if #t.costItems > 0 then for i = 1, #t.costItems do tmp = t.costItems[i] doPlayerRemoveItem(cid, tmp[1], tmp[2]) end end for k = 1, #t.rewardItems do tmp = t.rewardItems[k] if isItemStackable(tmp[1]) then doPlayerAddItem(cid, tmp[1], tmp[2]) else for n = 1, tmp[2] do doPlayerAddItem(cid, tmp[1], 1) end end end npcHandler:say("Negócio fechado! Receba o que prometi. Aguardo seu retorno outro dia.", cid) npcTopic[talkUser] = 0 npcHandler:releaseFocus(cid) end elseif msgcontains(msg, "no") and npcTopic[talkUser] == 2 then npcHandler:say("Sem problemas, estarei sempre aqui no mesmo local e no mesmo horário.", cid) npcTopic[talkUser] = 0 npcHandler:releaseFocus(cid) elseif msgcontains(msg, "bye") then npcHandler:say("Até outro dia.", cid) npcTopic[talkUser] = 0 npcHandler:releaseFocus(cid) end return true end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:setMessage(MESSAGE_FAREWELL, "Até mais.") npcHandler:setMessage(MESSAGE_WALKAWAY, "Até.") 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.