View Single Post
09-06-23, 07:53 AM   #7
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Originally Posted by Fizzlemizz View Post
If playerRole is still a table then no.
Whatever is on the left side has to be able to equate to whatever is on the right.

Taking a look at the library,
Code:
local playerRole = LibClassicSpecs.Role
Just returns a table of
Lua Code:
  1. local Role = {
  2.   Damager = "DAMAGER",
  3.   Tank = "TANK",
  4.   Healer = "HEALER"
  5. }

playerRole should be something like a return from GetSpecializationInfo for the characters current classs/spec. ie. a string with "HEALER", "TANK" etc.
Lua Code:
  1. local playerRole = select(6, GetSpecializationInfo(xxx))

Then where you're using playeRole it can just be
Lua Code:
  1. if playerRole == nil then
  2.     --xxx                Text:SetText(hexa.."No Stats"..hexb)
  3. else
  4.     if playerRole == "TANK" then
  5.         UpdateTank(self)
  6.     elseif playerRole == "HEALER" then
  7.         UpdateCaster(self)
  8.     elseif playerRole == "DAMAGER" then
  9.         UpdateDamager(self)
  10.     end
  11. end
Thank You for the help, I tried a different route but still doesnt show up on datapanel, i dont get any errors but no text either.

i chose to go by primary stat (Strength/Agility/Intel) to decide which set of stats should be shown, hopefully i have done this correct.

