local focuses = {}
local function isFocused(cid)
for i, v in pairs(focuses) do
if(v == cid) then
return true
end
end
return false
end
local function addFocus(cid)
if(not isFocused(cid)) then
table.insert(focuses, cid)
end
end
local function removeFocus(cid)
for i, v in pairs(focuses) do
if(v == cid) then
table.remove(focuses, i)
break
end
end
end
local function lookAtFocus()
for i, v in pairs(focuses) do
if(isPlayer(v) == TRUE) then
doNpcSetCreatureFocus(v)
return
end
end
doNpcSetCreatureFocus(0)
end
---
function onCreatureAppear(cid)
end
function onCreatureDisappear(cid)
if(isFocused(cid)) then
selfSay("Hmph!")
removeFocus(cid)
if(isPlayer(cid) == TRUE) then --Be sure he's online
closeShopWindow(cid)
end
end
end
function onCreatureSay(cid, type, msg)
if((msg == "hi") and not (isFocused(cid))) then
addFocus(cid)
selfSay("Hello, ".. getCreatureName(cid) .." I can repair your {soft boots}", cid)
elseif((isFocused(cid)) and (msg == "soft boots")) then
selfSay("Do you want that I repair your soft boots?", cid)
talk_state = 1
elseif((isFocused(cid)) and (msg == "yes")) and talk_state == 1 then
if doPlayerRemoveMoney(cid,300000) == 1 then
if doPlayerRemoveItem(cid,6530,1) == 1 then
doPlayerAddItem(cid,6132,1)
doPlayerSendTextMessage(cid,22,"Your pair of soft boots has been repaired.", cid)
else
doPlayerSendCancel(cid, "You need 30cc to repair your soft boots.", cid)
end
else
doPlayerSendCancel(cid, "You have not a worn soft boots.", cid)
end
elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
selfSay("Goodbye!", cid)
closeShopWindow(cid)
removeFocus(cid)
end
end
function onPlayerCloseChannel(cid)
if(isFocused(cid)) then
selfSay("Hmph!")
removeFocus(cid)
end
end
function onPlayerEndTrade(cid)
selfSay("It was a pleasure doing business with you.", cid)
end
function onThink()
for i, focus in pairs(focuses) do
if(isCreature(focus) == FALSE) then
removeFocus(focus)
else
local distance = getDistanceTo(focus) or -1
if((distance > 4) or (distance == -1)) then
selfSay("Hmph!")
closeShopWindow(focus)
removeFocus(focus)
end
end
end
lookAtFocus()
end