Unit Frame

90 Orc Warrior
8010
Does anyone know how to make a basic health frame that shows a group's health?
Reply Quote
90 Gnome Warrior
12325
Are you asking how to code one in lua?

For a single unit frame, you inherit SecureUnitButtonTemplate, attach statusbars, fontstrings, etc to that frame, and then register and react to events to reflect what's happened.

http://www.wowpedia.org/SecureUnitButtonTemplate
http://www.wowpedia.org/Events/Unit_Info

The most basic unit frame:
local f = CreateFrame("Button","BeNiceAndNameYourUnitFrames",UIParent,"SecureUnitButtonTemplate")

f.unit = "player" -- change to unit you want to track

f:SetAttribute("unit",f.unit)
f:SetAttribute("type","target")

f:SetSize(120,32)
f:SetPoint("CENTER")

-- background texture
f.back = f:CreateTexture(nil,"BACKGROUND")
f.back:SetAllPoints(true)
f.back:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Background")

-- health statusbar
f.hp = CreateFrame("StatusBar",nil,f,"TextStatusBar")
f.hp:SetHeight(16)
f.hp:SetPoint("BOTTOMLEFT")
f.hp:SetPoint("BOTTOMRIGHT")
f.hp:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
f.hp:SetStatusBarColor(0,1,0)
f.hp:SetMinMaxValues(0,1)

-- name fontstring
f.name = f:CreateFontString(nil,"ARTWORK","GameFontHighlight")
f.name:SetPoint("TOP",0,-2)
f.name:SetText((UnitName(f.unit)))

-- updates the status bar to new health
local function update(self)
local unit = self.unit
self.hp:SetValue(UnitHealth(unit)/UnitHealthMax(unit))
end

f:SetScript("OnEvent",update)
f:RegisterUnitEvent("UNIT_HEALTH",f.unit)

update(f) -- do an initial update

This will create a very basic unit frame for "player" in the middle of the screen.

If you want it for party1-4 or raid1-40 and you want one for each unit, then the above is just the tip of the iceberg. You need to set up a RegisterUnitWatch to show/hide them (can't do that in combat with a simple :Show() and :Hide()). You need a mechanism for placement. Do you reuse frames for party vs raid or separate? Will you precreate all frames so people joining the party/raid will appear in combat? Also right-click menu support, maybe other information like class as an icon or colored bars. Support for dead/disconnected players. There's a ton of stuff to consider.
Reply Quote
90 Dwarf Mage
10875
oUF can handle a lot of the updating for you, you just create the components and tell the game what they look like and where they're positioned.

http://www.wowinterface.com/downloads/info9994-oUF.html
Reply Quote

Please report any Code of Conduct violations, including:

Threats of violence. We take these seriously and will alert the proper authorities.

Posts containing personal information about other players. This includes physical addresses, e-mail addresses, phone numbers, and inappropriate photos and/or videos.

Harassing or discriminatory language. This will not be tolerated.

Forums Code of Conduct

Report Post # written by

Reason
Explain (256 characters max)
Submit Cancel

Reported!

[Close]