Ir para conteúdo
  • 0

Npc Que Troca 7 Itens Por 1 Item


xcocacola

Pergunta

ola xtibia,

 

gostaria de pedir um npc que troca-se 7 items por 1 item,

 

exemplo:

 

doPlayerRemoveItem(cid, 2335, 1)

doPlayerRemoveItem(cid, 2336, 1)

doPlayerRemoveItem(cid, 2337, 1)

doPlayerRemoveItem(cid, 2338, 1)

doPlayerRemoveItem(cid, 2339, 1)

doPlayerRemoveItem(cid, 2340, 1)

doPlayerRemoveItem(cid, 2341, 1)

doPlayerAddItem(cid, 2342)

 

vlw

Editado por xcocacola
Link para o comentário
Compartilhar em outros sites

4 respostass a esta questão

Posts Recomendados

  • 0

data/npc/scripts/troca7npc.lua:

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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

function playerHaveItems(cid, itemid) -- by MatheusMkalo
   local items = type(itemid) == "table" and itemid or {itemid}
   for i = 1, items do
       if getPlayerItemCount(cid, items[i]) <= 0 then
           return false
       end
   end
   return true
end

function doPlayerRemoveItems(cid, itemid, count) -- by MatheusMkalo
   local items = type(itemid) == "table" and itemid or {itemid}
   for i = 1, items do
       doPlayerRemoveItem(cid, items[i], count ~= nil and count or 1)
   end
return nil
end

function creatureSayCallback(cid, type, msg)

   if(not npcHandler:isFocused(cid)) then
       return false
   end

   if msgcontains(msg, "trocar") then
       if playerHaveItems(cid, {2335, 2336, 2337, 2338, 2339, 2340, 2341}) then
           doPlayerRemoveItems(cid, {2335, 2336, 2337, 2338, 2339, 2340, 2341}, 1)
           doPlayerAddItem(cid, 2342, 1)
       else
           selfSay("Voce nao tem os items nescessarios para trocar por um novo.")
       end
   end 
   return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

 

data/npc/Trocador de Items.xml:

<?xml version="1.0" encoding="UTF-8"?>
<npc name="Trocador" script="troca7npc.lua" walkinterval="2000" floorchange="0">
   <health now="100" max="100"/>
   <look type="128" head="17" body="54" legs="114" feet="0" addons="2"/>
   <parameters>
       <parameter key="message_greet" value="Ola, diga {trocar} para trocar 7 items por 1."/>
   </parameters>
</npc>

 

Nao testei, se nao funcionar avise.

Editado por MatheusMkalo
Link para o comentário
Compartilhar em outros sites

  • 0

no que eu falei "trocar" deu esse erro

 

[26/11/2010 14:27:37] [Error - Npc interface] 
[26/11/2010 14:27:37] data/npc/scripts/hota.lua:onCreatureSay
[26/11/2010 14:27:37] Description: 
[26/11/2010 14:27:37] data/npc/scripts/hota.lua:13: 'for' limit must be a number
[26/11/2010 14:27:37] stack traceback:
[26/11/2010 14:27:37] 	data/npc/scripts/hota.lua:13: in function 'playerHaveItems'
[26/11/2010 14:27:37] 	data/npc/scripts/hota.lua:36: in function 'callback'
[26/11/2010 14:27:37] 	data/npc/lib/npcsystem/npchandler.lua:383: in function 'onCreatureSay'
[26/11/2010 14:27:37] 	data/npc/scripts/hota.lua:8: in function <data/npc/scripts/hota.lua:8>

Link para o comentário
Compartilhar em outros sites

  • 0

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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

function playerHaveItems(cid, itemid) -- by MatheusMkalo
   local items = type(itemid) == "table" and itemid or {itemid}
   for i = 1, #items do
       if getPlayerItemCount(cid, items[i]) <= 0 then
           return false
       end
   end
   return true
end

function doPlayerRemoveItems(cid, itemid, count) -- by MatheusMkalo
   local items = type(itemid) == "table" and itemid or {itemid}
   for i = 1, #items do
       doPlayerRemoveItem(cid, items[i], count ~= nil and count or 1)
   end
return nil
end

function creatureSayCallback(cid, type, msg)

   if(not npcHandler:isFocused(cid)) then
       return false
   end

   if msgcontains(msg, "trocar") then
       if playerHaveItems(cid, {2335, 2336, 2337, 2338, 2339, 2340, 2341}) then
           doPlayerRemoveItems(cid, {2335, 2336, 2337, 2338, 2339, 2340, 2341}, 1)
           doPlayerAddItem(cid, 2342, 1)
       else
           selfSay("Voce nao tem os items nescessarios para trocar por um novo.")
       end
   end 
   return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

 

Erros bobos, desculpe

Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...