Thread Tools Display Modes
09-05-12, 08:46 PM   #1
Talisia
A Deviate Faerie Dragon
Join Date: Sep 2007
Posts: 15
Pitbull Lua Help Please =)

Hi all,

After patch and updating my Pitbull 4 a few pieces of code I use seem to be broken. I got this code from some lovely people here when I came asking for help before. The code is:

Health/Player:
local cur, max = HP(unit), MaxHP(unit)
local PerHP = cur/max
local hr, hg, hb

if (PerHP < 0.5) then
hr = 255
hg = 255 * PerHP * 2
hb = 0
else
hr = 255 * (1 - ((PerHP - 0.5) * 2))
hg = 255
hb = 0
end

and

Health/Target:
local cur, max = HP(unit), MaxHP(unit)
local PerHP = cur/max
local hr, hg, hb

if (PerHP < 0.5) then
hr = 255
hg = 255 * PerHP * 2
hb = 0
else
hr = 255 * (1 - ((PerHP - 0.5) * 2))
hg = 255
hb = 0
end

return "|cff%02x%02x%02x%s - %s%%|r", hr, hg, hb, Short(cur,true), Percent(cur, max)

They don't show as errors on Pitbull but when I use them I keep getting Blizzard Lua error screens popping up and the errors just keeping increasing until I reload the ui. It then starts all over again. I have just disabled them completely.

I have lots of little bits of code for Pitbull (all written by other people! I am clueless but only these 2 seem to be having problems.

I would be most grateful if anybody could take a look and maybe fix them for me =)
  Reply With Quote
09-05-12, 09:29 PM   #2
Shefki
An Aku'mai Servant
 
Shefki's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2007
Posts: 31
Without seeing the errors it's hard to say for sure but it looks to me like your problem occurs when the max hp is zero. Try changing:

Lua Code:
  1. local PerHP = cur/max

to

Lua Code:
  1. local PerHP = max > 0 and cur/max or 0
  Reply With Quote
09-05-12, 10:34 PM   #3
Talisia
A Deviate Faerie Dragon
Join Date: Sep 2007
Posts: 15
I realised as I was typing this message that I should have kept the error to show! I just logged in and enabled them again so I could post it, but so far no error grrr! Always the way =p I only logged in for a few minutes though as its 5am in the morning and I need sleep

I will recreate tomorrow and then try the changes, I'l post the errors for reference and results of the edit, hopefully all fixed though!

Just to add, thank you for such a great addon, I have used it for years now and do not think I could ever play without it =p
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Pitbull Lua Help Please =)

Thread Tools
Display Modes

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