Game Object - Functions
Overviewβ
The game_object
class represents entities within the game world. This class provides a comprehensive set of methods to interact with and retrieve information about game objects, such as players, NPCs, items, and more. Almost everything that we are ever going to interact with is a game_object, so this class is one of the most important ones.
Functionsβ
Validation and Type Checks πβ
is_valid() -> boolean
β
Checks if the game_object
is valid (exists in the game world).
get_type() -> number
β
Returns the type identifier of the object.
get_class() -> number
β
Retrieves the class identifier of the object.
You can use the following code to translate from class ID to class name:
---@type enums
local enums = require("common/enums")
local function call_this_function_inside_the_on_update_callback()
local local_player = core.object_manager.get_local_player()
if not local_player then
return
end
local class_name = enums.class_id_to_name[local_player:get_class()]
core.log("This is my current class: " .. class_name)
end
is_basic_object() -> boolean
β
Determines if the object is a basic game object.
is_player() -> boolean
β
Checks if the object is a player.
is_unit() -> boolean
β
Checks if the object is a unit (NPC, creature, etc.).
is_item() -> boolean
β
Checks if the object is an item.
is_pet() -> boolean
β
Determines if the object is a pet.
is_boss() -> boolean
β
Checks if the object is classified as a boss.
Blizzard's "is_boss" function is not accurate, since only certain bosses like world bosses have this flag enabled. To check if a mob is a boss more accurately, you should use the function provided in the unit_helper module. Here is a code showing how to properly check if a unit is a boss or not:
---@type unit_helper
local unit_helper = require("common/utility/unit_helper")
local function is_boss(target)
return unit_helper:is_boss(target)
end
Identification and Attributes πβ
get_npc_id() -> number
β
Retrieves the NPC ID of the object (if applicable).
This only works for npcs!
get_level() -> number
β
Returns the level of the object.
get_faction_id() -> number
β
Gets the faction ID the object belongs to.
get_target_marker_index() -> number
β
Retrieves the target marker (raid icon) index:
0
: No Icon1
: Yellow 4-point Star2
: Orange Circle3
: Purple Diamond4
: Green Triangle5
: White Crescent Moon6
: Blue Square7
: Red "X" Cross8
: White Skull
get_classification() -> number
β
Gets the classification of the object:
-1
: Unknown0
: Normal1
: Elite2
: Rare Elite3
: World Boss4
: Rare5
: Trivial6
: Minus
get_group_role() -> number
β
Retrieves the group role of the object:
-1
: Unknown / None0
: Tank1
: Healer2
: Damage Dealer
get_name() -> string
β
Returns the name of the object.
get_attack_speed() -> number
β
Retrieves the auto-attack swing speed.
Status and State Checks πβ
get_specialization_id() -> integer
β
Returns the spec_id if the game_object is a player.
get_creature_type() -> integer
β
Returns the type of the creature.
is_dead() -> boolean
β
Checks if the object is dead.
is_visible() -> boolean
β
Checks if the object is visible or not. Also might be useful to check if an object is alive / useful or it's removed from the game (for example, a trap expiring).
is_mounted() -> boolean
β
Determines if the object is mounted.
is_outdoors() -> boolean
β
Checks if the object is outdoors.
is_indoors() -> boolean
β
Checks if the object is indoors.
is_in_combat() -> boolean
β
Checks if the object is currently in combat.
is_moving() -> boolean
β
Determines if the object is moving.
is_dashing() -> boolean
β
Checks if the object is dashing.
is_casting_spell() -> boolean
β
Checks if the object is casting a spell.
is_channelling_spell() -> boolean
β
Determines if the object is channeling a spell.
is_active_spell_interruptable() -> boolean
β
Checks if the currently casting spell can be interrupted.
is_glow() -> boolean
β
Checks if the object is glowing.
set_glow(state: boolean)
β
Sets the glowing state of the object.
Combat and Threat πβ
can_attack(other: game_object) -> boolean
β
Determines if the object can attack another object.
is_enemy_with(other: game_object) -> boolean
β
Checks if the object is an enemy of another object.
is_friend_with(other: game_object) -> boolean
β
Checks if the object is friendly with another object.
get_threat_situation(obj: game_object) -> threat_table
β
Retrieves the threat status relative to another object.
threat_table
Properties:
is_tanking
: Whether the object is tanking.status
: Threat status (0
to3
).threat_percent
: Threat percentage (0
to100
).
Position and Movement πβ
get_position() -> vec3
β
Gets the current position of the object. See vec3
get_rotation() -> number
β
Retrieves the rotation angle of the object.
get_direction() -> vec3
β
Gets the directional vector the object is facing. See vec3
get_movement_speed() -> number
β
Returns the current movement speed.
get_movement_speed_max() -> number
β
Retrieves the maximum possible movement speed.
get_swim_speed_max() -> number
β
Gets the maximum swim speed.
get_flight_speed_max() -> number
β
Returns the maximum flight speed.
get_bounding_radius() -> number
β
Retrieves the bounding radius of the object.
get_height() -> number
β
Returns the height of the object.
get_scale() -> number
β
Gets the scale factor of the object.
Health and Power πβ
get_health() -> number
β
Retrieves the current health value.
get_max_health() -> number
β
Gets the maximum health value.
get_max_health_modifier() -> number
β
Returns any modifiers affecting max health.
get_power(power_type: number) -> number
β
Gets the current power for a specified power type.
Refer to Power Types.
Use the enums power types to check all the possible values. For example:
---@type enums
local enums = require("common/enums")
local function print_player_fury()
local local_player = core.object_manager.get_local_player()
if not local_player then
return
end
local local_player_power = local_player:get_power(enums.power_type.FURY)
core.log("Local Player Current Fury: " .. tostring(local_player_power))
end
get_max_power(power_type: number) -> number
β
Retrieves the maximum power for a specified power type. Same like the previous function , only that this one returns the maximum possible power that the character can have, instead of the current one.
get_xp() -> number
β
Returns the current experience points (XP).
get_max_xp() -> number
β
Gets the maximum XP for the current level.
Casting and Spells πβ
get_active_spell_id() -> number
β
Retrieves the spell ID of the spell currently being cast.
get_active_spell_cast_start_time() -> number
β
Gets the start time of the active spell cast.
get_active_spell_cast_end_time() -> number
β
Retrieves the end time of the active spell cast.
get_active_spell_target() -> game_object
β
Gets the target of the spell currently being cast.
get_active_channel_spell_id() -> number
β
Retrieves the spell ID of the spell currently being channeled.
get_active_channel_cast_start_time() -> number
β
Gets the start time of the active channel spell.
get_active_channel_cast_end_time() -> number
β
Retrieves the end time of the active channel spell.
is_ghost() -> boolean
β
Returns true when the game object is a ghost (not dead but not alive either)
Relationships πβ
get_owner() -> game_object
β
Returns the owner of the object (if any).
get_pet() -> game_object
β
Retrieves the pet of the object (if any).
get_target() -> game_object
β
Gets the current target of the object.
is_party_member() -> boolean
β
Checks if the object is a party member.
Auras and Effects πβ
get_auras() -> table<buff>
β
Retrieves all auras affecting the object.
get_buffs() -> table<buff>
β
Gets all buffs applied to the object. See buffs
get_debuffs() -> table<buff>
β
Retrieves all debuffs applied to the object. see debuffs
buff
Properties:
buff_name
: Name of the buff.buff_id
: Unique identifier.count
: Stack count.expire_time
: When the buff expires.duration
: Total duration.type
: Type identifier.caster
: The object that applied the buff.
get_loss_of_control_info() -> loss_of_control_info
β
Provides information on any loss of control effects.
loss_of_control_info
Properties:
valid
: Whether the info is valid.spell_id
: Associated spell ID.start_time
: Effect start time.end_time
: Effect end time.duration
: Total duration.type
: Type of control loss.
get_total_shield() -> number
β
Returns the total shield applied to the game_object.