Npc Que Troca Itens

gabizinhaah
em Scripts

gabizinhaah

avatar
Artesão
Artesão

INFOS

Grupo: ArtesãoRegistrado: 09/08/07Posts: 138Char no Tibia: Gabii'zinhaa

Galera, alguem tem algum NPC que troque itens?

Por exemplo:Eu falo com ele e ele me da 10 spool of yarn em troca de 100 gss

Agradeço desde ja

obrigada.

Gabii'zinhaa .. ;)



É Meu fan? Então use meu fan bar! ;D

Doidin

Delícia
avatar
Herói
Herói

INFOS

Grupo: HeróiRegistrado: 25/06/08Posts: 723Gênero: MasculinoChar no Tibia: Diiva

Bom irei botar o Script de troca e o Script de NPC completo você edita da maneira que quiser ai na sua casa...

 

Script basico de troca de itens:

elseif talk_state == 1 then
if msgcontains(msg, 'yes') then
itemstatus = doPlayerRemoveItem(cid,2379,1)
if itemstatus == 0 then
selfSay('Sorry, you not have this item.')
else
doPlayerAddItem(cid,2148,2)
selfSay('Thanks for this item.')
end
end
talk_state = 0

NPC Completo:

local focus = 0
local talk_start = 0
local target = 0
local following = false
local 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('Olá ' .. creatureGetName(cid) .. '! Eu te dou um Demon Shield por um Royal Helmet.')
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, 'troca') or msgcontains(msg,'trade') then
if queststatus == -1 then
selfSay('Você quer trocar um royal helmet por um demon shield?')
talk_state = 1

elseif msgcontains(msg, 'exemplo de quest') or msgcontains(msg,'exemplo de quest.') then
selfSay('Você quer trocar um royal helmet por um demon shield?')
talk_state = 2

elseif talk_state == 1 then
if msgcontains(msg, 'yes') then
itemstatus = doPlayerRemoveItem(cid,2498,1) <------ Item que será removido para trocar
if itemstatus == 0 then
selfSay('Sorry, you not have items.')
else
doPlayerAddItem(cid,2520,2) <---- Item que o player ganhará na troca
selfSay('Thanks for items.')
end
end
talk_state = 0

elseif talk_state == 2 then
if msgcontains(msg, 'yes') then
itemstatus = doPlayerRemoveItem(cid,2498,1)
if itemstatus == 0 then
selfSay('Sorry, you not have items.')
else
doPlayerAddItem(cid,2520,2)
selfSay('Thanks for items.')
end
end
talk_state = 0


elseif msgcontains(msg, 'bye') 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

Créditos pelo script: Tryller.

 

Espero ter ajudado...

Meu site pessoal:
https://devmat.com.br/


dono do um sitezinho qualquer

o lado negro da força, bjs

vicentemacedo

avatar
Campones
Campones

INFOS

Grupo: CamponesRegistrado: 28/04/12Posts: 7Char no Tibia: No'have

como eu faço para adicionar mais itens, tipo 2 meat, 3 gs silk, 4 rusty remover.. e assim por diante

tudo isso em troca de um unico item.

Valendo Rep+

Vodkart

Sumus Validus
avatar
Herói
Herói

INFOS

Grupo: HeróiRegistrado: 21/05/10Posts: 3406Gênero: Masculino

como eu faço para adicionar mais itens, tipo 2 meat, 3 gs silk, 4 rusty remover.. e assim por diante

tudo isso em troca de um unico item.

Valendo Rep+

 

usa essa função:

 

function getItemsFromList(items) -- by vodka
local str = ''
if table.maxn(items) > 0 then
for i = 1, table.maxn(items) do
str = str .. items[i][2] .. ' ' .. getItemNameById(items[i][1])
if i ~= table.maxn(items) then str = str .. ', ' end end end
return str
end
function doRemoveItemsFromList(cid,items) -- by vodka
local count = 0
if table.maxn(items) > 0 then
for i = 1, table.maxn(items) do
if getPlayerItemCount(cid,items[i][1]) >= items[i][2] then
count = count + 1 end  end  end
if count == table.maxn(items) then
for i = 1, table.maxn(items) do doPlayerRemoveItem(cid,items[i][1],items[i][2]) end
else return false end
return true end

 

exemplo de uso

 

local list = {{2173,2},{2123,1},{2311,5}}
if doRemoveItemsFromList(cid,list) then
-- funcao que adc item
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,"você precisa ter "..getItemsFromList(list).." para trocar o item.")
end

bossisg.png

vicentemacedo

avatar
Campones
Campones

INFOS

Grupo: CamponesRegistrado: 28/04/12Posts: 7Char no Tibia: No'have

onde eu salvo a

function getItemsFromList(items) -- by vodka

para utilizar no script do npc? '-'