A Rage Talon Dragon Guard
Join Date: Aug 2009
Posts: 328
|
[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:
local LibClassicSpecs = LibStub("LibClassicSpecs") local MAX_TALENT_TIERS = _G.MAX_TALENT_TIERS or LibClassicSpecs.MAX_TALENT_TIERS local NUM_TALENT_COLUMNS = _G.NUM_TALENT_COLUMNS or LibClassicSpecs.NUM_TALENT_COLUMNS local GetNumClasses = _G.GetNumClasses or LibClassicSpecs.GetNumClasses local GetClassInfo = _G.GetClassInfo or LibClassicSpecs.GetClassInfo local GetNumSpecializationsForClassID = _G.GetNumSpecializationsForClassID or LibClassicSpecs.GetNumSpecializationsForClassID local GetActiveSpecGroup = _G.GetActiveSpecGroup or LibClassicSpecs.GetActiveSpecGroup local GetSpecialization = _G.GetSpecialization or LibClassicSpecs.GetSpecialization local GetSpecializationInfo = _G.GetSpecializationInfo or LibClassicSpecs.GetSpecializationInfo local GetSpecializationInfoForClassID = _G.GetSpecializationInfoForClassID or LibClassicSpecs.GetSpecializationInfoForClassID local GetSpecializationRole = _G.GetSpecializationRole or LibClassicSpecs.GetSpecializationRole local GetSpecializationRoleByID = _G.GetSpecializationRoleByID or LibClassicSpecs.GetSpecializationRoleByID -- Useful constants/enums local playerRole = LibClassicSpecs.Role local playerClass = LibClassicSpecs.Class local playerStat = LibClassicSpecs.Stat
spec code:
Lua Code:
if db.spec then local specPlugin = CreateFrame('Frame', nil, Datapanel) specPlugin:EnableMouse(true) specPlugin:SetFrameStrata('BACKGROUND') specPlugin:SetFrameLevel(3) local Text = specPlugin:CreateFontString(nil, 'OVERLAY') Text:SetFont(db.font, db.fontSize,'THINOUTLINE') PlacePlugin(db.spec, Text) local talent = {} local active local talentString = string.join('', '|cffFFFFFF%s|r ') local activeString = string.join('', '|cff00FF00' , ACTIVE_PETS, '|r') local inactiveString = string.join('', '|cffFF0000', FACTION_INACTIVE, '|r') --[[local function LoadTalentTrees() for i = 1, GetNumSpecGroups(false, false) do talent[i] = {} -- init talent group table for j = 1, GetNumSpecializations(false, false) do talent[i][j] = select(5, GetSpecializationInfo(j, false, false, i)) end end end]] local int = 5 local function Update(self, t) int = int - t if int > 0 then return end active = GetActiveSpecGroup(false, false) if playerRole ~= nil then Text:SetFormattedText(talentString, hexa..select(2, GetSpecializationInfo(GetSpecialization(false, false, active)))..hexb) else Text:SetText(hexa.."No Spec"..hexb) end int = 2 -- disable script --self:SetScript('OnUpdate', nil) end specPlugin:SetScript('OnEnter', function(self) local anchor, panel, xoff, yoff = DataTextTooltipAnchor(Text) GameTooltip:SetOwner(panel, anchor, xoff, yoff) GameTooltip:ClearLines() GameTooltip:AddLine(hexa..PLAYER_NAME.."'s"..hexb.." Spec") GameTooltip:AddLine' ' if playerRole ~= nil then for i = 1, GetNumSpecGroups() do if GetSpecialization(false, false, i) then GameTooltip:AddLine(string.join('- ', string.format(talentString, select(2, GetSpecializationInfo(GetSpecialization(false, false, i)))), (i == active and activeString or inactiveString)),1,1,1) end end else GameTooltip:AddLine("You have not chosen a Spec yet.") end GameTooltip:AddLine' ' GameTooltip:AddLine("|cffeda55fClick|r to Open Talent Tree") GameTooltip:Show() end) specPlugin:SetScript('OnLeave', function() GameTooltip:Hide() end) local function OnEvent(self, event, ...) if event == 'PLAYER_ENTERING_WORLD' then self:UnregisterEvent('PLAYER_ENTERING_WORLD') end -- load talent information --LoadTalentTrees() -- Setup Talents Tooltip self:SetAllPoints(Text) -- update datatext if event ~= 'PLAYER_ENTERING_WORLD' then self:SetScript('OnUpdate', Update) end end specPlugin:RegisterEvent('PLAYER_ENTERING_WORLD'); specPlugin:RegisterEvent('CHARACTER_POINTS_CHANGED'); specPlugin:RegisterEvent('PLAYER_TALENT_UPDATE'); specPlugin:RegisterEvent('ACTIVE_TALENT_GROUP_CHANGED') specPlugin:RegisterEvent("EQUIPMENT_SETS_CHANGED") specPlugin:SetScript('OnEvent', OnEvent) specPlugin:SetScript('OnUpdate', Update) specPlugin:SetScript("OnMouseDown", function() ToggleTalentFrame() end) end
stat code:
Lua Code:
if db.stats then local statsPlugin = CreateFrame('Frame', nil, Datapanel) statsPlugin:RegisterEvent("PLAYER_ENTERING_WORLD") statsPlugin:SetFrameStrata("BACKGROUND") statsPlugin:SetFrameLevel(3) statsPlugin:EnableMouse(true) local Text = statsPlugin:CreateFontString(nil, "OVERLAY") Text:SetFont(db.font, db.fontSize,'THINOUTLINE') PlacePlugin(db.stats, Text) local playerClass, englishClass = UnitClass("player"); local function ShowTooltip(self) local anchor, panel, xoff, yoff = DataTextTooltipAnchor(Text) GameTooltip:SetOwner(panel, anchor, xoff, yoff) GameTooltip:ClearLines() GameTooltip:AddLine(hexa..PLAYER_NAME.."'s"..hexb.." Statistics") GameTooltip:AddLine' ' if playerRole == nil then GameTooltip:AddLine("Choose a Specialization to see Stats") else if playerRole == playerRole.Tank then local Total_Dodge = GetDodgeChance() local Total_Parry = GetParryChance() local Total_Block = GetBlockChance() GameTooltip:AddLine(STAT_CATEGORY_DEFENSE) GameTooltip:AddDoubleLine(DODGE_CHANCE, format("%.2f%%", Total_Dodge),1,1,1) GameTooltip:AddDoubleLine(PARRY_CHANCE, format("%.2f%%", Total_Parry),1,1,1) GameTooltip:AddDoubleLine(BLOCK_CHANCE, format("%.2f%%", Total_Block),1,1,1) elseif playerRole == playerRole.Healer then local SC = GetSpellCritChance("2") local Total_Spell_Haste = UnitSpellHaste("player") local base, casting = GetManaRegen() local manaRegenString = "%d / %d" GameTooltip:AddLine(STAT_CATEGORY_SPELL) GameTooltip:AddDoubleLine(STAT_CRITICAL_STRIKE, format("%.2f%%", SC), 1, 1, 1) GameTooltip:AddDoubleLine(STAT_HASTE, format("%.2f%%", Total_Spell_Haste), 1, 1, 1) GameTooltip:AddDoubleLine(MANA_REGEN, format(manaRegenString, base * 5, casting * 5), 1, 1, 1) elseif playerRole == playerRole.Damager then if Class == Class.Hunter then local Total_Range_Haste = GetRangedHaste("player") local Range_Crit = GetRangedCritChance("25") local speed = UnitRangedDamage("player") local Total_Range_Speed = speed GameTooltip:AddLine(STAT_CATEGORY_RANGED) GameTooltip:AddDoubleLine(STAT_CRITICAL_STRIKE, format("%.2f%%", Range_Crit), 1, 1, 1) GameTooltip:AddDoubleLine(STAT_HASTE, format("%.2f%%", Total_Range_Haste), 1, 1, 1) GameTooltip:AddDoubleLine(STAT_ATTACK_SPEED, format("%.2f".." (sec)", Total_Range_Speed), 1, 1, 1) else local Melee_Crit = GetCritChance("player") local Total_Melee_Haste = GetMeleeHaste("player") local mainSpeed = UnitAttackSpeed("player"); local MH = mainSpeed GameTooltip:AddLine(STAT_CATEGORY_MELEE) GameTooltip:AddDoubleLine(STAT_CRITICAL_STRIKE, format("%.2f%%", Melee_Crit), 1, 1, 1) GameTooltip:AddDoubleLine(STAT_HASTE, format("%.2f%%", Total_Melee_Haste), 1, 1, 1) GameTooltip:AddDoubleLine(STAT_ATTACK_SPEED, format("%.2f".." (sec)", MH), 1, 1, 1) end end --[[if GetCombatRating(CR_MASTERY) ~= 0 and GetSpecialization() then local masteryspell = GetSpecializationMasterySpells(GetSpecialization()) local Mastery = GetMasteryEffect("player") local masteryName, _, _, _, _, _, _, _, _ = GetSpellInfo(masteryspell) if masteryName then GameTooltip:AddDoubleLine(masteryName, format("%.2f%%", Mastery), 1, 1, 1) end end]] GameTooltip:AddLine' ' GameTooltip:AddLine(STAT_CATEGORY_GENERAL) --local Life_Steal = GetLifesteal(); --local Versatility_Damage_Bonus = GetCombatRatingBonus(CR_VERSATILITY_DAMAGE_DONE) + GetVersatilityBonus(CR_VERSATILITY_DAMAGE_DONE); --local Avoidance = GetAvoidance(); --GameTooltip:AddDoubleLine(STAT_LIFESTEAL, format("%.2f%%", Life_Steal), 1, 1, 1) --GameTooltip:AddDoubleLine(STAT_VERSATILITY, format("%.2f%%", Versatility_Damage_Bonus), 1, 1, 1) --GameTooltip:AddDoubleLine(STAT_AVOIDANCE, format("%.2f%%", Avoidance), 1, 1, 1) end GameTooltip:Show() end local function UpdateTank(self) local armorString = hexa..ARMOR..hexb..": " local displayNumberString = string.join("", "%s", "%d|r"); local base, effectiveArmor, armor, posBuff, negBuff = UnitArmor("player"); local Melee_Reduction = effectiveArmor Text:SetFormattedText(displayNumberString, armorString, effectiveArmor) --Setup Tooltip self:SetAllPoints(Text) end local function UpdateCaster(self) local spellpwr = GetSpellBonusDamage("2"); local displayNumberString = string.join("", "%s", "%d|r"); Text:SetFormattedText(displayNumberString, hexa.."SP: "..hexb, spellpwr) --Setup Tooltip self:SetAllPoints(Text) end local function UpdateDamager(self) local displayNumberString = string.join("", "%s", "%d|r"); if Class == Class.Hunter then local base, posBuff, negBuff = UnitRangedAttackPower("player") local Range_AP = base + posBuff + negBuff pwr = Range_AP else local base, posBuff, negBuff = UnitAttackPower("player") local Melee_AP = base + posBuff + negBuff pwr = Melee_AP end Text:SetFormattedText(displayNumberString, hexa.."AP: "..hexb, pwr) --Setup Tooltip self:SetAllPoints(Text) end -- initial delay for update (let the ui load) local int = 5 local function Update(self, t) int = int - t if int > 0 then return end if playerRole == nil then Text:SetText(hexa.."No Stats"..hexb) else if playerRole == playerRole.Tank then UpdateTank(self) elseif playerRole == playerRole.Healer then UpdateCaster(self) elseif playerRole == playerRole.Damager then UpdateDamager(self) end end int = 2 end statsPlugin:SetScript("OnEnter", function() ShowTooltip(statsPlugin) end) statsPlugin:SetScript("OnLeave", function() GameTooltip:Hide() end) statsPlugin:SetScript("OnUpdate", Update) Update(statsPlugin, 10) 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
|