can someone fix this?
engine: otserv
engine: otserv
Lua:
focuses = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
target = 0
following = false
attacking = false
focus2 = 0
move = true
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
for i, v in pairs(focuses) do
if(v == 0)then
focuses[i] = cid
break
end
end
end
end
local function removeFocus(cid)
for i, v in pairs(focuses) do
if(v == cid) then
focuses[i] = 0
break
end
end
end
local function isFandD(cid, dist)
if(isFocused(cid) and getDistanceToCreature(cid) < dist)then
return true
end
return false
end
function onThingMove(creature, thing, oldpos, oldstackpos)
end
function onCreatureAppear(creature)
end
function onCreatureDisappear(cid, pos)
if(isFocused(cid)) then
selfSay('Good bye then.', cid)
removeFocus(cid)
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 msgcontains(msg, 'hi') and (not isFocused(cid)) and getDistanceToCreature(cid) < 4 then
selfSay('Hello ' .. creatureGetName(cid) .. '! I Exchange ', cid)
--addFocus(cid)
elseif msgcontains(msg, 'das') then
doPlayerAddItem(cid,2640,1)
elseif isFandD(cid, 4) and string.find(msg, '(%a*)bye(%a*)')then
selfSay('Good bye, ' .. creatureGetName(cid) .. '!', cid)
removeFocus(cid)
move = true
end
end
function onCreatureChangeOutfit(creature)
end
function onThink()
randmove = math.random(1,20)
for i, focus in pairs(focuses) do
if(focus > 0)then
focus2 = focus
move = false
end
if(focus ~= 0)then
if getDistanceToCreature(focus) > 5 then
selfSay('Good bye then.', focus)
removeFocus(focus)
move = true
end
end
end
if(focus2 == 0 or move)then
cx, cy, cz = selfGetPosition()
if randmove == 1 then
nx = cx + 1
end
if randmove == 2 then
nx = cx - 1
end
if randmove == 3 then
ny = cy + 1
end
if randmove == 4 then
ny = cy - 1
end
if randmove >= 5 then
nx = cx
ny = cy
end
moveToPosition(nx, ny, cz)
end
end