Olá amigo!
Ai vai o código do NPC, espero que te ajude.
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)
-- greeting phrase
if string.find(msg, '(%a*)hi(%a*)') and focus == 0 and string.len(msg) == 2 and getDistanceToCreature(cid) < 4 then
selfSay('Oi ' .. creatureGetName(cid) .. '! Eu compro as seguintes joias:Black Pearl , White Pearl , Small Amethyst , Small Emerald ,Small Ruby,Small Diamons,Small Sapphire.')
selfSay('Diga info para saber informações sobre o npc')
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()
-- Mensages:
buy_error = 'Sorry, you dont have enough money.'
buy_ok = 'Here you are.'
buy_no = 'Ok. Maybe another time.'
--
sell_error = 'Sorry, you dont have that item.'
sell_ok = 'Thanks for this item.'
sell_no = 'Ok. Maybe another time.'
--
-- Joias
if msgcontains(msg, 'sell') and msgcontains(msg, 'small diamond') or msgcontains(msg, 'small diamonds') then
bs,itemid,count,subtype,price,iscountable,article,name,plural = 'sell',2145,getCountNumber(msg),1,300,1,'a','small diamond','small diamonds'
sendMsgBuySell(cid,itemid,count,price,article,name,plural,bs)
talk_state = 786
elseif msgcontains(msg, 'sell') and msgcontains(msg, 'white pearl') or msgcontains(msg, 'white pearls') then
bs,itemid,count,subtype,price,iscountable,article,name,plural = 'sell',2143,getCountNumber(msg),1,160,1,'a','white pearl','white pearls'
sendMsgBuySell(cid,itemid,count,price,article,name,plural,bs)
talk_state = 786
elseif msgcontains(msg, 'sell') and (msgcontains(msg, 'small emerald') or msgcontains(msg, 'small emerald')) then
bs,itemid,count,subtype,price,iscountable,article,name,plural = 'sell',2149,getCountNumber(msg),1,500,1,'a','small emerald','small emeralds'
sendMsgBuySell(cid,itemid,count,price,article,name,plural,bs)
talk_state = 786
elseif msgcontains(msg, 'sell') and msgcontains(msg, 'small amethyst') or msgcontains(msg, 'small amethysts') then
bs,itemid,count,subtype,price,iscountable,article,name,plural = 'sell',2150,getCountNumber(msg),1,400,1,'a','small amethyst','small amethysts'
sendMsgBuySell(cid,itemid,count,price,article,name,plural,bs)
talk_state = 786
elseif msgcontains(msg, 'sell') and msgcontains(msg, 'small sapphire') or msgcontains(msg, 'small sapphires') then
bs,itemid,count,subtype,price,iscountable,article,name,plural = 'sell',2146,getCountNumber(msg),1,300,1,'a','small sapphire','small sapphires'
sendMsgBuySell(cid,itemid,count,price,article,name,plural,bs)
talk_state = 786
elseif msgcontains(msg, 'sell') and msgcontains(msg, 'black pearl') or msgcontains(msg, 'black pearls') then
bs,itemid,count,subtype,price,iscountable,article,name,plural = 'sell',2144,getCountNumber(msg),1,280,1,'a','black pearl','black pearls'
sendMsgBuySell(cid,itemid,count,price,article,name,plural,bs)
talk_state = 786
elseif msgcontains(msg, 'sell') and msgcontains(msg, 'small ruby') or msgcontains(msg, 'small rubys') then
bs,itemid,count,subtype,price,iscountable,article,name,plural = 'sell',2147,getCountNumber(msg),1,500,1,'a','small ruby','small rubys'
sendMsgBuySell(cid,itemid,count,price,article,name,plural,bs)
talk_state = 786
----------------------
elseif msgcontains(msg, 'info') then
selfSay('Npc feito por Upking preços = a tibia global')
talk_state = 786
-----------------------
elseif talk_state == 786 then
if msgcontains(msg, 'yes') or msgcontains(msg, 'no') or msgcontains(msg, 'info') then
if bs == 'buy' then
buyItem(cid,itemid,count,subtype,price,iscountable,name,plural,buy_error,buy_ok,
buy_no,msg)
else
sellItem(cid,itemid,count,subtype,price,iscountable,sell_error,sell_ok,sell_no,m
sg)
end
talk_state = 0
end
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 focus > 0 then
x, y, z = creatureGetPosition(focus)
myx, myy, myz = selfGetPosition()
if ((myy-y==0) and (myx-x<=0 and myx-x>=-4)) then
selfTurn(1)
end
if ((myy-y==0) and (myx-x>=0 and myx-x<=4)) then
selfTurn(3)
end
if ((myx-x==0) and (myy-y<=0 and myy-y>=-4)) then
selfTurn(2)
end
if ((myx-x==0) and (myy-y>=0 and myy-y<=4)) then
selfTurn(0)
end
if ((myy-y==-2) and (myx-x>=-1 and myx-x<=1)) then
selfTurn(2)
end
if ((myy-y==2) and (myx-x>=-1 and myx-x<=1)) then
selfTurn(0)
end
if ((myx-x==2) and (myy-y>=-1 and myy-y<=1)) then
selfTurn(3)
end
if ((myx-x==-2) and (myy-y>=-1 and myy-y<=1)) then
selfTurn(1)
end
if ((myy-y==-3) and (myx-x>=-2 and myx-x<=2)) then
selfTurn(2)
end
if ((myy-y==3) and (myx-x>=-2 and myx-x<=2)) then
selfTurn(0)
end
if ((myx-x==3) and (myy-y>=-2 and myy-y<=2)) then
selfTurn(3)
end
if ((myx-x==-3) and (myy-y>=-2 and myy-y<=2)) then
selfTurn(1)
end
if ((myy-y==-4) and (myx-x>=-3 and myx-x<=3)) then
selfTurn(2)
end
if ((myy-y==4) and (myx-x>=-3 and myx-x<=3)) then
selfTurn(0)
end
if ((myx-x==4) and (myy-y>=-3 and myy-y<=3)) then
selfTurn(3)
end
if ((myx-x==-4) and (myy-y>=-3 and myy-y<=3)) then
selfTurn(1)
end
end
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




info
Grupo: Campones
Registrado: 30/07/09
Posts: 0
Reputação: 0
Char no Tibia: HIght
Queria um npc que comprasse todo tipow de Diamantes
Red Gem
Yellow Gem
Small Shappire
essas coisa esses diamantes
se ja tiver algum poderia me mandar o link? obg