Files
wow-weakauras/Complete Projects/Legion/TSU - EnemyPlayerHealth.lua
2024-08-24 22:43:07 +02:00

143 lines
3.8 KiB
Lua

--TSU
--UNIT_HEALTH NAME_PLATE_UNIT_ADDED NAME_PLATE_UNIT_REMOVED
function(allstates, e, unit)
if e == "NAME_PLATE_UNIT_ADDED" then
if UnitExists(unit) then
if UnitIsPlayer(unit) then
if UnitIsEnemy("player", unit) then
local hp = UnitHealth(unit)
local maxHp = UnitHealthMax(unit)
local hppp = aura_env.round(hp / maxHp * 100, 2)
local shortHP = aura_env.shorten(hp)
local shortmaxHP = aura_env.shorten(maxHp)
local name = UnitName(unit)
local class = select(3, UnitClass(unit))
local r, g, b, a = aura_env.classColor(class)
allstates[unit] =
{
changed = true,
show = true,
resort = true,
progressType = "static",
value = hp,
total = maxHp,
index = hppp,
name = name,
hppp = hppp,
shortHP = shortHP,
shortmaxHP = shortmaxHP,
r = r, g = g, b = b, a = a,
}
return true
end
end
end
elseif e == "NAME_PLATE_UNIT_REMOVED" then
if UnitExists(unit) then
if UnitIsPlayer(unit) then
if UnitIsEnemy("player", unit) then
if allstates[unit] then
allstates[unit].show = false
allstates[unit].changed = true
return true
end
end
end
end
elseif e == "UNIT_HEALTH" then
if UnitExists(unit) then
if UnitIsPlayer(unit) then
if UnitIsEnemy("player", unit) then
if allstates[unit] then
local hp = UnitHealth(unit)
local maxHp = UnitHealthMax(unit)
local shortHP = aura_env.shorten(hp)
local shortmaxHP = aura_env.shorten(maxHp)
print(hp, maxHp)
allstates[unit].value = hp
allstates[unit].total = maxHP
allstates[unit].shortHP = shortHP
allstates[unit].shortmaxHP = shortmaxHP
allstates[unit].show = true
allstates[unit].changed = true
return true
end
end
end
end
end
end
--ANIMATION
function()
if aura_env.statee then
return aura_env.statee.r, aura_env.statee.g, aura_env.statee.b, aura_env.statee.a
end
end
--INIT
aura_env.round = function(var, n)
if (n) then
var = math.floor((var * 10^n) + 0.5) / (10^n)
else
var = math.floor(var+0.5)
end
return var
end
aura_env.shorten = function(val)
local function round(var, n)
if (n) then
var = math.floor((var * 10^n) + 0.5) / (10^n)
else
var = math.floor(var+0.5)
end
return var
end
local n = 2
if val < 1e3 then
return round(val, n)
elseif val > 1e3 and val < 1e6 then
return round(val / 1e3, n) .. "k"
elseif val > 1e6 and val < 1e9 then
return round(val / 1e6, n) .. "M"
elseif val > 1e9 then
return round(val / 1e9, n) .. "G"
end
end
aura_env.classColor = function(class)
if class == "1" then return 0.78, 0.61, 0.43, 1 elseif
class == "2" then return 0.96, 0.55, 0.73, 1 elseif
class == "3" then return 0.67, 0.83, 0.45, 1 elseif
class == "4" then return 1, 0.96, 0.41, 1 elseif
class == "5" then return 1, 1, 1, 1 elseif
class == "6" then return 0.77, 0.12, 0.23, 1 elseif
class == "7" then return 0, 0.44, 0.87, 1 elseif
class == "8" then return 0.25, 0.78, 0.92, 1 elseif
class == "9" then return 0.53, 0.53, 0.93, 1 elseif
class == "10" then return 0, 1, 0.59, 1 elseif
class == "11" then return 1, 0.49, 0.04, 1 elseif
class == "12" then return 0.64, 0.19, 0.79, 1 else
return 1, 1, 1, 1 end
end
aura_env.round = function(var, n)
if (n) then
var = math.floor((var * 10^n) + 0.5) / (10^n)
else
var = math.floor(var+0.5)
end
return var
end
aura_env.grad = function(c)
--c expected as [0, 1]
if c > 0.5 then
c = 1 - (2 * (c - 0.5))
return c, 1, 0, 1
else
c = c * 2
return 1, c, 0, 1
end
end
aura_env.range = function(val, min, max, max2)
val = 1 - (((max - val) / (max - min)) * max2)
return val
end