Skip to content

valid_enemy

The valid_enemy function checks if a specified unit is a valid enemy. This function is useful for determining whether a unit can be attacked by the player.

Parameters

  • unit (string): The unit identifier (such as "target", "focus", etc.) to check.

Returns

  • is_valid_enemy (boolean): Returns true if the unit is a valid enemy (i.e., it exists, is not dead or a ghost, and can be attacked by the player), otherwise returns false.

Example Usage in Lua

Here is an example of how to use the valid_enemy function in Lua:

local api = ...

-- Function to check if a unit is a valid enemy and print the result
function PrintValidEnemy(unit)
    local is_valid_enemy = api.valid_enemy(unit)
    if is_valid_enemy then
        print("The unit '" .. unit .. "' is a valid enemy.")
    else
        print("The unit '" .. unit .. "' is not a valid enemy.")
    end
end

-- Example usage: Check if the target unit is a valid enemy
PrintValidEnemy("target")