Bom... eu percebi q tinha muita gente pedind de como configurar os seus npcs e vou ensinar aki de como configurar alguns tipos de npcs..
Como fazer um npc vender itens diferentes:
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 ((string.find(msg, '(%a*)hi(%a*)')) and (focus == 0)) Oq ele vai falar ao npc and getDistanceToCreature(cid) < 3 then
selfSay('Hello ' .. creatureGetName(cid) .. '! I sell ham, meat, carrots, apples, brown breads, brown mushrooms and eggs (everything for 9gps).') Oq o npc irá responder
focus = cid
talk_start = os.clock()
end
if string.find(msg, '(%a*)hi(%a*)') and (focus ~= cid) and getDistanceToCreature(cid) < 3 then
selfSay('Sorry, ' .. creatureGetName(cid) .. '! I talk to you in a minute.')
end
if msgcontains(msg, 'brown bread') and focus == cid then
(id do item, quantidade, e quantos gps) buy(cid,3540,1,8)
talk_start = os.clock()
end
if msgcontains(msg, 'ham') and focus == cid then
buy(cid,3520,1,8)Buy é comprar do npc sell é vender para o npc..
talk_start = os.clock()
end
if msgcontains(msg, 'carrot') and focus == cid then
buy(cid,3533,1,8)
talk_start = os.clock()
end
if msgcontains(msg, 'meat') and focus == cid then
buy(cid,3515,1,8)O
talk_start = os.clock()
end
if msgcontains(msg, 'apple') and focus == cid then
buy(cid,3523,1,8)
talk_start = os.clock()
end
if msgcontains(msg, 'brown mushroom') and focus == cid then
buy(cid,3660,1,8)
talk_start = os.clock()
end
if msgcontains(msg, 'egg') and focus == cid then
buy(cid,3544,1,8)
talk_start = os.clock()
end
if string.find(msg, '(%a*)bye(%a*)') and focus == cid and getDistanceToCreature(cid) < 3 then
selfSay('Good bye, ' .. creatureGetName(cid) .. '!')
focus = 0
talk_start = 0
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
end
Bom espero ter ajudado!