ObjectManager Lists and Functions
The ObjectManager provides various lists and functions to help you manage and interact with units in the game. This guide will explain how to use these lists and functions effectively in your rotations.
Available Lists
The ObjectManager maintains several lists of units:
LT.Units: All units in the gameLT.Friends: Friendly unitsLT.Enemies: Enemy unitsLT.Attackable: Units that can be attackedLT.Group: Group members (excluding the player)LT.Fgroup: Group members (including the player)LT.Corpses: Dead unitsLT.Pets: Contains PetsLT.PlayerPet: Contains the Player's PetLT.SpecialHealUnits: Contains dedicated Heal units during encountersLT.AreaTriggers: Contains all Area Triggers
Gran
The Group list excludes the player, while Fgroup includes the player. Use Fgroup when you want to consider the player in group-wide calculations.
Only the Group and Fgroup lists have sub-lists for different roles:
TanksHealersDamage
For example:
LT.Group.Tankscontains all tank units in the group (excluding the player)LT.Fgroup.Healerscontains all healer units in the group (including the player, if they are a healer)
In solo play, the player is always included in the Fgroup array and in the respective role array for Fgroup. For instance, if you're playing a damage dealer:
LT.Fgroupwill contain the playerLT.Fgroup.Damagewill contain the playerLT.Fgroup.TanksandLT.Fgroup.Healerswill be empty
The Group array and its sub-arrays will be empty in solo play.
List Functions
loop
The loop function allows you to iterate through a list and perform actions on each unit.
lua
LT.Enemies:loop(function(enemy)
if enemy:hp() < 20 then
print(enemy:name())
end
end)
around
The around function finds units within a specified range of a target unit.
local count, total, nearbyEnemies = LT.Enemies:around(player, 10, function(unit)
return unit:healthpercent() < 50
end)
print(count, total, nearbyEnemies)
sort
The sort function allows you to sort a list based on a custom comparator. It returns a new sorted array containing the units from the list.
local sortedEnemies = LT.Enemies:sort(function(a, b)
return a:distanceto(player) < b:distanceto(player)
end)
The sort function takes a comparator function as an argument. This function should return true if the first argument should be sorted before the second argument.
The sort function can be quite performance-heavy, especially on large lists. It creates a new table and performs multiple comparisons to sort the units. Use it judiciously, and consider caching the results if you need to use the sorted list multiple times in a short period.
size
The size function allows you to quickly determine how many valid units are in a given unit list. This can be particularly useful when you need to know the number of units you're dealing with, such as enemies, friends, or group members.
-- Get the number of enemies
local enemyCount = LT.Enemies:size()
print("Number of enemies:", enemyCount)
The size function is efficient and can be called frequently without significant performance impact. It's a great tool for quick checks or conditional logic in your scripts.
filter
The filter function creates a new list containing all units that pass the test implemented by the provided predicate function.
local lowHealthEnemies = LT.Enemies:filter(function(unit)
return unit:healthpercentage() < 30
end)
Parameters
predicate(function): A function that tests each unit in the list.- The predicate function receives one argument:
unit(Unit): The current unit being tested.
- It should return
trueto include the unit in the result, orfalseto exclude it.
- The predicate function receives one argument:
Return Value
TypedUnitArray: A new list containing all units that pass the test implemented by the predicate function.
Description
The filter function iterates over all units in the list, applying the provided predicate function to each unit. It creates a new list containing only the units for which the predicate function returns true.
The filter function is extremely useful for creating subsets of units based on specific conditions. It's a powerful tool for focusing on relevant targets in your rotation or decision-making logic.
The original list is not modified. filter always returns a new list, leaving the original intact.
While filter is generally efficient, be mindful when using it on very large lists or in tight loops. If you need to use the filtered list multiple times, consider storing the result in a variable rather than calling filter repeatedly with the same predicate.
Using Lists and Functions in Rotations
Here's an example of how to use these lists and functions in combination with the Unit class methods to create a simple rotation:
LT.Fgroup:loop(function(ally)
if ally:hp() < 30 and player:los(ally) and player:distanceto(ally) <= 40 then
-- Cast supportive ability on low health ally
end
end)
When using multiple conditions in a loop, order your checks from least to most computationally expensive. This way, you can potentially skip more expensive calculations if earlier, cheaper checks fail. In the example above:
ally:healthpercent()is relatively cheapplayer:distanceto(ally)is more expensiveplayer:los(ally)(line of sight check) is the most expensive
By putting the line of sight check last, we avoid performing this costly operation unless the other conditions are met.
This optimization technique, known as "short-circuiting," can significantly improve the performance of your rotation, especially when dealing with large numbers of units or frequent updates.