View Single Post
09-05-23, 08:31 AM   #1
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
[WoW Classic Era] Bringing back a older addon.

Hello everyone, im trying to resurrect my old addon BasicUI but am having some issues with my datapanel and some datatext.

Mostly the 2 main datatext im having issues with are spec and stat datatext.

I have add LibClassicSpecs to help me get the players roles in classic era but i cant seem to get them to work correctly.

So what i would like to achive is...

spec - show your current spec at a glance (mainly for people that play multiple toons)

stat - show the players current major stat either being Armor for tanks, attack power for damagers and spell power for caster/healers.

Here are the lua codes im working with.

LibClassicSpecs code at the top of the module:
Lua Code:
  1. local LibClassicSpecs = LibStub("LibClassicSpecs")
  2.  
  3. local MAX_TALENT_TIERS                = _G.MAX_TALENT_TIERS or LibClassicSpecs.MAX_TALENT_TIERS
  4. local NUM_TALENT_COLUMNS              = _G.NUM_TALENT_COLUMNS or LibClassicSpecs.NUM_TALENT_COLUMNS
  5.  
  6. local GetNumClasses                   = _G.GetNumClasses or LibClassicSpecs.GetNumClasses
  7. local GetClassInfo                    = _G.GetClassInfo or LibClassicSpecs.GetClassInfo
  8. local GetNumSpecializationsForClassID = _G.GetNumSpecializationsForClassID or LibClassicSpecs.GetNumSpecializationsForClassID
  9.  
  10. local GetActiveSpecGroup              = _G.GetActiveSpecGroup or LibClassicSpecs.GetActiveSpecGroup
  11.  
  12. local GetSpecialization               = _G.GetSpecialization or LibClassicSpecs.GetSpecialization
  13. local GetSpecializationInfo           = _G.GetSpecializationInfo or LibClassicSpecs.GetSpecializationInfo
  14. local GetSpecializationInfoForClassID = _G.GetSpecializationInfoForClassID or LibClassicSpecs.GetSpecializationInfoForClassID
  15.  
  16. local GetSpecializationRole           = _G.GetSpecializationRole or LibClassicSpecs.GetSpecializationRole
  17. local GetSpecializationRoleByID       = _G.GetSpecializationRoleByID or LibClassicSpecs.GetSpecializationRoleByID
  18.  
  19.  
  20. -- Useful constants/enums
  21. local playerRole = LibClassicSpecs.Role
  22. local playerClass = LibClassicSpecs.Class
  23. local playerStat = LibClassicSpecs.Stat

spec code:
Lua Code:
  1. if db.spec then
  2.  
  3.         local specPlugin = CreateFrame('Frame', nil, Datapanel)
  4.         specPlugin:EnableMouse(true)
  5.         specPlugin:SetFrameStrata('BACKGROUND')
  6.         specPlugin:SetFrameLevel(3)
  7.  
  8.         local Text = specPlugin:CreateFontString(nil, 'OVERLAY')
  9.         Text:SetFont(db.font, db.fontSize,'THINOUTLINE')
  10.         PlacePlugin(db.spec, Text)
  11.  
  12.         local talent = {}
  13.         local active
  14.         local talentString = string.join('', '|cffFFFFFF%s|r ')
  15.         local activeString = string.join('', '|cff00FF00' , ACTIVE_PETS, '|r')
  16.         local inactiveString = string.join('', '|cffFF0000', FACTION_INACTIVE, '|r')
  17.  
  18.  
  19.  
  20.         --[[local function LoadTalentTrees()
  21.             for i = 1, GetNumSpecGroups(false, false) do
  22.                 talent[i] = {} -- init talent group table
  23.                 for j = 1, GetNumSpecializations(false, false) do
  24.                     talent[i][j] = select(5, GetSpecializationInfo(j, false, false, i))
  25.                 end
  26.             end
  27.         end]]
  28.  
  29.         local int = 5
  30.         local function Update(self, t)
  31.            
  32.             int = int - t
  33.             if int > 0 then return end
  34.             active = GetActiveSpecGroup(false, false)
  35.             if playerRole ~= nil then
  36.                 Text:SetFormattedText(talentString, hexa..select(2, GetSpecializationInfo(GetSpecialization(false, false, active)))..hexb)
  37.             else
  38.                 Text:SetText(hexa.."No Spec"..hexb)
  39.             end
  40.             int = 2
  41.  
  42.             -- disable script  
  43.             --self:SetScript('OnUpdate', nil)
  44.            
  45.         end
  46.  
  47.  
  48.         specPlugin:SetScript('OnEnter', function(self)
  49.             local anchor, panel, xoff, yoff = DataTextTooltipAnchor(Text)
  50.             GameTooltip:SetOwner(panel, anchor, xoff, yoff)
  51.  
  52.             GameTooltip:ClearLines()
  53.             GameTooltip:AddLine(hexa..PLAYER_NAME.."'s"..hexb.." Spec")
  54.             GameTooltip:AddLine' '
  55.             if playerRole ~= nil then
  56.                 for i = 1, GetNumSpecGroups() do
  57.                     if GetSpecialization(false, false, i) then
  58.                         GameTooltip:AddLine(string.join('- ', string.format(talentString, select(2, GetSpecializationInfo(GetSpecialization(false, false, i)))), (i == active and activeString or inactiveString)),1,1,1)
  59.                     end
  60.                 end
  61.             else
  62.                 GameTooltip:AddLine("You have not chosen a Spec yet.")
  63.             end
  64.             GameTooltip:AddLine' '     
  65.             GameTooltip:AddLine("|cffeda55fClick|r to Open Talent Tree")
  66.             GameTooltip:Show()
  67.         end)
  68.  
  69.         specPlugin:SetScript('OnLeave', function() GameTooltip:Hide() end)
  70.  
  71.         local function OnEvent(self, event, ...)
  72.             if event == 'PLAYER_ENTERING_WORLD' then
  73.                 self:UnregisterEvent('PLAYER_ENTERING_WORLD')
  74.             end
  75.            
  76.             -- load talent information
  77.             --LoadTalentTrees()
  78.  
  79.             -- Setup Talents Tooltip
  80.             self:SetAllPoints(Text)
  81.  
  82.             -- update datatext
  83.             if event ~= 'PLAYER_ENTERING_WORLD' then
  84.                 self:SetScript('OnUpdate', Update)
  85.             end
  86.         end
  87.  
  88.  
  89.  
  90.         specPlugin:RegisterEvent('PLAYER_ENTERING_WORLD');
  91.         specPlugin:RegisterEvent('CHARACTER_POINTS_CHANGED');
  92.         specPlugin:RegisterEvent('PLAYER_TALENT_UPDATE');
  93.         specPlugin:RegisterEvent('ACTIVE_TALENT_GROUP_CHANGED')
  94.         specPlugin:RegisterEvent("EQUIPMENT_SETS_CHANGED")
  95.         specPlugin:SetScript('OnEvent', OnEvent)
  96.         specPlugin:SetScript('OnUpdate', Update)
  97.  
  98.         specPlugin:SetScript("OnMouseDown", function() ToggleTalentFrame() end)
  99.     end

