• You've discovered RedGuides, an EverQuest multi-boxing and scripting community 🧙‍♀️⚙️. We want you to play several EQ characters at once, come join us and say hello! 👋

  • A TLP without truebox has thawed (Very Vanilla ready)
    Frostreaver

Question - NearestSpawn that is NOT a corpse (1 Viewer)

Joined
Mar 20, 2024
RedCents
1,051¢
I am trying to use a mq.TLO.NearestSpawn(npc radius 200) instruction to auto-target whatever nearest mob might be in the near abouts. The problem is that, once the script has successfully picked up a nearby mob and it has been killed, the script runs again and picks up its very corpse instead of the next living NPC within the radius. I have tried to use conditional filters such as IF mq.TLO.NearestSpawn(npc radius 200).PctHPs() > 0 THEN... or IF mq.TLO.NearestSpawn(npc radius 200).Type.NotEqual(CORPSE)() THEN... in order to pick up the second next NearestSpawn, but I cannot make it work.

What is the most efficient way to filter out corpses (both PC and NPC) while using the NearestSpawn TLO, so only living mobs are picked up?

Thanks!
 
I am trying to use a mq.TLO.NearestSpawn(npc radius 200) instruction to auto-target whatever nearest mob might be in the near abouts. The problem is that, once the script has successfully picked up a nearby mob and it has been killed, the script runs again and picks up its very corpse instead of the next living NPC within the radius. I have tried to use conditional filters such as IF mq.TLO.NearestSpawn(npc radius 200).PctHPs() > 0 THEN... or IF mq.TLO.NearestSpawn(npc radius 200).Type.NotEqual(CORPSE)() THEN... in order to pick up the second next NearestSpawn, but I cannot make it work.

What is the most efficient way to filter out corpses (both PC and NPC) while using the NearestSpawn TLO, so only living mobs are picked up?

Thanks!
mq.TLO.NearestSpawn(npc radius 200)
is missing single quotes, it should be
mq.TLO.NearestSpawn('npc radius 200')
'npc' already distinguishes living mobs from corpses (unless it dies right after the call, which can happen)
If you want something more explicit, here is a sample that I use:
Code:
function MobsWithinRange(range)
    local xSpawn = mq.TLO.NearestSpawn('npc targetable')
    while (xSpawn.Name()) do
        if xSpawn.Targetable() and xSpawn.Type() == 'NPC' and not xSpawn.Dead() then
            if xSpawn.Distance3D() < range then
                print(xSpawn.Name() .. ' ' .. xSpawn.Race() .. ' ' .. xSpawn.Distance3D())
                xSpawn.DoTarget()
                mq.delay(100)
                return true
            end
        end
        xSpawn = xSpawn.Next
    end
    return false
end
The print statement makes it rather spammy, but its nice for debugging.
Just comment the print line out in production.

PS Once you start calling Next on a spawn, you leave the NearestSpawn behind. This function only starts with NearestSpawn, then it goes as it pleases, hence the double checking inside the while loop.
PPS I don't use this function anymore, apparently, cause it wastes time.
 
mq.TLO.NearestSpawn(npc radius 200)
is missing single quotes, it should be
mq.TLO.NearestSpawn('npc radius 200')
'npc' already distinguishes living mobs from corpses (unless it dies right after the call, which can happen)
If you want something more explicit, here is a sample that I use:
Code:
function MobsWithinRange(range)
    local xSpawn = mq.TLO.NearestSpawn('npc targetable')
    while (xSpawn.Name()) do
        if xSpawn.Targetable() and xSpawn.Type() == 'NPC' and not xSpawn.Dead() then
            if xSpawn.Distance3D() < range then
                print(xSpawn.Name() .. ' ' .. xSpawn.Race() .. ' ' .. xSpawn.Distance3D())
                xSpawn.DoTarget()
                mq.delay(100)
                return true
            end
        end
        xSpawn = xSpawn.Next
    end
    return false
end
The print statement makes it rather spammy, but its nice for debugging.
Just comment the print line out in production.

PS Once you start calling Next on a spawn, you leave the NearestSpawn behind. This function only starts with NearestSpawn, then it goes as it pleases, hence the double checking inside the while loop.
PPS I don't use this function anymore, apparently, cause it wastes time.

That worked beautiful, thank you!
 
Question - NearestSpawn that is NOT a corpse

Users who are viewing this thread

Back
Top
Cart