11-02-14, 10:48 AM | #1 |
Stat Switching Unexpectedly
Below is my current Stat that keeps switching from Melee to Caster for my hunter.
This seems to only happens when I take a portal from Shrine. Here is the playerRole Function: Code:
function nData:UpdatePlayerRole() if UnitLevel("player") >= 10 then local _, class = UnitClass("player") local spec = GetSpecialization() local specRole = GetSpecializationRole(spec) -- no need for a giant table that must be maintained by hand if specRole == "TANK" then playerRole = "Tank" elseif specRole == "HEALER" then playerRole = "Caster" elseif specRole == "DAMAGER" then if UnitPowerType("player") == SPELL_POWER_MANA then if (class == "PALADIN" and spec == 3) or (class == "SHAMAN" and spec == 2) then playerRole = "Melee" else playerRole = "Caster" end else playerRole = "Melee" end elseif specRole == nil then playerRole = nil -- no spec end else return end end Code:
local nData = LibStub("AceAddon-3.0"):GetAddon("nData") ------------------------------------------------------------------------ -- Statistics Plugin Functions ------------------------------------------------------------------------ nData.pluginConstructors["stat1"] = function() db = nData.db.profile local plugin = CreateFrame('Frame', nil, Datapanel) plugin:RegisterEvent("PLAYER_ENTERING_WORLD") plugin:SetFrameStrata("BACKGROUND") plugin:SetFrameLevel(3) plugin:EnableMouse(true) local Text = plugin:CreateFontString(nil, "OVERLAY") Text:SetFont(db.font, db.fontSize,'THINOUTLINE') nData:PlacePlugin(db.stat1, Text) local playerClass, englishClass = UnitClass("player"); local function ShowTooltip(self) if InCombatLockdown() then return end local anchor, panel, xoff, yoff = nData:DataTextTooltipAnchor(Text) GameTooltip:SetOwner(panel, anchor, xoff, yoff) GameTooltip:ClearLines() GameTooltip:AddLine(hexa..PLAYER_NAME.."'s"..hexb.." Statistics") GameTooltip:AddLine' ' if UnitLevel("player") > 10 then if 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 == "Caster" 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 == "Melee" then if englishClass == "HUNTER" then local Total_Range_Haste = GetRangedHaste("player") local Range_Armor_Pen = GetArmorPenetration(); local Range_Crit = GetRangedCritChance("25") local speed = UnitRangedDamage("player") local Total_Range_Speed = speed GameTooltip:AddLine(STAT_CATEGORY_RANGED) GameTooltip:AddDoubleLine("Armor Penetration", format("%.2f%%", Range_Armor_Pen), 1, 1, 1) 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 Melee_Armor_Pen = GetArmorPenetration(); local Total_Melee_Haste = GetMeleeHaste("player") local mainSpeed = UnitAttackSpeed("player"); local MH = mainSpeed GameTooltip:AddLine(STAT_CATEGORY_MELEE) GameTooltip:AddDoubleLine("Armor Penetration", format("%.2f%%", Melee_Armor_Pen), 1, 1, 1) 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 GameTooltip:AddLine' ' GameTooltip:AddLine(STAT_CATEGORY_GENERAL) local masteryspell local Multi_Strike = GetMultistrike(); local Life_Steal = GetLifesteal(); --local Versatility = GetVersatility(); local Versatility_Damage_Bonus = GetCombatRatingBonus(CR_VERSATILITY_DAMAGE_DONE) + GetVersatilityBonus(CR_VERSATILITY_DAMAGE_DONE); local Avoidance = GetAvoidance(); local bonusArmor, isNegatedForSpec = UnitBonusArmor("player"); GameTooltip:AddDoubleLine(STAT_BONUS_ARMOR, format("%s", bonusArmor), 1, 1, 1) GameTooltip:AddDoubleLine(STAT_MULTISTRIKE, format("%.2f%%", Multi_Strike), 1, 1, 1) 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_VERSATILITY, format("%d", Versatility), 1, 1, 1) GameTooltip:AddDoubleLine(STAT_AVOIDANCE, format("%.2f%%", Avoidance), 1, 1, 1) if GetCombatRating(CR_MASTERY) ~= 0 and GetSpecialization() then if englishClass == "DRUID" then if playerRole == "Melee" then masteryspell = select(2, GetSpecializationMasterySpells(GetSpecialization())) elseif playerRole == "Tank" then masteryspell = select(1, GetSpecializationMasterySpells(GetSpecialization())) else masteryspell = GetSpecializationMasterySpells(GetSpecialization()) end else masteryspell = GetSpecializationMasterySpells(GetSpecialization()) end local Mastery = GetMasteryEffect("player") local masteryName, _, _, _, _, _, _, _, _ = GetSpellInfo(masteryspell) if masteryName then GameTooltip:AddDoubleLine(masteryName, format("%.2f%%", Mastery), 1, 1, 1) end end else GameTooltip:AddLine("No Stats Available unit Level 10") 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 UpdateMelee(self) local displayNumberString = string.join("", "%s", "%d|r"); if englishClass == "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 UnitLevel("player") >= 10 then if playerRole == "Tank" then UpdateTank(self) elseif playerRole == "Caster" then UpdateCaster(self) elseif playerRole == "Melee" then UpdateMelee(self) end else Text:SetText(hexa.."No Stats"..hexb) end int = 2 end plugin:SetScript("OnEnter", function() ShowTooltip(plugin) end) plugin:SetScript("OnLeave", function() GameTooltip:Hide() end) plugin:SetScript("OnUpdate", Update) Update(plugin, 10) return plugin -- important! end Thanks Coke |
|
11-02-14, 02:22 PM | #2 |
I take it you debugged it and it highlights that it is passing true for mana in hunters for a split second somewhere during that port before realising it is not really mana ?
Although maybe it is best to check for the class and spec to decide on damager type rather than rely on the power source. Just a thought.
__________________
All Level 70 Characters: Demon Warlock Resto Druid Disc Priest Resto Shaman Survival Hunter Augment Evoker Frost Mage Vengence Demon Hunter Rogue ( was subtlety ) Brewmaster Monk (TR) Prot Paladin (TR) Blood Death Knight ( TR) As you can see I am missing a warrior And .. I don't have all the allied races covered. Time Runner time when it happens again Last edited by Xrystal : 11-02-14 at 02:24 PM. |
|
11-02-14, 08:16 PM | #3 | ||
I'd also suggest using values for "playerRole" that more closely match the values from role-related API functions, so "TANK" instead of "Tank", "HEALER" instead of "Healer", "DAMAGER" instead of "Melee", and just add an extra "CASTER" value for casters. This way you can cut out half your if/then checks. I would just do something like this: Code:
local playerRole local isCaster = { DRUID = { true }, -- Balance MAGE = { true, true, true }, -- all specs PRIEST = { nil, nil, true }, -- Shadow SHAMAN = { true }, -- Elemental WARLOCK = { true, true, true } -- all specs } function nData:UpdatePlayerRole() local spec = GetSpecialization() if not spec then playerRole = nil return end local specRole = GetSpecializationRole(spec) if specRole == "DAMAGER" then local _, class = UnitClass("player") if isCaster[class][spec] then playerRole = "CASTER" return end end playerRole = specRole end
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. |
|||
11-03-14, 10:42 AM | #4 | ||
I had to remove the: Code:
local playerRole Also I had to change the below to show all the classes or a error popped up when it went to look for "CASTER" Lua Code:
Here is the new Statisctics.lua file: Lua Code:
Thank You for all the help with the nData project. Coke Last edited by cokedrivers : 11-03-14 at 11:40 AM. |
|||
11-03-14, 01:52 PM | #5 | |
That code is setting a global "playerRole" variable. Put "local playerRole" at the top of the file. It probably didn't work before because you were defining the variable too far down in the file. Remember, you need to define variables above any parts of the code where you read from or write to them.
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. |
||
11-03-14, 02:11 PM | #6 | |
Code:
-- no need to make a separate frame to handle events, your module object already does this! self:UpdatePlayerRole() self:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED", "UpdatePlayerRole") |
||
11-03-14, 05:05 PM | #7 |
If you want it to work across different files, the simplest solution would be to add the "playerRole" value to your addon's object instead of having it a standalone variable.
Remove the line where you declare the variable in your main file: Code:
local playerRole
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. |
|
11-03-14, 06:08 PM | #8 | |
Code:
function nData:UpdatePlayerRole() local spec = GetSpecialization() if not spec then self.playerRole = nil return end local specRole = GetSpecializationRole(spec) if specRole == "DAMAGER" then if isCaster[class][spec] then self.playerRole = "CASTER" return end end self.playerRole = specRole end Thanks for helping me on this. Coke |
||
WoWInterface » Developer Discussions » Lua/XML Help » Stat Switching Unexpectedly |
«
Previous Thread
|
Next Thread
»
|
Thread Tools | |
Display Modes | |
|
|