Call 'break' to make that loop stop and for it to move on.
e.g:
Code:
for _,unit in pairs(pUnit:GetInRangeUnits()) do
if unit:GetAreaId() == 1 and unit:GetEntry() == 525003 then
if unit:IsAlive() then
-- Unit is alive
-- Do something
break
else
-- Unit is dead, do something
break
end
end
end
Alternatively you can do something similar with a function:
Code:
function CreatureSpawn(pUnit, Event)
pUnit:RegisterEvent("HandleStuff", 1000, 0)
end
function HandleStuff(pUnit)
local result = DoStuff(pUnit) -- We call the function, which will return a value
if result == 1 then
-- the unit was alive that we found
elseif result == 2 then
-- the unit was dead that we found
elseif result == 0 then
-- nothing was found
end
end
function DoStuff(pUnit)
for _,unit in pairs(pUnit:GetInRangeUnits()) do
if unit:GetAreaId() == 1 and unit:GetEntry() == 525003 then
if unit:IsAlive() then
-- Unit is alive
-- Do something
return 1
else
-- Unit is dead, do something
return 2
end
end
end
return 0
end