TLO:SpawnSort

From the wonderful RedGuides Wiki

Returns the nth spawn that matches your spawn search string, sorting in ascending or descending order by any spawn member.

There's a special case to handle MQ2Nav as well, see examples.

This TLO is added by MQ2SpawnSort

Forms

Type Member Description
spawn SpawnSort[<n>,<asc|desc>,<member>,<spawn search string>] returns the nth spawn that matches your spawn search string, sorting in ascending or descending order by whatever member you like (Level, PctHPs, etc). The member to sort by can be anything on a spawn type, so if you can do ${Spawn[something].<member>}, it'll work. A notable exception is "sub-members", like Class.ShortName. If there's a period in there, it won't work 😔. See examples on the TLO page.
xtarget SpawnSort[<n>,<asc|desc>,<member>,<xtarget-specific spawn search>] If the spawn search string restricts it to NPCs on your xtarget (i.e. includes xtarhater), you can sort by xtarget members, e.g. ${SpawnSort[1,asc,PctAggro,xtarhater].PctAggro, and it will return XTargetType instead of SpawnType. See examples on the TLO page.
groupmember SpawnSort[<n>,<asc|desc>,<member>,group] You can also use "group" in spawn search, and sort by something on groupmember (probably the most useful is PctAggro again). It'll return GroupMemberType too. See examples on the TLO page.

Access to Types

Type Description
groupmember Contains data on a specific group member. Inherits DataType:spawn
spawn A type for spawns
xtarget Contains the data related to your extended target list. Inherits DataType:spawn

Examples

A list of spawn types you can search can be found on Spawn search.

Some random examples:

  • The lowest level player within 100 yards:
    • ${SpawnSort[1,asc,Level,pc radius 100]}
  • The 2nd highest level npc in the zone:
    • ${SpawnSort[2,desc,Level,npc]}
  • Lowest HP group member:
    • ${SpawnSort[1,asc,PctHPs,group]}


  • It handles a a special case for MQ2Nav as well, you can do:
    • /varset closestNPCID ${SpawnSort[1,asc,PathLength,npc radius 1000].ID}
- Which will give you the closest NPC within 1000 yards, but using MQ2Nav path length instead of just straight line distance. PathExists works too, in case you just want to find the first spawn you can navigate to but don't care about distance.


  • If the spawn search string restricts it to NPCs on your xtarget (i.e. includes xtarhater), you can sort by xtarget members, e.g. PctAggro, and it will return XTargetType instead of SpawnType. E.g.
# if any npcs on xtarget have less than 100% aggro
/if (${SpawnSort[1,asc,PctAggro,xtarhater].PctAggro} < 100) {
    /varset npcIDontHaveAggroOnID ${SpawnSort[1,asc,PctAggro,xtarhater].ID}
    # stuff to get aggro back
}
  • You can also use "group" in spawn search, and sort by something on groupmember (probably the most useful is PctAggro again). It'll return GroupMemberType too. e.g.
# if the highest aggro player in the group isn't the main assist
/if (!${SpawnSort[1,desc,PctAggro,group].MainAssist}) {
    /varset playerWithAggroID ${SpawnSort[1,desc,PctAggro,group].ID}
    # heal them or whatever
}


See also