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('See ya.')
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)) and getDistanceToCreature(cid) < 3 then
selfSay('Hello' .. creatureGetName(cid) .. '! 'I Sell ...')
focus = cid
talk_start = os.clock()
end
if string.find(msg, '(%a*)Hi(%a*)') and (focus ~= cid) and getDistanceToCreature(cid) < 3 then
selfSay('Sorry, I'm busy at this moment.')
end
if msgcontains(msg, 'item') and focus == cid then
item = id
count = 1
price = preço
talkcount = 1
shop = 1
selfSay('Do you want to buy a item for ' .. price .. ' Gold Coins?
talk_start = os.clock()
return
end
if string.find(msg, '(%a*)yes(%a*)') and cid == focus and talkcount == 1 then
if shop == 1 then
buy(cid,item,count,price)
talk_start = os.clock()
end
if shop == 2 then
sell(cid,item,count,price)
talk_start = os.clock()
end
if string.find(msg, '(%a*)Bye(%a*)') and focus == cid and getDistanceToCreature(cid) < 3 then
selfSay('Good bye then.')')
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('See ya.')
end
focus = 0
end
end