Referenz › Funktionsreferenz › Platform

Platform.unit_health.GetUnitHealthObservation

öffentlich

Aufruf als

addon.Platform:GetUnitHealthObservation(unit, includeMaximum)

Direkt über addon verfügbar; keine Abhängigkeit nötig.

Was sie bewirkt

Lesbare aktuelle Gesundheit und optional die maximale Gesundheit auf unterstützten Clients beobachten. Eine lesbar abwesende Einheit ergibt exists=false. Fehlende, fehlgeschlagene, eingeschränkte oder fehlerhafte Beobachtungen ergeben nil mit einem Grund; sie belegen weder eine abwesende Einheit noch einen Gesundheitswert.

Argumente

NameTypWas sie bewirkt
selfRMPlatformPlattformadapter von Rotation Master (bei Doppelpunktaufrufen implizit).
unitstringEinheitenkennung, deren aktuelle Gesundheit beobachtet werden soll.
includeMaximumboolean | nilTrue beobachtet auch die maximale Gesundheit; false oder nil liest nur die aktuelle Gesundheit.

Rückgabewerte

1table | nilFrisch gelesener lesbarer Datensatz mit exists und, falls vorhanden, der aktuellen Gesundheit. Die maximale Gesundheit ist nur enthalten, wenn sie angefragt wird.
2string | nilGrund aus Richtlinie, Validierung oder Verfügbarkeit für eine nil-Gesundheitsbeobachtung.

Editionen

Integrierte Hilfsfunktionen werden auf jeder Edition registriert. Unterschiedlich ist die Spiel-API, die sie lesen; fehlt eine, weicht die Hilfsfunktion aus oder gibt nil mit einem Grund zurück.

  • Auf dieser Edition nicht verfügbar (den Grund nennt der Tooltip)
  • Nur, solange Blizzards Ersatz für veraltete Funktionen aktiv ist
Spiel-APIClassic EraTBC AnniversaryClassic ProgressionForeverRetail
UnitExistsClassic EraTBC AnniversaryClassic ProgressionForeverRetail
UnitHealthClassic EraTBC AnniversaryClassic ProgressionForeverRetail
UnitHealthMaxClassic EraTBC AnniversaryClassic ProgressionForeverRetail
canaccessvalueClassic EraTBC AnniversaryClassic ProgressionForeverRetail
issecretvalueClassic EraTBC AnniversaryClassic ProgressionForeverRetail

Geheime Werte (Retail und Forever)

Auf Retail und Forever übergibt das Spiel Addons geheime Werte. Diese Hilfsfunktion prüft, was sie liest (addon.Platform:CanReadValue), und gibt statt eines geheimen Werts, den sie nicht vergleichen kann, nil mit einem Grund wie restricted-value zurück. Behandeln Sie nil als nicht verfügbar, nicht als false.

Beispiel

local health = addon.Platform:GetUnitHealthObservation("target", true)
if not health then return nil end
if not health.exists then return false end
if health.maximum == 0 then return nil end
return health.current / health.maximum < 0.2

Abhängigkeiten

Quelle

Platform/unit_health.lua, Zeile 28. Im Spiel schreibgeschützt; Duplizieren erstellt eine bearbeitbare Kopie.

Platform.unit_health.GetUnitHealthObservation(self, unit, includeMaximum)
    local policy=self:GetCombatDataPolicy()
    if policy~='probe' and policy~='restricted' then return nil,'unsupported-policy' end
    if not self:CanReadValue(unit) or not self:CanReadValue(includeMaximum) then return nil,'restricted-value' end
    if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
    if includeMaximum~=nil and type(includeMaximum)~='boolean' then return nil,'invalid-health-query' end
    if type(UnitExists)~='function' then return nil,'missing-api' end
    local existsOk,exists=pcall(UnitExists,unit)
    if not existsOk then return nil,'api-error' end
    if not self:CanReadValue(exists) then return nil,'restricted-value' end
    if exists==nil then return nil,'unit-data-unavailable' end
    if type(exists)~='boolean' then return nil,'invalid-api-result' end
    if not exists then return {exists=false} end
    if type(UnitHealth)~='function' then return nil,'missing-api' end
    local currentOk,current=pcall(UnitHealth,unit)
    if not currentOk then return nil,'api-error' end
    if not self:CanReadValue(current) then return nil,'restricted-value' end
    -- Keep the native proof visible at the arithmetic boundary; the platform
    -- guard above also covers older clients and the issecretvalue predicate.
    if canaccessvalue and not canaccessvalue(current) then return nil,'restricted-value' end
    if current==nil then return nil,'health-data-unavailable' end
    if not finite(current) or current<0 then return nil,'invalid-api-result' end
    local record={exists=true,current=current}
    if includeMaximum then
        if type(UnitHealthMax)~='function' then return nil,'missing-api' end
        local maximumOk,maximum=pcall(UnitHealthMax,unit)
        if not maximumOk then return nil,'api-error' end
        if not self:CanReadValue(maximum) then return nil,'restricted-value' end
        if canaccessvalue and not canaccessvalue(maximum) then return nil,'restricted-value' end
        if maximum==nil then return nil,'health-data-unavailable' end
        if not finite(maximum) or maximum<0 then return nil,'invalid-api-result' end
        record.maximum=maximum
    end
    return record

Zurück zu Funktionsreferenz