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)) 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)) then --Be sure he's online
closeShopWindow(cid)
end
end
end
local vocations =
{
--[Master sorc] = {Heaven sorc}
[5] = {new_voc = 13},
--[Elder Druid] = {Heaven druid}
[6] = {new_voc = 14},
--[Royal paladin] = {Heaven paladin}
[7] = {new_voc = 15},
--[Elite knight] = {Heaven knight}
[8] = {new_voc = 16}
}
function onCreatureSay(cid, type, msg)
if((msg == "hi") and not (isFocused(cid))) then
selfSay("You can recieve the heaven {promotion} from me.", cid)
addFocus(cid)
elseif((isFocused(cid)) and (msg == "promotion" or msg == "Promotion")) then
if getPlayerVocation(cid) < 8 then
selfSay("Are you sure you would like the heaven promotion?", cid)
else
selfSay("You have already recieved the heaven or hell promotion.", cid)
end
elseif((isFocused(cid)) and (msg == "yes" or msg == "Yes")) then
VOC = vocations[getPlayerVocation(cid)]
if not VOC then
selfSay("You cannot recieve this promotion!", cid)
else
selfSay("You have recieved the heaven promotion!", cid)
setPlayerVocation(cid, VOC.new_voc)
end
end
end
function onThink()
for i, focus in pairs(focuses) do
if(not isCreature(focus)) then
removeFocus(focus)
else
local distance = getDistanceTo(focus) or -1
if((distance > 4) or (distance == -1)) then
removeFocus(focus)
end
end
end
lookAtFocus()
end