1. #1
    Deleted

    [lua] health warning

    hey together,

    currently i'm working on a health warning for my ui, found something on the internet and tried to implement it.
    thats the problem it doesn't work

    so this is what i have
    Code:
    -- Health Indicator ---------------------------------------------------------------------------
    -----------------------------------------------------------------------------------------------
    local HPIndicator = zInterfaceTextureTemplate(nil, UIParent, cfg.CISize, cfg.CISize, "CENTER",0,0)
    
    local t = HPIndicator:CreateTexture()
        t:SetParent(HPIndicator)
        t:SetAllPoints(HPIndicator)
        t:SetTexture("Interface\\Addons\\zMedia\\textures\\"..cfg.CombatIndicatorRight)
    
       -- HPIndicator:Hide()
        
    function HPIndicator_OnUpdate(self)
    		local remaining_hp_percent = UnitHealth("player") / UnitHealthMax("player");
    		HPIndicator_CheckStatus(HPIndicator, remaining_hp_percent, cfg.healthWarningPercent)
    	end
    	
    
    function HPIndicator_CheckStatus(frame, percent, trigger)
    	if ((not UnitIsDeadOrGhost("player")) and (not UnitOnTaxi("player")) and (percent <= trigger)) then
    		HPIndicator:Show()
    		return
    	end
    	HPIndicator:Hide()
    end

    all it does is to stay visible all the time.
    for testing purpose cfg.healthWarningPercent is set to 0.8
    can someone please help me fix this

  2. #2
    well you've made 2 functions but you are not calling them so they are not running. you need to create a frame to register for OnUpdate event so that when the event is fired, it will run the HPIndicator_OnUpdate function

    OnUpdate events can be very performance impacting, best to wait for some one who knows how to make them properly :P although if theres a health related event it would be better to register for that instead

  3. #3
    Deleted
    the first half of this snippet is the frame. it's created with a template. Framename is HPIndicator

  4. #4
    Assuming that the template auto-registers an OnUpdate handler, your function still won't get called because it's not a member function of the HPIndicator frame, but is just a standalone function that happens to be similarly named.

  5. #5
    Deleted
    so, what do i have to change?
    i'm no pro in lua, more a newbie.
    was so happy with that function.

  6. #6
    Is this just a lesson in LUA for you or something? Is there a reason you don't want to leverage WeakAuras or something similar to get this done? I know this isn't all that constructive, but just wanted to make sure you knew there are plenty of ways to accomplish this outside of writing your own code.
    Virtualize <Solution> @ Greymane | virtual#1157 | Web | YouTube | Twitter | Facebook
    Hermes - Share cooldown status with raid/party.
    Skada: Survivability - Show when a character died during a specific attempt.
    AffDots - Track the potency of your DoTs on a target.

  7. #7
    Deleted
    i know that there are several other ways to get this task done you could say that it's kind of a lesson for me in lua.
    i'm working on my interface for quit a long time now. never programmed anything before. all this interface compilations or stand alone interfaces like elvui... er... um... i don't like them.
    not that they are not good or anything. all brilliant work, but not my style.

    so i tried it myself. looked at wowprogramming and so on but in all guides they talk about functions like hello world etc. or mathematical functions. never found anything about such advanced tasks with api events or i simply overread it. for me it's hard work in my sparetime to do this. i adapt what i see in snippets to understand what it does but simetimes it's so enigmatic for me.

    as i said, never ever programmed any little bit of code before

  8. #8
    Quote Originally Posted by Vyntrox View Post
    i know that there are several other ways to get this task done you could say that it's kind of a lesson for me in lua.
    i'm working on my interface for quit a long time now. never programmed anything before. all this interface compilations or stand alone interfaces like elvui... er... um... i don't like them.
    not that they are not good or anything. all brilliant work, but not my style.

    so i tried it myself. looked at wowprogramming and so on but in all guides they talk about functions like hello world etc. or mathematical functions. never found anything about such advanced tasks with api events or i simply overread it. for me it's hard work in my sparetime to do this. i adapt what i see in snippets to understand what it does but simetimes it's so enigmatic for me.

    as i said, never ever programmed any little bit of code before
    Understandable. What you're looking to do next is hook in to the Event system. You basically have your frame and you want that frame to monitor for combat events. The specific event you're looking for is called "UNIT_COMBAT".

    Register Event example: http://www.wowpedia.org/API_Frame_RegisterEvent
    Combat Events: http://www.wowpedia.org/Events/Combat

    This is totally untested code, but it should look something like:

    Code:
    t:RegisterEvent("UNIT_COMBAT")
    t:SetScript("OnEvent", HPIndicator_OnUpdate)
    
    function HPIndicator_OnUpdate(self, event, ...)
                    print("EVENT FIRED: " .. event)
    		local remaining_hp_percent = UnitHealth("player") / UnitHealthMax("player");
    		HPIndicator_CheckStatus(HPIndicator, remaining_hp_percent, cfg.healthWarningPercent)
    	end
    Again, this is just off the top of my head but it should hopefully put you in the right direction. Best of luck in your journey.
    Virtualize <Solution> @ Greymane | virtual#1157 | Web | YouTube | Twitter | Facebook
    Hermes - Share cooldown status with raid/party.
    Skada: Survivability - Show when a character died during a specific attempt.
    AffDots - Track the potency of your DoTs on a target.

  9. #9
    Deleted
    hey together,

    looks like i've managed it, somehow...

    Code:
    -- Health Indicator ---------------------------------------------------------------------------
    -----------------------------------------------------------------------------------------------
    local HPIndicator = zInterfaceTextureTemplate(nil, UIParent, cfg.CISize, cfg.CISize, "CENTER",0,0)
        HPIndicator:Hide()
        HPIndicator:RegisterEvent("UNIT_HEALTH")
        
    local t = HPIndicator:CreateTexture()
        t:SetParent(HPIndicator)
        t:SetAllPoints(HPIndicator)
        t:SetTexture("Interface\\Addons\\zMedia\\textures\\"..cfg.CombatIndicatorRight)
    
    HPIndicator:RegisterEvent("UNIT_HEALTH")
    
    function HPWarning_OnUpdate(self, event, ...)
                    --print("EVENT FIRED: " .. event)
    		local remaining_hp_percent = UnitHealth("player") / UnitHealthMax("player");
    		HPWarning_CheckStatus(HPIndicator, remaining_hp_percent, cfg.healthWarningPercent)
    	end
    
    HPIndicator:SetScript("OnEvent", HPWarning_OnUpdate)    
    
    function HPWarning_CheckStatus(frame, percent, trigger)
    	if ((not UnitIsDeadOrGhost("player")) and (not UnitOnTaxi("player")) and (percent <= trigger)) then
    		HPIndicator:Show()
    		return
    	end
    	HPIndicator:Hide()
        end
    thx to all helping hands i got

    greetings
    vyntrox aka tobs

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •