Wowpedia

We have moved to Warcraft Wiki. Click here for information and the new URL.

READ MORE

Wowpedia
Advertisement

Since there are functions incorporated in the WoW API to return parry, dodge and block chances but none to return crit chance, here's one that was taken (and slightly adaptated) from mercdev's Combat Info.

The code

 function GetCritChance()
   local critChance, iCritInfo;
   local id = 1;
   -- This may vary depending on WoW localizations, it's the name of the "Attack" button in the spellbook.
   local atkName = "Attack";
   local attackSpell = GetSpellName(id,BOOKTYPE_SPELL);
   if (attackSpell ~= atkName) then
     name, texture, offset, numSpells = GetSpellTabInfo(1);
     -- Looping through Spellbook to find the "Attack" button
     for i=1, numSpells do
       if (GetSpellName(i,BOOKTYPE_SPELL) == atkName) then id = i; end
     end
   end
   GameTooltip:SetSpell(id, BOOKTYPE_SPELL);
   local spellName = GameTooltipTextLeft2:GetText();
   GameTooltip:Hide();
   iCritInfo = string.find(spellName, "%s");
   critChance = string.sub(spellName,0,(iCritInfo -2));
   return critChance;
 end

Usage

Simply call the function and display it, like this:

 /script DEFAULT_CHAT_FRAME:AddMessage("Your crit chance is: "..GetCritChance().."%");

or

 /script SendChatMessage("My crit chance is: "..GetCritChance().."%","SAY");
Advertisement