Existem muitas formas de troca, que muita gente não sabe como colocar, geral as pessoas tentam colocar :
buy(cid,2455,1,0) sell(cid,2455,1,0)
Mas sempre dava a mesma coisa, ele sempre pega o item sem devolver um....
O Script de troca é esse:
elseif talk_state == 1 thenif 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
Explicando:
Mensagem que o player irá dizer para a troca, no caso, eu fiz um exemplo de uma confirmação.
Esse comando serve para remover o item do player, no caso, uma dagger.
No caso, ai está o tal comando de se o player não tiver o item, ele não trocara o item.
Essa mensagem o NPC falará quando o player não tiver o item para a troca.
Esse comando server para adicionar um item ao player, no caço 2 gps pela dagger.
Essa mensagem o NPC irá falar quando vocês trocarem o item.
Importante¹: Se for para adicionar mais de 100 gold tenque colocar 2 comando, exemplo: doPlayerAddItem(cid,2148,43) e doPlayerAddItem(cid,2152,2), no caso o player ganhara 243 gps.
Aqui está um exemplo de um NPC de Troca:
local focus = 0local 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)
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 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
Agora é so configura como eu disse acima....
Agora vou ensinar como o NPC falará com você apenas se você tiver feito alguma quest.
Depois de:
if (msgcontains(msg, 'hi') and focus == 0) and getDistanceToCreature(cid) < 4
Adicione:
and queststatus > 0 then
Ficando:
if (msgcontains(msg, 'hi') and focus == 0) and getDistanceToCreature(cid) < 4 and queststatus > 0 then
Emcima adicione:
queststatus = getPlayerStorageValue(cid,2520)
Esse é o StorageValue da quest, se você fez ela ou não...
Embaixo de:
elseif string.find(msg, '(%a*)bye(%a*)') and getDistanceToCreature(cid) < 4 then selfSay('Bye human.') focus = 0 talk_start = 0 end
Adicione:
else
selfSay('Você não pode conversar comigo sem fazer a quest')
Mensagem que irá aparecer se o player não tiver feito a quest
Pronto, estou acabando meu tutorial por aqui, espero ter ajudado as pessoas a fazerem seu server com mais RPG do que o normal.