Not_Wilson Posted July 31, 2016 Share Posted July 31, 2016 I'm trying to make a certain character blink red over and over ntil his health is brought up above a certain threshold. However, with the code I have, it'll only blink once and only when the health updates. local function OnHealthDelta(inst, data) if data.newpercent <= .25 then --Blip for 1/5 of a second inst.AnimState:SetMultColour(1,.5,.5,1) inst:DoTaskInTime((1 *.5), function(inst) inst.AnimState:SetMultColour(1,1,1,1) end) elseif data.newpercent >= .25 then inst.AnimState:SetMultColour(1,1,1,1) end end inst:ListenForEvent("healthdelta", OnHealthDelta) --This goes in master_postinit Is there away to make a stategraph, by chance? Link to comment Share on other sites More sharing options...
Not_Wilson Posted July 31, 2016 Author Share Posted July 31, 2016 Got it. If you want the code, here you go in case if you wanna make it obvious that a character is low on health. Thank you @Neutral_Steve for the help. Slap this in above common_postinit local function DoPain(inst) -- R G B A inst.AnimState:SetMultColour(1,.25,0,1) inst:DoTaskInTime((1/2 *.5), function(inst) inst.AnimState:SetMultColour(1,1,1,1) end) end local function OnHealthDelta(inst, data) local health = inst.components.health:GetPercent() if health <= .25 and not inst:HasTag("hascurrentpain") then inst.task = inst:DoPeriodicTask(1/2, DoPain) inst:AddTag("hascurrentpain") elseif health >= .25 then if inst.task ~= nil then inst.task:Cancel() end inst:RemoveTag("hascurrentpain") inst.AnimState:SetMultColour(1,1,1,1) end end Put this in onbecamehuman(inst) and master_postinit inst:ListenForEvent("healthdelta", OnHealthDelta) and onbecameghost(inst) inst:RemoveEventCallback("healthdelta", OnHealthDelta) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now