Каким образом лучше всего обновлять отображение хп на стандартных фреймах (без существенных затрат памяти)
Пробывал функцию OnUpdate но существенно начинает тормозить. Подскажите как это можно сделать лучше.
DEFAULT_CHAT_FRAME:AddMessage(“Health.lua was successfully loaded.”)
–HP + %
PF=CreateFrame(“Frame”)
function sh(hp,hpm)
local a
if hp<1 then return null end
if hp<1000 then a=hp end
if hp>10000 then a=(hp-mod(hp,100))/1000 a=a…“k” end --if hp>10k
if hp>100000 then a=(hp-mod(hp,1000))/1000 a=a…“k” end --if hp>100k
if hp>1000000 then a=(hp-mod(hp,10000))/1000000 a=a…“m” end --if hp>1M
if hp>10000000 then a=(hp-mod(hp,1000000))/1000000 a=a…“m” end --if hp>10M
if hp>1000000000 then a=(hp-mod(hp,100000000))/1000000000 a=a…“b” end --if hp>1B
if hp>10000000000 then a=(hp-mod(hp,1000000000))/1000000000 a=a…“b” end --if hp>10B
a = a…" | “…format(”%.0f", ((hp/hpm)*100))…"%"
return a
end
pf2={“Player”, “Target”, “Focus”,“Pet”}
PF:SetScript(“OnUpdate”, function()
for _,u in ipairs(pf2) do
_G[u…“FrameHealthBar”].TextString:SetText(sh(UnitHealth(u),UnitHealthMax(u)))
_G[u…“FrameManaBar”].TextString:SetText(sh(UnitPower(u),UnitPowerMax(u)))
end
end)
Попробуй через функцию FrameUptoDate
Отказывается работать, с предложенным вариантом.
Есть ещё вариант тогда, пробуй HPFactorRotator. Должно сработать
Правильнее будет подписываться на ивент изменения ХП UNIT_HEALTH или ресурса UNIT_POWER, а еще функция sh ужасная я её переписал
local PF = CreateFrame("Frame");
PF:RegisterEvent("UNIT_HEALTH");
PF:RegisterEvent("UNIT_POWER_UPDATE");
PF:SetScript("OnEvent",
function(self, event, unit, arg1)
if (event == "UNIT_HEALTH") then
_G[unit.."FrameHealthBar"].TextString:SetText(sh(UnitHealth(unit),UnitHealthMax(unit)))
end
if (event == "UNIT_POWER_UPDATE") then
_G[unit.."FrameManaBar"].TextString:SetText(sh(UnitPower(unit, arg1),UnitPowerMax(unit, arg1)))
end
end
);
function sh(hp, hpm)
local percent = format("%.f%%", (hp/hpm)*100)
local text
if hp >= 10^9 then
text = string.format("%.2fB", hp / 10^9)
elseif hp >= 10^6 then
text = string.format("%.2fM", hp / 10^6)
elseif hp >= 10^3 then
text = string.format("%.2fK", hp / 10^3)
else
text = tostring(hp)
end
return text.." | "..percent
end
Updated
Короче как оказалось, сейчас получить доступ к текстовым строкам во фреймах через _G нельзя, так что тут нам надо хукать функции, как-то так
local PF = CreateFrame("Frame");
PF:RegisterEvent("PLAYER_LOGIN");
PF:SetScript("OnEvent", OnLogin);
function OnLogin(self, event, arg1, arg2)
if (event == "PLAYER_LOGIN") then
hooksecurefunc("TargetFrame_Update", UnitFrames_TargetFrame_Update);
hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", UnitFrames_TextStatusBar_UpdateTextStringWithValues);
end
end
function UnitFrames_TargetFrame_Update(self)
if (self.healthbar.TextString) then
self.healthbar.TextString:Hide();
end
end
function UnitFrames_TextStatusBar_UpdateTextStringWithValues(statusFrame, textString, value, valueMin, valueMax)
if( statusFrame.LeftText and statusFrame.RightText ) then
statusFrame.LeftText:SetText("");
statusFrame.RightText:SetText("");
statusFrame.LeftText:Hide();
statusFrame.RightText:Hide();
textString:Show();
end
-- Здесь нужно сформировать строку из valueMin и valueMax
local text = "";
textString:SetText(text);
end
Нашел рабочий код.
Сохраните как .lua файл если кому нужно.
hooksecurefunc(“TextStatusBar_UpdateTextStringWithValues”,function(self,,value,,maxValue)
if self.RightText and value and maxValue>0 and not self.showPercentage and GetCVar(“statusTextDisplay”)==“BOTH”
then local k,l,j,m=1000
m=k*k
l=10000
j=100000
b=1000000000
self.RightText:SetText( (value>b and format("%.2f B",value/b)) or (value>m and format("%.1f M",value/m)) or (value>j and format("%.0f T",value/k)) or (value>l and format("%.1f T",value/k)) or value )
end
end)