unitframes: add 40y-rangecheck

This commit is contained in:
shagu
2017-04-16 16:07:41 +02:00
parent 31012d4921
commit 0b3e9df0d9
11 changed files with 115 additions and 1 deletions
+43
View File
@@ -1,6 +1,7 @@
pfUI.api = { }
pfUI.api._G = getfenv(0)
local _G = getfenv(0)
-- [ strsplit ]
-- Splits a string using a delimiter.
-- 'delimiter' [string] characters that will be interpreted as delimiter
@@ -14,6 +15,48 @@ function pfUI.api.strsplit(delimiter, subject)
return unpack(fields)
end
-- [ UnitInRange ]
-- Returns whether a party/raid member is nearby. It uses spells with a distance of around 40 yards.
-- unit [string] A unit to query (string, unitID)
-- return: [bool] "1" if in range otherwise "nil"
local RangeCache = {}
function pfUI.api.UnitInRange(unit)
if not UnitExists(unit) or not UnitIsVisible(unit) then
return nil
end
if CheckInteractDistance(unit, 4) then
return 1
else if not pfUI.rangecheck or not pfUI.rangecheck.slot then
return nil
else
-- Extended Range Check
if not RangeCache[unit] or RangeCache[unit].time + pfUI.rangecheck.interval < GetTime() then
RangeCache[unit] = {}
RangeCache[unit].time = GetTime()
local noswitch = true
if not UnitIsUnit("target", unit) then
TargetUnit(unit)
noswitch = false
end
if IsActionInRange(pfUI.rangecheck.slot) == 1 then
RangeCache[unit].range = 1
else
RangeCache[unit].range = nil
end
if not noswitch then
TargetLastTarget()
end
end
return RangeCache[unit].range
end
end
end
-- [ strvertical ]
-- Creates vertical text using linebreaks. Multibyte char friendly.
-- 'str' [string] String to columnize.