in_angle
The in_angle function checks if a specified unit is within a given angle relative to another unit. This function is useful for determining if a unit is within a certain directional cone from another unit.
Parameters
unit(string): The unit identifier (such as "player", "target", "focus", etc.) from which to measure the angle.otherUnit(string): The unit identifier of the other unit to check the angle against.angle(number): The angle in degrees within which to check if the other unit is located.
Returns
is_within_angle(boolean): Returnstrueif the other unit is within the specified angle relative to the unit, otherwise returnsfalse.
Example Usage in Lua
Here is an example of how to use the in_angle function in Lua:
local api = ...
-- Function to check if a unit is within a specified angle relative to another unit
function CheckInAngle(unit, otherUnit, angle)
local is_within_angle = api.in_angle(unit, otherUnit, angle)
if is_within_angle then
print("The unit '" .. otherUnit .. "' is within " .. angle .. " degrees of the unit '" .. unit .. "'.")
else
print("The unit '" .. otherUnit .. "' is not within " .. angle .. " degrees of the unit '" .. unit .. "'.")
end
end
-- Example usage: Check if the target is within 45 degrees of the player
CheckInAngle("player", "target", 45)