• Hail, we're RedGuides. We want you to play six (yes, 6!) EverQuest characters at once. We have scripts and a friendly community to help, please join our playstyle and say hello! 👋
  • We've added LLM sections to our Terms & Rules and Resource Rules, for everyone's sanity & in-game safety.
    Read more
    a. Do not replace your voice with an LLM. This goes for your posts and your scripts. Drafting and editing with a tool is fine, but don't take you out of what you share.
    b. Do not replace your EQ character's voice with an LLM. We don't want scripts that speak over /ooc, /shout or other public channels. This has been an unwritten rule that's kept casino scripts off the site for decades, but we're now compelled to make it clear: keep automated communication private.

    Why Does RG Review Scripts?
    Nearly every LLM-written Lua script we see is making your character do impossible things, and rarely in a way that's beneficial to you. We've seen heavy server hammering, /target over impossible distances when /nav spawn would passively accomplish the same thing, a spawn search that fires 20+ times per second, and other pointless actions that are likely annoying GMs.

    You are welcome to use LLMs as a tool to structure, draft, and edit your work, but please read critically before hitting /lua run

Question - NearestSpawn that is NOT a corpse

Yaguex

Well-known member
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