Unit Methods
This document outlines all available methods for the Unit class in the Aurora Framework.
Custom Methods
AddCustomMethod
Aurora.addcustommethod(name: string, handler: fun(unit: Unit, ...): any, options?: table) -> boolean
Registers a new Unit method that can later be called on any Unit instance. Returns true when the method is added successfully.
Cache control: results for custom methods are cached unless you pass
options.cache = false(oroptions.cacheable = false). Use this when the method performs time-sensitive calculations.
-- Example: add a helper that checks if the unit will stop channeling soon
Aurora.addobjectmethod("channelingsoon", function(unit, threshold)
local remains = unit.channelingtimeremains or 0
return remains > 0 and remains <= (threshold or 1.5)
end, {
aliases = {"channelingexpires"}
cache = false
})
-- Usage
if target.channelingsoon(2) then
print("Target stops channeling within 2 seconds")
end
Position & Movement Methods
behind(target)
behind(target: Unit) -> boolean
Check if unit is behind target
infront(target)
infront(target: Unit) -> boolean
Check if unit is in front of target
melee(target)
melee(target: Unit) -> boolean
Check if unit is in melee range of target
distanceto(target)
distanceto(target: Unit | {x: number, y: number, z: number}) -> number
Get distance to target. The target can be either:
- A Unit object
- A position table with x, y, z coordinates
Returns the distance in yards.
distancetoliteral(target)
distancetoliteral(target: Unit) -> number
Get literal distance to target (ignoring combat reach)
futureposition(timeframe)
futureposition(time: Number) -> Array: number
movingtoward(target, options)
movingtoward(target: Unit, options?: number | {angle?: number, duration?: number}) -> boolean
Check if unit is moving toward the specified target.
Parameters:
target: The target unit to check movement towardoptions: Can be either:- A number representing the angle threshold in degrees (default: 30)
- A table with optional properties:
angle: Angle threshold in degrees (default: 30)duration: Minimum duration in seconds the unit must be moving toward target (default: 0)
Returns: true if the unit is moving toward the target within the specified angle threshold and duration, false otherwise.
-- Simple check with default 30-degree threshold
if player.movingtoward(target) then
-- Player is moving toward target
end
-- Check with custom angle threshold
if player.movingtoward(target, 45) then
-- Player is moving toward target within 45 degrees
end
-- Check with angle and duration requirements
if player.movingtoward(target, {angle = 20, duration = 1.5}) then
-- Player has been moving toward target for at least 1.5 seconds within 20 degrees
end
movingawayfrom(target, options)
movingawayfrom(target: Unit, options?: number | {angle?: number, duration?: number}) -> boolean
Check if unit is moving away from the specified target.
Parameters:
target: The target unit to check movement away fromoptions: Can be either:- A number representing the angle threshold in degrees (default: 30)
- A table with optional properties:
angle: Angle threshold in degrees (default: 30)duration: Minimum duration in seconds the unit must be moving away from target (default: 0)
Returns: true if the unit is moving away from the target within the specified angle threshold and duration, false otherwise.
-- Simple check with default 30-degree threshold
if player.movingawayfrom(target) then
-- Player is moving away from target
end
-- Check with custom angle threshold
if player.movingawayfrom(target, 45) then
-- Player is moving away from target within 45 degrees
end
-- Check with angle and duration requirements
if player.movingawayfrom(target, {angle = 20, duration = 1.5}) then
-- Player has been moving away from target for at least 1.5 seconds within 20 degrees
end
predictposition(elapsed)
predictposition(elapsed: number) -> Vector3 | false
Predict the unit's position after a given elapsed time (in seconds). Returns a Vector3 of the predicted position, or false if prediction is not possible.
-- Predict where the player will be in 2 seconds
local futurePos = player.predictposition(2)
if futurePos then
-- Use predicted position for targeting or movement
end
Combat Methods
inarcof(target, size , arc , rotation)
inarcof(target: Unit, size: number, arc: number, rotation: number) -> boolean
Check if unit is within a specific arc of target
inrectangleof(target, width, length, rotation)
inrectangleof(target: Unit, width: number, length: number, rotation: number) -> boolean
Check if unit is within a rectangular area relative to the target.
Parameters:
target: The target unit that defines the center of the rectanglewidth: The width of the rectangle in yardslength: The length of the rectangle in yardsrotation: The rotation angle of the rectangle in degrees
Returns: true if the unit is within the specified rectangular area, false otherwise.
if player.inrectangleof(target, 10, 5, target.rotation) then
-- Player is in the rectangular area
end
enemiesaround(radius)
enemiesaround(radius: number) -> number
Count enemies within radius
haslos(target)
haslos(target: Unit | {x: number, y: number, z: number}) -> boolean
Check line of sight to target
predictlos(target, timeframe)
predictlos(target: Unit, timeframe?: number) -> boolean
Predict line of sight to target at a future position. This method calculates the predicted positions of both units after the specified timeframe and checks if there will be line of sight between them.
Parameters:
target: The target unit to check predicted line of sight totimeframe: Time in seconds to predict ahead (default: 1)
Returns: true if there will be line of sight to the target at the predicted positions, false otherwise.
The method:
- Predicts both units' positions at the future timeframe
- Checks for LOS override settings in Aurora.Enums.OMLists.LosOverride
- Uses TraceLine to verify line of sight between predicted positions
- Accounts for unit height in the calculation
-- Check if we'll have line of sight to target in 2 seconds
if player.predictlos(target, 2) then
-- Pre-cast spell that will land when we have LOS
end
-- Check predicted LOS with default 1 second timeframe
if unit.predictlos(enemy) then
-- Target will be in line of sight soon
end
Unit Interaction Methods
settarget(target)
settarget(target: Unit|nil) -> boolean
Set unit's target
isunit(target)
isunit(target: Unit) -> boolean
Check if unit is the same as target
interact()
interact() -> boolean
Interact with the unit
friendof(otherUnit)
friendof(otherUnit: Unit | string | userdata) -> boolean
Check if the unit is friendly to another unit.
Parameters:
otherUnit: The unit to check friendship with. Can be:- A Unit object
- A string representing a unit ID (e.g., "player", "target")
- A userdata object representing a WoW unit
Returns: true if the units are friendly to each other, false otherwise.
local player = Aurora.UnitManager:Get("player")
local target = Aurora.UnitManager:Get("target")
-- Check if player is friend to target
if player.friendof(target) then
end
-- Check using string unit ID
if player.friendof("target") then
-- Target is a friend
end
-- Check if target is friendly to player
if target.friendof(player) then
-- Target considers player a friend
end
Position & Movement
local target = Aurora.UnitManager:Get("target")
local player = Aurora.UnitManager:Get("player")
-- Check if player is behind target
if player.behind(target) then
-- Use backstab ability
end
-- Check distance and line of sight
if target.distanceto(player) < 30 and target.haslos(player) then
-- Cast ranged ability
end
Combat & Targeting
local player = Aurora.UnitManager:Get("player")
-- Count nearby enemies
local enemyCount = player.enemiesaround(8)
if enemyCount >= 3 then
-- Use AoE ability
end
-- Set target and interact
local enemy = Aurora.UnitManager:Get("target")
if enemy.exists and player.settarget(enemy) then
player.interact()
end
Best Practices
- Always check unit existence before calling methods
- Use appropriate range checks before attempting interactions
- Consider line of sight for ranged abilities
- Cache frequently accessed values for better performance
- Don't assume target existence
- Check range before melee abilities
- Verify line of sight for ranged abilities
- Consider unit type restrictions for certain interactions
Notes
All methods can be called using either:
- Colon syntax:
unit:method(args) - Dot syntax with self:
unit.method(unit, args)
- Most methods return
falseornilon failure - Check return values for critical operations
- Some methods may return multiple values