Ir para conteúdo

Featured Replies

Postado

Olá pessoal eu andei tentando criar um npc que troca dois itens por 1.

Exemplo: Uma CHAIN ARMOR + GOLDEN ARMOR + 10k por um outro item... só que quando vou falar com ele , basta ter só uma chain armor ou só uma golden armor, ou só 10k que ele ja troca..nao precisa ter os 3, e eu gostaria que ele trocasse os 3 itens por 1. Vou postar foto do meu script.

É um OTSERVER 7.6 ..OTyourotz, bem antigo.

Se alguem souber me ajudar, por favor, ficarei muito grato!

Abraço!

 

Script

focus = 0
talk_start = 0
target = 0
following = false
attacking = false

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
      if focus == cid then
          selfSay('Good bye then.')
          focus = 0
          talk_start = 0
      end
end


function onCreatureTurn(creature)

end


function msgcontains(txt, str)
      return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end


function onCreatureSay(cid, type, msg)
      msg = string.lower(msg)

      if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
          selfSay('Hi ' .. creatureGetName(cid) .. '... I can forge A Forge Armor for you to bring me a Chain Armor and a Golden Armor , will charge a fee of 10000GPS...')
          focus = cid
          talk_start = os.clock()

      elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
          selfSay('Sorry, ' .. creatureGetName(cid) .. '! I talk to you in a minute.')

    elseif focus == cid then
        talk_start = os.clock()

if msgcontains(msg, 'forge armor') then    
    itemstatus = doPlayerRemoveItem(cid,2464) -- 2464 golden armor    
    itemstatus = doPlayerRemoveItem(cid,2466) -- 2466 chain armor
    itemstatus = doPlayerRemoveItem(cid,2160) -- 2160 crystal coin
    needmoney = 0 -- qntidade que o player precisa pagar (em GPs)    
    money = pay(cid,needmoney)    
    if itemstatus == 0 and money == true then        
        selfSay('Hmm, this is incredible! Take this Forge Armor!')        
        buy(cid,2508,1,0) -- 2472 é o item que ele irá ganhar 
                -- note que o preço do item é 0, ou seja,                
                -- o player irá pagar 0 GPs pelo item;    
    else        
        selfSay('you do not have the necessary items...')    
end

if msgcontains(msg, 'helmet of the ancients') then    
    itemstatus = doPlayerRemoveItem(cid,2147) -- 2147 é o item que o player vai ter que dar pro npc    
    itemstatus = doPlayerRemoveItem(cid,2342) -- 2342 é o item que o player vai ter que dar pro npc
    needmoney = 0 -- qntidade que o player precisa pagar (em GPs)    
    money = pay(cid,needmoney)    
    if itemstatus == 0 and money == true then        
        selfSay('Hmm, this is incredible! Take this Full Helmet of the Ancients!')        
        buy(cid,2343,1,0) -- 2343 é o item que ele irá ganhar 
                -- note que o preço do item é 0, ou seja,                
                -- o player irá pagar 0 GPs pelo item;    
    else        
        selfSay('It is missing something...')    
    end
end
        elseif string.find(msg, '(%a*)bye(%a*)') and getDistanceToCreature(cid) < 4 then
            selfSay('Good bye, ' .. creatureGetName(cid) .. '!')
            focus = 0
            talk_start = 0
        end
    end
end


function onCreatureChangeOutfit(creature)

end


function onThink()
      if (os.clock() - talk_start) > 30 then
          if focus > 0 then
              selfSay('Next Please...')
          end
              focus = 0
      end
     if focus ~= 0 then
         if getDistanceToCreature(focus) > 5 then
             selfSay('Good bye then.')
             focus = 0
         end
     end
end
 

 

  • Respostas 5
  • Visualizações 675
  • Created
  • Última resposta

Top Posters In This Topic

Most Popular Posts

  • Tenta assim

  • Esquece esse script, tenta esse:   data/npc/scripts/blacksmith.lua local tab = { item = {2349, 1}, -- {ID do item, Quantidade} mude para os itens que voce quer, pois esses sao itens de

Postado
Spoiler

 

focus = 0
talk_start = 0
target = 0
following = false
attacking = false

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
      if focus == cid then
          selfSay('Good bye then.')
          focus = 0
          talk_start = 0
      end
end


function onCreatureTurn(creature)

end


function msgcontains(txt, str)
      return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end


function onCreatureSay(cid, type, msg)
      msg = string.lower(msg)

      if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
          selfSay('Hi ' .. creatureGetName(cid) .. '... I can forge A Forge Armor for you to bring me a Chain Armor and a Golden Armor , will charge a fee of 10000GPS...')
          focus = cid
          talk_start = os.clock()

      elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
          selfSay('Sorry, ' .. creatureGetName(cid) .. '! I talk to you in a minute.')

    elseif focus == cid then
        talk_start = os.clock()

if msgcontains(msg, 'forge armor') then    
    itemstatusum = doPlayerRemoveItem(cid,2464) -- 2464 golden armor    
    itemstatusdois = doPlayerRemoveItem(cid,2466) -- 2466 chain armor
    itemstatustres = doPlayerRemoveItem(cid,2160) -- 2160 crystal coin
    needmoney = 0 -- qntidade que o player precisa pagar (em GPs)    
    money = pay(cid,needmoney)    
    if itemstatusum == 0 and itemstatusdois == 0 and itemstatustres == 0 and money == true then        
        selfSay('Hmm, this is incredible! Take this Forge Armor!')        
        buy(cid,2508,1,0) -- 2472 é o item que ele irá ganhar 
                -- note que o preço do item é 0, ou seja,                
                -- o player irá pagar 0 GPs pelo item;    
    else        
        selfSay('you do not have the necessary items...')    
end

if msgcontains(msg, 'helmet of the ancients') then    
    itemstatusum = doPlayerRemoveItem(cid,2147) -- 2147 é o item que o player vai ter que dar pro npc    
    itemstatusdois = doPlayerRemoveItem(cid,2342) -- 2342 é o item que o player vai ter que dar pro npc
    needmoney = 0 -- qntidade que o player precisa pagar (em GPs)    
    money = pay(cid,needmoney)    
    if itemstatusum == 0 and itemstatusdois == 0 and money == true then        
        selfSay('Hmm, this is incredible! Take this Full Helmet of the Ancients!')        
        buy(cid,2343,1,0) -- 2343 é o item que ele irá ganhar 
                -- note que o preço do item é 0, ou seja,                
                -- o player irá pagar 0 GPs pelo item;    
    else        
        selfSay('It is missing something...')    
    end
end
        elseif string.find(msg, '(%a*)bye(%a*)') and getDistanceToCreature(cid) < 4 then
            selfSay('Good bye, ' .. creatureGetName(cid) .. '!')
            focus = 0
            talk_start = 0
        end
    end
end


function onCreatureChangeOutfit(creature)

end


function onThink()
      if (os.clock() - talk_start) > 30 then
          if focus > 0 then
              selfSay('Next Please...')
          end
              focus = 0
      end
     if focus ~= 0 then
         if getDistanceToCreature(focus) > 5 then
             selfSay('Good bye then.')
             focus = 0
         end
     end
end

 

Tenta assim

Postado
  • Autor

ai irmao, tentei, mas o que acontece , se eu tenho por exemplo UM item dos que precisa pra ''fazer'' a armadura, ele simplismente some, mas se eu tenho todos os itens ele faz a armadura.

 

Postado
3 horas atrás, fedegrodas21 disse:

ai irmao, tentei, mas o que acontece , se eu tenho por exemplo UM item dos que precisa pra ''fazer'' a armadura, ele simplismente some, mas se eu tenho todos os itens ele faz a armadura.

 

 

Esquece esse script, tenta esse:

 

data/npc/scripts/blacksmith.lua

local tab = {
	item = {2349, 1}, -- {ID do item, Quantidade} mude para os itens que voce quer, pois esses sao itens de teste que usei
	item2 = {2346, 1},
	item3 = {2156, 1},
	recompensa = {5791, 1}, -- Armadura que vai ganhar se tiver todos os itens
	price = 10 -- quantidade em crystal coins
	
}

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 creatureSayCallback(cid, type, msg)
	if (not npcHandler:isFocused(cid)) then
		return false
	end
	
	local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
	if (msgcontains(msg, 'forge armor')) then
		talkState[talkUser] = 1
		selfSay('Lembre-se.. Voce precisa de '..tab.item[2]..' '..getItemNameById(tab.item[1])..', '..tab.item2[2]..' '..getItemNameById(tab.item2[1])..', '..tab.item3[2]..' '..getItemNameById(tab.item3[1])..' e 10k. Ja possui todos?', cid)
	elseif (msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if (getPlayerItemCount(cid, tab.item[1]) >= tab.item[2] and
			getPlayerItemCount(cid, tab.item2[1]) >= tab.item2[2] and 
			getPlayerItemCount(cid, tab.item3[1]) >= tab.item3[2] and
			doPlayerRemoveMoney(cid, tab.price * 1000)) then
			doPlayerRemoveItem(cid, tab.item[1], tab.item[2])
			doPlayerRemoveItem(cid, tab.item2[1], tab.item2[2])
			doPlayerRemoveItem(cid, tab.item3[1], tab.item3[2])
			doPlayerAddItem(cid,tab.recompensa[1],tab.recompensa[2])
			doSendMagicEffect(getThingPos(cid), CONST_ME_TELEPORT)
			selfSay('Veja so, voce tem todos os itens, parabens, aproveite sua nova armadura!.', cid)
		else
			talkState[talkUser] = 0
			selfSay('Perdao, mas voce nao tem os itens necessarios ainda, volte quando estiver com todos.', cid)
		end
	elseif (msgcontains(msg, 'no') and talkState[talkUser] == 1) then
		talkState[talkUser] = 0
		selfSay('Pois bem, pegue os itens e retorne.', cid)
	end
	
	return true
end

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

data/npc/blacksmith.xml

<npc name="Blacksmith" script="data/npc/scripts/blacksmith.lua" access="5" lookdir="1">
<health now="1000" max="1000"/>
<look type="54" head="45" body="67" legs="79" feet="10" addons="1"/>
	<parameters>
		<parameter key="message_greet" value="Ola, |PLAYERNAME|. Se voce tiver os itens certos diga {forge armor} e ganhe uma armadura nova." />
	</parameters>
</npc>

 

Script de @Wise , adaptei para sua necessidade.

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.

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.6k

Informação Importante

Confirmação de Termo