Thread Tools Display Modes
01-11-11, 07:48 AM   #1
Dozi
Guest
Posts: n/a
Predictive Health Bars

Hi,

I am new to lua but have a little bit of basic programming knowledge. I decided to convert my Stuf unit frames layout to oUF, just to see if I could. I am not doing too bad, but I seem to have become a bit stuck with the predictive health bar.

I have attached an image, the green bar next to my unit frame is the predictive health bar. I can't seem to figure out why it is not working. If I loose health the bar does not move.

I have checked the code on the ouf wiki on git hub and ouf_ep on gut hub.

Below is my code to create a Health bar, mana bar and the predictive health bar:

local function CreateHPBar(self, w, h)

local HpBar = CreateFrame("StatusBar", nil, self)
HpBar:SetStatusBarTexture(HPBarTex)
HpBar:SetSize(w, h)
HpBar:SetPoint("TOP", self, "TOP", 0, -Border)
HpBar.frequentUpdates = FreqUpd
HpBar.colorTapping = true
HpBar.Smooth = true

--HPBar Color
if HPClassColour then
HpBar.colorClass = true
HpBar.colorClassNPC = true
else
HpBar.colorSmooth = true
end

self.Health = HpBar
end

local function CreateMPBar(self, w, h)

local MpBar = CreateFrame("StatusBar", nil, self)
MpBar:SetStatusBarTexture(BarTex)
MpBar:SetSize(w, h)
MpBar:SetPoint("BOTTOM", self, "BOTTOM", 0, -Border)

MpBar.frequentUpdates = true
MpBar.colorPower = true
MpBar.Smooth = true

self.Power = MpBar
end

local function CreatePredictedHealthBar(self, w)
-- Position and size
local mhpb = CreateFrame('StatusBar', nil, self.Health)
mhpb:SetPoint('TOPLEFT', self.Health:GetStatusBarTexture(), 'TOPRIGHT', 0, 0)
mhpb:SetPoint('BOTTOMLEFT', self.Health:GetStatusBarTexture(), 'BOTTOMRIGHT', 0, 0)
mhpb:SetWidth(w)
mhpb:SetStatusBarTexture(BarTex)
mhpb:SetStatusBarColor(0, 1, 0.5, 0.25)

local ohpb = CreateFrame('StatusBar', nil, self.Health)
ohpb:SetPoint('TOPLEFT', mhpb:GetStatusBarTexture(), 'TOPRIGHT', 0, 0)
ohpb:SetPoint('BOTTOMLEFT', mhpb:GetStatusBarTexture(), 'BOTTOMRIGHT', 0, 0)
ohpb:SetWidth(w)
ohpb:SetStatusBarTexture(BarTex)
ohpb:SetStatusBarColor(0, 1, 0, 0.25)

-- Register it with oUF
self.HealPrediction = {
-- status bar to show my incoming heals
myBar = mhpb,

-- status bar to show other peoples incoming heals
otherBar = ohpb,

-- amount of overflow past the end of the health bar
maxOverflow = 1.05,
}
end

I call the above functions from the below code:

local function CreateUnitFrame(self, unit)
-- size the overall unit frame
self:SetSize(PlayerWidth + 2 * Border, PlayerHPBarHeight + PlayerMPBarHeight + 3 * Border)

-- Menu
self.menu = CreateMenu
self:RegisterForClicks('AnyDown')
self:SetScript('OnEnter', UnitFrame_OnEnter)
self:SetScript('OnLeave', UnitFrame_OnLeave)
self:SetAttribute('*type2', 'menu')

MoveMe(self)
CreateBackGround(self)
CreateHPBar(self, PlayerWidth, PlayerHPBarHeight)
CreatePredictedHealthBar(self, PlayerWidth)
CreateMPBar(self, PlayerWidth, PlayerMPBarHeight)
CreateCastBar(self, PlayerWidth, PlayerCBHeight)

-- Raid Icon
local RaidIcon = self:CreateTexture(nil, "OVERLAY")
RaidIcon:SetSize(18,18)
RaidIcon:SetPoint("TOP", self.Health, "TOP", 0, 20)

self.RaidIcon = RaidIcon

if UnitSpecific[unit] then
return UnitSpecific[unit](self)
end
end

I hope that it is something really silly that I am missing.
Attached Thumbnails
Click image for larger version

Name:	predicted health gone wrong.jpg
Views:	776
Size:	10.0 KB
ID:	5589  

Last edited by Dozi : 01-11-11 at 08:52 AM.
  Reply With Quote
01-11-11, 09:22 AM   #2
yj589794
A Rage Talon Dragon Guard
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 314
Looking at the code there is nothing that jumps out at me as being wrong.

