Thread Tools Display Modes
02-16-16, 01:14 PM   #1
FishStixx
A Kobold Labourer
Join Date: Feb 2016
Posts: 1
6.23 Updated CombatTracker

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
Attached Files
File Type: zip 14-CombatTracker.zip (2.1 KB, 95 views)

Last edited by FishStixx : 02-16-16 at 09:45 PM.
  Reply With Quote
02-19-16, 06:50 AM   #2
Yukyuk
A Chromatic Dragonspawn
 
Yukyuk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2015
Posts: 179
Some general advice.

Post the actual code that you are using, that way its easier to see what we are talking about.

When I started coding lua (just over a year ago) I first installed !BugGrabber and BugSack.
They were (and still are) great addons to help you with your programming and testing.

And what is the actual problem you are having?
__________________
Better to fail then never have tried at all.
  Reply With Quote
02-19-16, 01:53 PM   #3
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
The code you have posted appears to work. Make sure you have "Load out of date addons" checked if you are going to continue to use that ## Interface: number in the .toc file or change it to 60200 (the current interface no. until Legion pre-launch goes live).

The display frame for the addon is anchored to the bottom of the minimap. If you have moved your minimap to the bottom of the screen you won't see anything. If this is the case then change the xml file from:
Code:
    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>
...
To:
Code:
    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="BOTTOM" relativePoint="TOP" relativeTo="Minimap">
                <Offset x="0" y="10"/>
            </Anchor>
        </Anchors>
...
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-19-16 at 03:29 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » 6.23 Updated CombatTracker

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