Thread Tools Display Modes
01-04-16, 08:53 AM   #1
EvilMaddness
An Aku'mai Servant
 
EvilMaddness's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2015
Posts: 33
Change bar color for Mind Blast CD in Weakauras

This code will change the color for your Mind Blast Cooldown depending on where you set your Warning Time at. I didn't get any help with this code I basically did trial and error till I was able to get it right. This code should work for Shadow Word: Death cooldown also. Just change the spell name.

Lua Code:
  1. function(progress, r1, g1, b1, a1, r2, g2, b2, a2)
  2.     local start, duration, enable = GetSpellCooldown("Mind Blast")
  3.     local warning_time = 3
  4.     local progress = start + duration - GetTime()
  5.     if start>0 then
  6.         if progress < warning_time then
  7.             return r2, g2, b2, a2
  8.         end
  9.     end
  10.     return r1,g1,b1, a1
  11. end

To make this work in WeakAuras go to the animations tab, main custom, then go down where the color box is ( this is where you set what color you want for your warning time ) put a check on color type will be custom function and then set the code in the custom function box.
__________________
The Maddness Within lua
  Reply With Quote
11-10-16, 01:41 AM   #2
Sabertooth18
A Kobold Labourer
Join Date: Nov 2016
Posts: 1
Hi! hope everything is going well for you. So I have been trying to find scripts that will change the color of a bar depending on my targets health. I found things like

function(progress, r1, g1, b1, a1, r2, g2, b2, a2)
local player_health = UnitHealth("player")
local red, green, blue = 0,0,0
if player_health > 60 then
red, green, blue = 0,1,0
elseif player_health > 20 then
red, green, blue = 0,1,1
else
red, green, blue = 1,0,0
end
return red, green, blue, 1
end

and tried and tried to make it work without any luck.
Do you think you could help me out? Thank you for your time.
  Reply With Quote
11-10-16, 04:11 PM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Your code assumes that UnitHealth() returns a percentage. It does not.

http://wowprogramming.com/docs/api/UnitHealth
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
11-10-16, 06:46 PM   #4
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Like Seerah said, UnitHealth("unit") function does not return the percentage, but returns current health of the unit.

Your code would still work and even view-able on low levels, but it gets harder to recognize as the damage and health values get huge on higher levels.

Thus, you will have to do something like this:

Code:
function(progress, r1, g1, b1, a1, r2, g2, b2, a2)
	local health, healthMax = UnitHealth("player"), UnitHealthMax("player");
	local percentage = health / healthMax * 100;
	local red, green, blue = 0, 0, 0;

	if percentage > 60 then
		red, green, blue = 0, 1, 0;
	elseif percentage > 20 then
		red, green, blue = 0, 1, 1;
	else
		red, green, blue = 1, 0, 0;
	end

	return red, green, blue, 1;
end
Hope this helps
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Change bar color for Mind Blast CD in Weakauras


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off