local focuses = {}
local playerInfos = {}
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
doTeleportThing(v, "type place here") ----If you want normal NPC take this out. then it wont tp them on exit, you can do alot wit this npc system--
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
end
function onCreatureDisappear(cid)
if(isFocused(cid)) then
selfSay("Good bye...")
removeFocus(cid)
if(isPlayer(cid) == TRUE) then --Be sure he's online
closeShopWindow(cid)
end
end
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)
local msg = string.lower(msg)
-- HOW THIS WORKS!!!!!-----
if not isFocused(cid) and getDistanceTo(cid) < 4 and msgcontains(msg, "hi") then -- if not focused and player says hi, and he is within 3 sqm. --
selfSay("Welcome to the teleport you when you leave npc", cid) -- say this --
addFocus(cid) -- add focus to the person --
return true
end
if isFocused(cid) and getDistanceTo(cid) < 4 and msgcontains(msg, "quest") then -- what ever the player says after they say hi --
selfSay("say bye to teleport!") -- npc says this --
end
if isFocused(cid) and getDistanceTo(cid) < 4 and msgcontains(msg, "bye") then
selfSay("TELEPORT NOW!")
doTeleportThing(cid, "type place here")
removeFocus(cid) -- always add this when you want npc to stop focusing...--
end
end
function onPlayerCloseChannel(cid)
if(isFocused(cid)) then
selfSay("Take care.")
closeShopWindow(cid)
removeFocus(cid)
removeInfo(cid)
end
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("Good Bye.", cid)
closeShopWindow(focus)
removeFocus(focus)
removeInfo(cid)
end
end
end
lookAtFocus()
end