Here is the new code for stats.
Lua Code:
  1. if db.stats then
  2.  
  3.         local statsPlugin = CreateFrame('Frame', nil, Datapanel)
  4.         statsPlugin:RegisterEvent("PLAYER_ENTERING_WORLD")
  5.         statsPlugin:SetFrameStrata("BACKGROUND")
  6.         statsPlugin:SetFrameLevel(3)
  7.         statsPlugin:EnableMouse(true)
  8.  
  9.         local Text = statsPlugin:CreateFontString(nil, "OVERLAY")
  10.         Text:SetFont(db.font, db.fontSize,'THINOUTLINE')
  11.         PlacePlugin(db.stats, Text)
  12.  
  13.         local function ShowTooltip(self)
  14.             local playerStat = select(7, GetSpecializationInfo())
  15.             local playerClass = select(3, GetClassInfo())
  16.             local anchor, panel, xoff, yoff = DataTextTooltipAnchor(Text)
  17.             GameTooltip:SetOwner(panel, anchor, xoff, yoff)
  18.             GameTooltip:ClearLines()
  19.             GameTooltip:AddLine(hexa..PLAYER_NAME.."'s"..hexb.." Statistics")
  20.             GameTooltip:AddLine' '
  21.             if playerStat == 1 then
  22.                 local Total_Dodge = GetDodgeChance()
  23.                 local Total_Parry = GetParryChance()
  24.                 local Total_Block = GetBlockChance()
  25.                
  26.                 GameTooltip:AddLine(STAT_CATEGORY_DEFENSE)
  27.                 GameTooltip:AddDoubleLine(DODGE_CHANCE, format("%.2f%%", Total_Dodge),1,1,1)
  28.                 GameTooltip:AddDoubleLine(PARRY_CHANCE, format("%.2f%%", Total_Parry),1,1,1)
  29.                 GameTooltip:AddDoubleLine(BLOCK_CHANCE, format("%.2f%%", Total_Block),1,1,1)               
  30.                
  31.             elseif playerStat == 4 then
  32.                 local SC = GetSpellCritChance("2")
  33.                 local Total_Spell_Haste = UnitSpellHaste("player")
  34.                 local base, casting = GetManaRegen()
  35.                 local manaRegenString = "%d / %d"              
  36.                
  37.                 GameTooltip:AddLine(STAT_CATEGORY_SPELL)
  38.                 GameTooltip:AddDoubleLine(STAT_CRITICAL_STRIKE, format("%.2f%%", SC), 1, 1, 1)
  39.                 GameTooltip:AddDoubleLine(STAT_HASTE, format("%.2f%%", Total_Spell_Haste), 1, 1, 1)    
  40.                 GameTooltip:AddDoubleLine(MANA_REGEN, format(manaRegenString, base * 5, casting * 5), 1, 1, 1)
  41.  
  42.             elseif playerStat == 2 then        
  43.                 if playerClass == "HUNTER" then
  44.                     local Total_Range_Haste = GetRangedHaste("player")
  45.                     local Range_Crit = GetRangedCritChance("25")
  46.                     local speed = UnitRangedDamage("player")
  47.                     local Total_Range_Speed = speed
  48.                    
  49.                     GameTooltip:AddLine(STAT_CATEGORY_RANGED)                  
  50.                     GameTooltip:AddDoubleLine(STAT_CRITICAL_STRIKE, format("%.2f%%", Range_Crit), 1, 1, 1) 
  51.                     GameTooltip:AddDoubleLine(STAT_HASTE, format("%.2f%%", Total_Range_Haste), 1, 1, 1)
  52.                     GameTooltip:AddDoubleLine(STAT_ATTACK_SPEED, format("%.2f".." (sec)", Total_Range_Speed), 1, 1, 1)                 
  53.                 else
  54.                     local Melee_Crit = GetCritChance("player")
  55.                     local Total_Melee_Haste = GetMeleeHaste("player")
  56.                     local mainSpeed = UnitAttackSpeed("player");
  57.                     local MH = mainSpeed
  58.                    
  59.                     GameTooltip:AddLine(STAT_CATEGORY_MELEE)
  60.                     GameTooltip:AddDoubleLine(STAT_CRITICAL_STRIKE, format("%.2f%%", Melee_Crit), 1, 1, 1)     
  61.                     GameTooltip:AddDoubleLine(STAT_HASTE, format("%.2f%%", Total_Melee_Haste), 1, 1, 1)
  62.                     GameTooltip:AddDoubleLine(STAT_ATTACK_SPEED, format("%.2f".." (sec)", MH), 1, 1, 1)
  63.                 end
  64.             end
  65.                
  66.             GameTooltip:AddLine' '
  67.             GameTooltip:AddLine(STAT_CATEGORY_GENERAL)         
  68.  
  69.             GameTooltip:Show()
  70.         end
  71.  
  72.         local function UpdateTank(self)
  73.             local armorString = hexa..ARMOR..hexb..": "
  74.             local displayNumberString = string.join("", "%s", "%d|r");
  75.             local base, effectiveArmor, armor, posBuff, negBuff = UnitArmor("player");
  76.             local Melee_Reduction = effectiveArmor
  77.            
  78.             Text:SetFormattedText(displayNumberString, armorString, effectiveArmor)
  79.             --Setup Tooltip
  80.             self:SetAllPoints(Text)
  81.         end
  82.  
  83.         local function UpdateCaster(self)
  84.             local spellpwr = GetSpellBonusDamage("2");
  85.             local displayNumberString = string.join("", "%s", "%d|r");
  86.            
  87.             Text:SetFormattedText(displayNumberString, hexa.."SP: "..hexb, spellpwr)
  88.            
  89.             --Setup Tooltip
  90.             self:SetAllPoints(Text)
  91.         end
  92.  
  93.         local function UpdateDamager(self) 
  94.             local displayNumberString = string.join("", "%s", "%d|r");
  95.                
  96.             if playerClass == "HUNTER" then
  97.                 local base, posBuff, negBuff = UnitRangedAttackPower("player")
  98.                 local Range_AP = base + posBuff + negBuff  
  99.                 pwr = Range_AP
  100.             else
  101.                 local base, posBuff, negBuff = UnitAttackPower("player")
  102.                 local Melee_AP = base + posBuff + negBuff      
  103.                 pwr = Melee_AP
  104.             end
  105.            
  106.             Text:SetFormattedText(displayNumberString, hexa.."AP: "..hexb, pwr)      
  107.             --Setup Tooltip
  108.             self:SetAllPoints(Text)
  109.         end
  110.  
  111.         local int = 5  
  112.         local function Update(self, t)
  113.             int = int - t
  114.             if int > 0 then return end
  115.             if playerStat == 1 then
  116.                 UpdateTank(self)
  117.             elseif playerStat == 4 then
  118.                 UpdateCaster(self)
  119.             elseif playerStat == 2 then
  120.                 UpdateDamager(self)
  121.             end
  122.             int = 2
  123.         end
  124.  
  125.         statsPlugin:SetScript("OnEnter", function() ShowTooltip(statsPlugin) end)
  126.         statsPlugin:SetScript("OnLeave", function() GameTooltip:Hide() end)
  127.         statsPlugin:SetScript("OnUpdate", Update)
  128.         Update(statsPlugin, 10)
  129.     end
  Reply With Quote