12.07.2015 Views

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

278 Part II ■ <strong>Programming</strong> in <strong>World</strong> <strong>of</strong> <strong>Warcraft</strong>When run, this <strong>for</strong>mat string shows the number <strong>of</strong> seconds in combat,followed by the amount <strong>of</strong> damage taken, <strong>and</strong> the average incoming DPS <strong>for</strong>that combat period.CombatTracker_ReportDPS()The CombatTracker_ReportDPS()checks calls the GetNumPartyMembers() functionto determine whether or not the player is in a party. If the number isgreater than 0, the player is in a party. Add the following function to yourCombatTracker.lua:function CombatTracker_ReportDPS()local msg<strong>for</strong>mat = “%d seconds spent in combat with %d incoming idamage. Average incoming DPS was %.2f“local msg = string.<strong>for</strong>mat(msg<strong>for</strong>mat, total_time, total_damage, iaverage_dps)if GetNumPartyMembers() > 0 thenSendChatMessage(msg, “PARTY“)elseprint(msg)endendThis function uses a <strong>for</strong>mat string to craft the outgoing message, <strong>and</strong> thenuses GetNumPartyMembers() to decide where to send it. If the player is in aparty, the SendChatMessage() function is used to send the message to theparty; otherwise, the print() function is used to send it to the chat frame sothe player can see it.Testing CombatTrackerYou have completed all the code necessary <strong>for</strong> a fully functional Combat-Tracker addon. Load the game <strong>and</strong> select a character. You should be greetedwith the CombatTracker frame right below your minimap.Testing is a very important part <strong>of</strong> addon writing if you plan to release youraddons to the public. When you write a set <strong>of</strong> features, it’s prudent to testthem yourself be<strong>for</strong>e you ship the addon to the public to ensure that userswon’t get error messages <strong>and</strong> be reporting them to you after the fact. That sort<strong>of</strong> troubleshooting is always more difficult than errors you encounter on yourown. Systematically test each portion <strong>of</strong> the addon.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!