Torax
05-24-2010, 03:13 AM
Due to an oversight, the example script was not included in this patch. Here is the DPS sample script. Create a folder in your main directory called addons. (Crowns of Power/main/addons). Create a new file called dps.lua and paste this into it:
-- Register the chat command /dps
addChatCommand("dps");
-- Function to reset DPS stats
function resetStats()
damageTable = {};
totalDamage = 0;
end
-- Initilize variable when script first executes
resetStats()
-- Called when the player first spawns
function onLoaded()
status("DPS monitor loaded.");
isLoaded = true;
end
-- Report the damage to the appropriate channel. func is the function to use to report the damage, see chatcmd_dps
function reportDamage(func)
sorttbl = GetSortedTable(damageTable)
place = 1;
for idx,row in pairs(sorttbl) do
dmgPct = round(((row.value / totalDamage) * 100), 2);
func(place .. ". " .. row.key .. " - " .. commas(row.value) .. " (" .. dmgPct .. "%)")
place = place + 1;
if(place > 10) then break end
end
end
-- Called when /dps is entered in chat. Anything after /dps is in the text variable
function chatcmd_dps(text)
if text == "say" then
chatSay(" -= DPS Report =- ");
reportDamage(chatSay);
elseif text == "group" then
chatGroup("=DPS for group=");
reportDamage(chatGroup);
elseif text == "guild" then
chatGuild("=DPS for group=");
reportDamage(chatGuild);
elseif text == "reset" then
status("DPS Monitor reset");
resetStats();
else
status("DPS Monitor 1.0")
status("==== COMMANDS ====")
status("/dps group (Report DPS to group)")
status("/dps say (Report DPS to say)")
status("/dps guild (Report DPS to guild)")
status("/dps reset (Reset current DPS statistics)")
end
end
-- Event called every time a player does damage in your group
function onDamageDone(damageDone, attackerName, defenderName, hitType, damageType)
-- Convert your damage to your name
if (attackerName == "You" or attackerName == "Your") then attackerName = playerInfo("name") end
if damageTable[attackerName] == nil then
damageTable[attackerName] = 0;
end
damageTable[attackerName] = damageTable[attackerName] + damageDone;
totalDamage = totalDamage + damageDone;
end
-- Reset stats when you join a new group
function onGroupJoin()
if isLoaded == nil then return end
status("DPS Monitor stats reset");
resetStats();
end
-- Reset stats when you leave a group
function onGroupLeave()
if isLoaded == nil then return end
status("DPS Monitor stats reset");
resetStats();
end
-- Register the chat command /dps
addChatCommand("dps");
-- Function to reset DPS stats
function resetStats()
damageTable = {};
totalDamage = 0;
end
-- Initilize variable when script first executes
resetStats()
-- Called when the player first spawns
function onLoaded()
status("DPS monitor loaded.");
isLoaded = true;
end
-- Report the damage to the appropriate channel. func is the function to use to report the damage, see chatcmd_dps
function reportDamage(func)
sorttbl = GetSortedTable(damageTable)
place = 1;
for idx,row in pairs(sorttbl) do
dmgPct = round(((row.value / totalDamage) * 100), 2);
func(place .. ". " .. row.key .. " - " .. commas(row.value) .. " (" .. dmgPct .. "%)")
place = place + 1;
if(place > 10) then break end
end
end
-- Called when /dps is entered in chat. Anything after /dps is in the text variable
function chatcmd_dps(text)
if text == "say" then
chatSay(" -= DPS Report =- ");
reportDamage(chatSay);
elseif text == "group" then
chatGroup("=DPS for group=");
reportDamage(chatGroup);
elseif text == "guild" then
chatGuild("=DPS for group=");
reportDamage(chatGuild);
elseif text == "reset" then
status("DPS Monitor reset");
resetStats();
else
status("DPS Monitor 1.0")
status("==== COMMANDS ====")
status("/dps group (Report DPS to group)")
status("/dps say (Report DPS to say)")
status("/dps guild (Report DPS to guild)")
status("/dps reset (Reset current DPS statistics)")
end
end
-- Event called every time a player does damage in your group
function onDamageDone(damageDone, attackerName, defenderName, hitType, damageType)
-- Convert your damage to your name
if (attackerName == "You" or attackerName == "Your") then attackerName = playerInfo("name") end
if damageTable[attackerName] == nil then
damageTable[attackerName] = 0;
end
damageTable[attackerName] = damageTable[attackerName] + damageDone;
totalDamage = totalDamage + damageDone;
end
-- Reset stats when you join a new group
function onGroupJoin()
if isLoaded == nil then return end
status("DPS Monitor stats reset");
resetStats();
end
-- Reset stats when you leave a group
function onGroupLeave()
if isLoaded == nil then return end
status("DPS Monitor stats reset");
resetStats();
end