Which version of oUF are you running?
Would it be possible to post a link to your layout? (It's easier to debug if I can just run the entire thing)


For anyone else looking at this, here is the code Dozi posted in a nicer format:
lua Code:
  1. local function CreateHPBar(self, w, h)
  2.  
  3.     local HpBar = CreateFrame("StatusBar", nil, self)
  4.     HpBar:SetStatusBarTexture(HPBarTex)
  5.     HpBar:SetSize(w, h)
  6.     HpBar:SetPoint("TOP", self, "TOP", 0, -Border)
  7.     HpBar.frequentUpdates = FreqUpd
  8.     HpBar.colorTapping = true
  9.     HpBar.Smooth = true
  10.  
  11.     --HPBar Color
  12.     if HPClassColour then
  13.         HpBar.colorClass = true
  14.         HpBar.colorClassNPC = true
  15.     else
  16.         HpBar.colorSmooth = true
  17.     end
  18.  
  19.     self.Health = HpBar
  20. end
  21.  
  22. local function CreateMPBar(self, w, h)
  23.  
  24.     local MpBar = CreateFrame("StatusBar", nil, self)
  25.     MpBar:SetStatusBarTexture(BarTex)
  26.     MpBar:SetSize(w, h)
  27.     MpBar:SetPoint("BOTTOM", self, "BOTTOM", 0, -Border)
  28.  
  29.     MpBar.frequentUpdates = true
  30.     MpBar.colorPower = true
  31.     MpBar.Smooth = true
  32.  
  33.     self.Power = MpBar
  34. end
  35.  
  36. local function CreatePredictedHealthBar(self, w)
  37.     -- Position and size
  38.     local mhpb = CreateFrame('StatusBar', nil, self.Health)
  39.     mhpb:SetPoint('TOPLEFT', self.Health:GetStatusBarTexture(), 'TOPRIGHT', 0, 0)
  40.     mhpb:SetPoint('BOTTOMLEFT', self.Health:GetStatusBarTexture(), 'BOTTOMRIGHT', 0, 0)
  41.     mhpb:SetWidth(w)
  42.     mhpb:SetStatusBarTexture(BarTex)
  43.     mhpb:SetStatusBarColor(0, 1, 0.5, 0.25)
  44.  
  45.     local ohpb = CreateFrame('StatusBar', nil, self.Health)
  46.     ohpb:SetPoint('TOPLEFT', mhpb:GetStatusBarTexture(), 'TOPRIGHT', 0, 0)
  47.     ohpb:SetPoint('BOTTOMLEFT', mhpb:GetStatusBarTexture(), 'BOTTOMRIGHT', 0, 0)
  48.     ohpb:SetWidth(w)
  49.     ohpb:SetStatusBarTexture(BarTex)
  50.     ohpb:SetStatusBarColor(0, 1, 0, 0.25)
  51.  
  52.     -- Register it with oUF
  53.     self.HealPrediction = {
  54.         -- status bar to show my incoming heals
  55.         myBar = mhpb,
  56.  
  57.         -- status bar to show other peoples incoming heals
  58.         otherBar = ohpb,
  59.  
  60.         -- amount of overflow past the end of the health bar
  61.         maxOverflow = 1.05,
  62.     }
  63. end

lua Code:
  1. local function CreateUnitFrame(self, unit) 
  2.     -- size the overall unit frame
  3.     self:SetSize(PlayerWidth + 2 * Border, PlayerHPBarHeight + PlayerMPBarHeight + 3 * Border)
  4.  
  5.     -- Menu
  6.     self.menu = CreateMenu
  7.     self:RegisterForClicks('AnyDown')
  8.     self:SetScript('OnEnter', UnitFrame_OnEnter)
  9.     self:SetScript('OnLeave', UnitFrame_OnLeave)
  10.     self:SetAttribute('*type2', 'menu')
  11.  
  12.     MoveMe(self)
  13.     CreateBackGround(self)
  14.     CreateHPBar(self, PlayerWidth, PlayerHPBarHeight)
  15.     CreatePredictedHealthBar(self, PlayerWidth)
  16.     CreateMPBar(self, PlayerWidth, PlayerMPBarHeight)
  17.     CreateCastBar(self, PlayerWidth, PlayerCBHeight)
  18.  
  19.     -- Raid Icon
  20.     local RaidIcon = self:CreateTexture(nil, "OVERLAY")
  21.     RaidIcon:SetSize(18,18)
  22.     RaidIcon:SetPoint("TOP", self.Health, "TOP", 0, 20)
  23.  
  24.     self.RaidIcon = RaidIcon
  25.  
  26.     if UnitSpecific[unit] then
  27.         return UnitSpecific[unit](self)
  28.     end
  29. end
  Reply With Quote
01-11-11, 02:17 PM   #3
Dozi
Guest
Posts: n/a
Thank you for your relpy and formatting my code in a nicer way.

I have attached my layout in a zip file.

I am going to strip my code back to just a player frame, health, mana and predictive bar tonight. If I can get that working hopfully I should find what part of my code is breaking things.

Thank you for offering to take a look at my code

Edit: I have just tested my layout after taking out everything apart from a player frame, the predictive bar works. I just need to find the code which messed it up.
Attached Files
File Type: zip ouf_Dozi.zip (16.0 KB, 734 views)

Last edited by Dozi : 01-11-11 at 02:31 PM.
  Reply With Quote
01-12-11, 11:15 AM   #4
Dozi
Guest
Posts: n/a
Everything is working now.

While I was debugging I decided to clean up some code that I was not happy with, and turned several parts of my code into functions.

Thanks for looking over things
  Reply With Quote
01-12-11, 03:45 PM   #5
yj589794
A Rage Talon Dragon Guard
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 314
np, good job in getting it sorted out yourself.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Predictive Health Bars


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