stat code:
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 playerClass, englishClass = UnitClass("player");
  14.  
  15.         local function ShowTooltip(self)   
  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 playerRole == nil then
  22.                 GameTooltip:AddLine("Choose a Specialization to see Stats")
  23.             else
  24.                 if playerRole == playerRole.Tank then
  25.                     local Total_Dodge = GetDodgeChance()
  26.                     local Total_Parry = GetParryChance()
  27.                     local Total_Block = GetBlockChance()
  28.                    
  29.                     GameTooltip:AddLine(STAT_CATEGORY_DEFENSE)
  30.                     GameTooltip:AddDoubleLine(DODGE_CHANCE, format("%.2f%%", Total_Dodge),1,1,1)
  31.                     GameTooltip:AddDoubleLine(PARRY_CHANCE, format("%.2f%%", Total_Parry),1,1,1)
  32.                     GameTooltip:AddDoubleLine(BLOCK_CHANCE, format("%.2f%%", Total_Block),1,1,1)               
  33.                    
  34.                 elseif playerRole == playerRole.Healer then
  35.                     local SC = GetSpellCritChance("2")
  36.                     local Total_Spell_Haste = UnitSpellHaste("player")
  37.                     local base, casting = GetManaRegen()
  38.                     local manaRegenString = "%d / %d"              
  39.                    
  40.                     GameTooltip:AddLine(STAT_CATEGORY_SPELL)
  41.                     GameTooltip:AddDoubleLine(STAT_CRITICAL_STRIKE, format("%.2f%%", SC), 1, 1, 1)
  42.                     GameTooltip:AddDoubleLine(STAT_HASTE, format("%.2f%%", Total_Spell_Haste), 1, 1, 1)    
  43.                     GameTooltip:AddDoubleLine(MANA_REGEN, format(manaRegenString, base * 5, casting * 5), 1, 1, 1)
  44.  
  45.                 elseif playerRole == playerRole.Damager then           
  46.                     if Class == Class.Hunter then
  47.                         local Total_Range_Haste = GetRangedHaste("player")
  48.                         local Range_Crit = GetRangedCritChance("25")
  49.                         local speed = UnitRangedDamage("player")
  50.                         local Total_Range_Speed = speed
  51.                        
  52.                         GameTooltip:AddLine(STAT_CATEGORY_RANGED)                  
  53.                         GameTooltip:AddDoubleLine(STAT_CRITICAL_STRIKE, format("%.2f%%", Range_Crit), 1, 1, 1) 
  54.                         GameTooltip:AddDoubleLine(STAT_HASTE, format("%.2f%%", Total_Range_Haste), 1, 1, 1)
  55.                         GameTooltip:AddDoubleLine(STAT_ATTACK_SPEED, format("%.2f".." (sec)", Total_Range_Speed), 1, 1, 1)                 
  56.                     else
  57.                         local Melee_Crit = GetCritChance("player")
  58.                         local Total_Melee_Haste = GetMeleeHaste("player")
  59.                         local mainSpeed = UnitAttackSpeed("player");
  60.                         local MH = mainSpeed
  61.                        
  62.                         GameTooltip:AddLine(STAT_CATEGORY_MELEE)
  63.                         GameTooltip:AddDoubleLine(STAT_CRITICAL_STRIKE, format("%.2f%%", Melee_Crit), 1, 1, 1)     
  64.                         GameTooltip:AddDoubleLine(STAT_HASTE, format("%.2f%%", Total_Melee_Haste), 1, 1, 1)
  65.                         GameTooltip:AddDoubleLine(STAT_ATTACK_SPEED, format("%.2f".." (sec)", MH), 1, 1, 1)
  66.                     end
  67.                 end
  68.                 --[[if GetCombatRating(CR_MASTERY) ~= 0 and GetSpecialization() then
  69.                     local masteryspell = GetSpecializationMasterySpells(GetSpecialization())
  70.                     local Mastery = GetMasteryEffect("player")
  71.                     local masteryName, _, _, _, _, _, _, _, _ = GetSpellInfo(masteryspell)
  72.                     if masteryName then
  73.                         GameTooltip:AddDoubleLine(masteryName, format("%.2f%%", Mastery), 1, 1, 1)
  74.                     end
  75.                 end]]
  76.                    
  77.                 GameTooltip:AddLine' '
  78.                 GameTooltip:AddLine(STAT_CATEGORY_GENERAL)
  79.                
  80.                 --local Life_Steal = GetLifesteal();
  81.                 --local Versatility_Damage_Bonus = GetCombatRatingBonus(CR_VERSATILITY_DAMAGE_DONE) + GetVersatilityBonus(CR_VERSATILITY_DAMAGE_DONE);
  82.                 --local Avoidance = GetAvoidance();
  83.                
  84.                 --GameTooltip:AddDoubleLine(STAT_LIFESTEAL, format("%.2f%%", Life_Steal), 1, 1, 1)
  85.                 --GameTooltip:AddDoubleLine(STAT_VERSATILITY, format("%.2f%%", Versatility_Damage_Bonus), 1, 1, 1)
  86.                 --GameTooltip:AddDoubleLine(STAT_AVOIDANCE, format("%.2f%%", Avoidance), 1, 1, 1)          
  87.             end
  88.  
  89.             GameTooltip:Show()
  90.         end
  91.  
  92.         local function UpdateTank(self)
  93.             local armorString = hexa..ARMOR..hexb..": "
  94.             local displayNumberString = string.join("", "%s", "%d|r");
  95.             local base, effectiveArmor, armor, posBuff, negBuff = UnitArmor("player");
  96.             local Melee_Reduction = effectiveArmor
  97.            
  98.             Text:SetFormattedText(displayNumberString, armorString, effectiveArmor)
  99.             --Setup Tooltip
  100.             self:SetAllPoints(Text)
  101.         end
  102.  
  103.         local function UpdateCaster(self)
  104.             local spellpwr = GetSpellBonusDamage("2");
  105.             local displayNumberString = string.join("", "%s", "%d|r");
  106.            
  107.             Text:SetFormattedText(displayNumberString, hexa.."SP: "..hexb, spellpwr)
  108.            
  109.             --Setup Tooltip
  110.             self:SetAllPoints(Text)
  111.         end
  112.  
  113.         local function UpdateDamager(self) 
  114.             local displayNumberString = string.join("", "%s", "%d|r");
  115.                
  116.             if Class == Class.Hunter then
  117.                 local base, posBuff, negBuff = UnitRangedAttackPower("player")
  118.                 local Range_AP = base + posBuff + negBuff  
  119.                 pwr = Range_AP
  120.             else
  121.                 local base, posBuff, negBuff = UnitAttackPower("player")
  122.                 local Melee_AP = base + posBuff + negBuff      
  123.                 pwr = Melee_AP
  124.             end
  125.            
  126.             Text:SetFormattedText(displayNumberString, hexa.."AP: "..hexb, pwr)      
  127.             --Setup Tooltip
  128.             self:SetAllPoints(Text)
  129.         end
  130.  
  131.         -- initial delay for update (let the ui load)
  132.         local int = 5  
  133.         local function Update(self, t)
  134.             int = int - t
  135.             if int > 0 then return end
  136.             if playerRole == nil then
  137.                 Text:SetText(hexa.."No Stats"..hexb)
  138.             else
  139.                 if playerRole == playerRole.Tank then
  140.                     UpdateTank(self)
  141.                 elseif playerRole == playerRole.Healer then
  142.                     UpdateCaster(self)
  143.                 elseif playerRole == playerRole.Damager then
  144.                     UpdateDamager(self)
  145.                 end
  146.             end
  147.             int = 2
  148.         end
  149.  
  150.         statsPlugin:SetScript("OnEnter", function() ShowTooltip(statsPlugin) end)
  151.         statsPlugin:SetScript("OnLeave", function() GameTooltip:Hide() end)
  152.         statsPlugin:SetScript("OnUpdate", Update)
  153.         Update(statsPlugin, 10)
  154.     end

neither one populate on the datapanel.

Any help would be great.

Also all my other datatext are working as of right now so its not the datapanel its the datatext itself.

Thanks
Cokedriver
  Reply With Quote