CheckInteractDistance

From Warcraft Wiki
Jump to navigation Jump to search

Returns true if the player is in range to perform a specific interaction with the unit.

inRange = CheckInteractDistance(unit, distIndex)

Arguments

unit
string : UnitId - The unit to compare distance to.
distIndex
number - A value from 1 to 5:
1 = Compare Achievements, 28 yards
2 = Trade, 8 yards
3 = Duel, 7 yards
4 = Follow, 28 yards
5 = Pet-battle Duel, 7 yards

Returns

inRange
boolean - 1 if you are in range to perform the interaction, nil otherwise.

Details

  • If "unit" is a hostile unit, the return values are the same. But you obviously won't be able to do things like Trade.

Example

if ( CheckInteractDistance("target", 4) ) then
  FollowUnit("target");
else
  -- we're too far away to follow the target
end

Patch changes

Dragonflight Hotfix (2023-12-11): Partially unrestricted. Querying enemy units while in combat is once again permitted. (Build: 10.2.0.52485)
Dragonflight Hotfix (2023-11-16): Protected. May no longer be called in combat by insecure code. (Build: 10.2.0.52188)