So I´ve run across this addon example/tutorial from World of Warcraft Programming: A Guide and Reference for Creating WoW Addons.
http://wowprogramming.com/chapters/second-edition/14
After searching the website forums I cant seem to get it to work correctly on 6.2.3, even with the changes:
All CombatTrackerFrameText:SetText calls should be replaced by CombatTrackerFrame_Text:SetText
GetNumPartyMembers() function used in CombatTracker_ReportDPS() was removed in 5.0.4 patch. You can use GetNumGroupMembers() or IsInGroup() function instead.
Looking for any insights, changes or working version of that addon. Apreciate any help.
LUA
Code:
-- Set up some local variables to track time and damage
local start_time = 0
local end_time = 0
local total_time = 0
local total_damage = 0
local average_dps = 0
function CombatTracker_OnLoad(frame)
frame:RegisterEvent("UNIT_COMBAT")
frame:RegisterEvent("PLAYER_REGEN_ENABLED")
frame:RegisterEvent("PLAYER_REGEN_DISABLED")
frame:RegisterForClicks("RightButtonUp")
frame:RegisterForDrag("LeftButton")
end
function CombatTracker_OnEvent(frame, event, ...)
if event == "PLAYER_REGEN_DISABLED" then
-- This event is called when we enter combat
-- Reset the damage total and start the timer
CombatTrackerFrameText:SetText("In Combat")
total_damage = 0
start_time = GetTime()
elseif event == "PLAYER_REGEN_ENABLED" then
-- This event is called when the player exits combat
end_time = GetTime()
total_time = end_time - start_time
average_dps = total_damage / total_time
CombatTracker_UpdateText()
elseif event == "UNIT_COMBAT" then
if InCombatLockdown() then
local unit, action, modifier, damage, damagetype = ...
if unit == "player" and action ~= "HEAL" then
total_damage = total_damage + damage
end_time = GetTime()
total_time = math.max(end_time - start_time, 1)
average_dps = total_damage / total_time
CombatTracker_UpdateText()
end
end
end
end
function CombatTracker_UpdateText()
local status = string.format("%ds / %d dmg / %.2f dps", total_time, total_damage, average_dps)
CombatTrackerFrameText:SetText(status)
end
function CombatTracker_ReportDPS()
local msgformat = "%d seconds spent in combat with %d incoming damage. Average incoming DPS was %.2f"
local msg = string.format(msgformat, total_time, total_damage, average_dps)
if GetNumGroupMembers() > 0 then
SendChatMessage(msg, "PARTY")
else
print(msg)
end
end
XML
Code:
<Ui xmlns="http://www.blizzard.com/wow/ui/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.blizzard.com/wow/ui/
http://wowprogramming.com/FrameXML/UI.xsd">
<Button name="CombatTrackerFrame" parent="UIParent" enableMouse="true" movable="true" frameStrata="LOW">
<Size x="175" y="40"/>
<Anchors>
<Anchor point="TOP" relativePoint="BOTTOM" relativeTo="Minimap">
<Offset x="0" y="-10"/>
</Anchor>
</Anchors>
<Backdrop bgFile="Interface\DialogFrame\UI-DialogBox-Background" edgeFile="Interface\DialogFrame\UI-DialogBox-Border" tile="true">
<BackgroundInsets>
<AbsInset left="11" right="12" top="12" bottom="11"/>
</BackgroundInsets>
<TileSize>
<AbsValue val="32"/>
</TileSize>
<EdgeSize>
<AbsValue val="32"/>
</EdgeSize>
</Backdrop>
<Layers>
<Layer level="OVERLAY">
<FontString name="$parentText" inherits="GameFontNormalSmall" justifyH="CENTER" setAllPoints="true" text="CombatTracker"/>
</Layer>
</Layers>
<Scripts>
<OnLoad>
CombatTracker_OnLoad(self)
</OnLoad>
<OnEvent>
CombatTracker_OnEvent(self, event, ...)
</OnEvent>
<OnClick>
CombatTracker_ReportDPS()
</OnClick>
<OnDragStart>
self:StartMoving()
</OnDragStart>
<OnDragStop>
self:StopMovingOrSizing()
</OnDragStop>
</Scripts>
</Button>
</Ui>
toc
Code:
## Interface: 30200
## Title: CombatTracker
## Notes: Tracks incoming DPS, and how long you spend in combat
CombatTracker.lua
CombatTracker.xml