WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Help with checking a Players Role (https://www.wowinterface.com/forums/showthread.php?t=56851)

cokedrivers 11-18-18 09:24 AM

Help with checking a Players Role
 
So im trying to get the players role with the following code:

Code:

local isCaster = {
        -- All Classes are needed as to not cause a error when the table is called.
        -- SpecID - Spec - Role
        DEATHKNIGHT = {
                nil, -- 250 - Blood - (TANK)
                nil, -- 251 - Frost - (MELEE_DPS)
                nil, -- 252 - Unholy - (MELEE_DPS)
        },
        DEMONHUNTER = {
                nil, -- 577 - Havoc - (TANK)
                nil, -- 581 - Vengeance - (MELEE_DPS)
        },
        DRUID = {
                true, -- 102 - Balance - (CASTER_DPS)
                nil,  -- 103 - Feral - (MELEE_DPS)
                nil,  -- 104 Guardian - (TANK)
                nil,  -- 105 Restoration - (HEALER)
        },
        HUNTER = {
                nil, -- 253 - Beast Mastery - (RANGED_DPS)
                nil, -- 254 - Marksmanship - (RANGED_DPS)
                nil, -- 255 - Survival - (RANGED_DPS)
        },
        MAGE = {
                true, -- 62 - Arcane - (CASTER_DPS)
                true, -- 63 - Fire - (CASTER_DPS)
                true, -- 64 - Frost - (CASTER_DPS)
        },
        MONK = {
                nil, -- 268 - Brewmaster - (TANK)
                nil, -- 269 - Windwalker - (MELEE_DPS)
                nil, -- 270 - Mistweaver - (HEALER)
        },
        PALADIN = {
                nil, -- 65 - Holy - (HEALER)
                nil, -- 66 - Protection - (TANK)
                nil, -- 70 - Retribution - (MELEE_DPS)
        },
        PRIEST = {
                nil,  -- 256 - Discipline - (HEALER}
                nil,  -- 257 - Holy - (HEALER)
                true, -- 258 - Shadow - (CASTER_DPS)
        },
        ROGUE = {
                nil, -- 259 - Assassination - (MELEE_DPS)
                nil, -- 260 - Combat - (MELEE_DPS)
                nil, -- 261 - Subtlety - (MELEE_DPS)
        },
        SHAMAN = {
                true, -- 262 - Elemental - (CASTER_DPS)
                nil,  -- 263 - Enhancement - (MELEE_DPS)
                nil,  -- 264 - Restoration - (HEALER)
        },
        WARLOCK = {
                true, -- 265 - Affliction - (CASTER_DPS)
                true, -- 266 - Demonology - (CASTER_DPS)
                true, -- 267 - Destruction - (CASTER_DPS)
        },
        WARRIOR = {
                nil, -- 71 - Arms - (MELEE_DPS)
                nil, -- 72 - Furry - (MELEE_DPS)
                nil, -- 73 - Protection - (TANK)
        },
}


local spec = GetSpecialization()
if not spec then
        playerRole = nil
        return
end

local specRole = GetSpecializationRole(spec)
if specRole == "DAMAGER" then
        if isCaster[class][spec] then
                playerRole = "CASTER"
                return
        end
end

local playerRole = specRole

but it is not pulling any info when i us it in one of my stats like:
Code:

        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

can anyone help out with this.

Now i do get it to wrok if i use Ace3 Libs but Im trying to get my addon as slim as possible.

Thanks in Advance
Coke

jlam 11-18-18 10:10 AM

I don't think GetSpecialization() returns a spec ID. You want GetInspectSpecialization(), but I think that only returns valid information after you call NotifyInspect() and wait for an appropriate INSPECT_READY event. It's possible that it always returns good information for the "player" unit, but I'm not sure.

When does your example code that initializes playerRole execute? Specialization information is definitely not available when an addon loads, so at the very least, you will need to wait for an appropriate event (perhaps PLAYER_ENTERING_WORLD?) to fetch the specialization information.

I just recently went through this dance for MooInspect-1.0 and MooSpec-1.0 if you want to look at the code for those two library addons on GitHub. You could also directly use MooInspect-1.0 and use lib:QueueInspect(playerGUID) and wait on MooInspect_InspectReady toi initialize your playerRole.

Fizzlemizz 11-18-18 10:57 AM

Do mean while in a group?
Lua Code:
  1. local role = UnitGroupRolesAssigned(unit)
  2. if role == "HEALER" then
  3.  
  4. elseif role == "DAMAGER" then
  5.  
  6. else
  7.  
  8. end

cokedrivers 11-18-18 11:08 AM

2 Attachment(s)
Quote:

Originally Posted by Fizzlemizz (Post 330869)
Do mean while in a group?
Lua Code:
  1. local role = UnitGroupRolesAssigned(unit)
  2. if role == "HEALER" then
  3.  
  4. elseif role == "DAMAGER" then
  5.  
  6. else
  7.  
  8. end

No i use it for my own info

If i use the ace3 Libs it works fine like the 1st image shows, but when i do not use ace3 libs it looks like image 2.

if you look at the Data also the middle stat the Spec stat does not work either.

Here are the lua for each:

Spec Stat =
Code:

        local plugin = CreateFrame('Frame', nil, Datapanel)
        plugin:EnableMouse(true)
        plugin:SetFrameStrata('BACKGROUND')
        plugin:SetFrameLevel(3)

        local Text = plugin:CreateFontString(nil, 'OVERLAY')
        Text:SetFont(cfg.font, cfg.fontSize,'THINOUTLINE')
        PlacePlugin(cfg.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


        plugin:SetScript('OnEnter', function(self)
                local anchor, panel, xoff, yoff = DataTextTooltipAnchor(Text)
                GameTooltip:SetOwner(panel, anchor, xoff, yoff)

                GameTooltip:ClearLines()
                GameTooltip:AddLine(hexa..playerName.."'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)

        plugin: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



        plugin:RegisterEvent('PLAYER_ENTERING_WORLD');
        plugin:RegisterEvent('CHARACTER_POINTS_CHANGED');
        plugin:RegisterEvent('PLAYER_TALENT_UPDATE');
        plugin:RegisterEvent('ACTIVE_TALENT_GROUP_CHANGED')
        plugin:RegisterEvent("EQUIPMENT_SETS_CHANGED")
        plugin:SetScript('OnEvent', OnEvent)
        plugin:SetScript('OnUpdate', Update)

        plugin:SetScript("OnMouseDown", function() ToggleTalentFrame() end)

Statistics Stat =
Code:

        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(cfg.font, cfg.fontSize,'THINOUTLINE')
        PlacePlugin(cfg.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..playerName.."'s"..hexb.." Statistics")
                GameTooltip:AddLine' '               
                if playerRole == nil then
                        GameTooltip:AddLine("Choose a Specialization to see Stats")
                else
                        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 == "HEALER" or 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 == "DAMAGER" 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
                        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 = 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_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)                       
                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 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 playerRole == nil then
                        Text:SetText(hexa.."No Stats"..hexb)
                else
                        if playerRole == "TANK" then
                                UpdateTank(self)
                        elseif playerRole == "HEALER" or playerRole == "CASTER" then
                                UpdateCaster(self)
                        elseif playerRole == "DAMAGER" then
                                UpdateDamager(self)
                        end
                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)


Xrystal 11-18-18 12:21 PM

It might be that the Ace libraries are accessing the talent information at the correct time.

If you aren't already, you probably have to make sure that the Blizzard_TalentUI addon is loaded before you start playing with specialization details.

You might have to look at the code of the Ace libraries and see how and when they are using the specialization stuff.

cokedrivers 11-18-18 01:12 PM

Thanks everyone for the tips but i figured it out by going back into some of my other datapanel addons.

This is the code that works:
Code:

--Check Player's Role

local classRoles = {

        DEATHKNIGHT = {
                [1] = "TANK",        -- 250 - Blood - (TANK)
                [2] = "DAMAGER",        -- 251 - Frost - (MELEE_DPS)
                [3] = "DAMAGER",        -- 252 - Unholy - (MELEE_DPS)
        },
        DEMONHUNTER = {
                [1] = "DAMAGER",        -- 577 - Havoc - (MELEE_DPS)
                [2] = "TANK",        -- 581 - Vengeance - (TANK)
        },
        DRUID = {
                [1] = "CASTER", -- 102 - Balance - (CASTER_DPS)
                [2] = "DAMAGER",  -- 103 - Feral - (MELEE_DPS)
                [3] = "TANK",          -- 104 Guardian - (TANK)
                [4] = "HEALER", -- 105 Restoration - (HEALER)
        },
        HUNTER = {
                [1] = "DAMAGER", -- 253 - Beast Mastery - (RANGED_DPS)
                [2] = "DAMAGER", -- 254 - Marksmanship - (RANGED_DPS)
                [3] = "DAMAGER",        -- 255 - Survival - (RANGED_DPS)
        },
        MAGE = {
                [1] = "CASTER", -- 62 - Arcane - (CASTER_DPS)
                [2] = "CASTER", -- 63 - Fire - (CASTER_DPS)
                [3] = "CASTER", -- 64 - Frost - (CASTER_DPS)
        },
        MONK = {
                [1] = "TANK",        -- 268 - Brewmaster - (TANK)
                [2] = "DAMAGER",        -- 269 - Windwalker - (MELEE_DPS)
                [3] = "HEALER", -- 270 - Mistweaver - (HEALER)
        },
        PALADIN = {
                [1] = "HEALER", -- 65 - Holy - (HEALER)
                [2] = "TANK",        -- 66 - Protection - (TANK)
                [3] = "DAMAGER",        -- 70 - Retribution - (MELEE_DPS)
        },
        PRIEST = {
                [1] = "HEALER", -- 256 - Discipline - (HEALER}
                [2] = "HEALER", -- 257 - Holy - (HEALER)
                [3] = "CASTER", -- 258 - Shadow - (CASTER_DPS)
        },
        ROGUE = {
                [1] = "DAMAGER",  -- 259 - Assassination - (MELEE_DPS)
                [2] = "DAMAGER",  -- 260 - Combat - (MELEE_DPS)
                [3] = "DAMAGER",  -- 261 - Subtlety - (MELEE_DPS)
        },
        SHAMAN = {
                [1] = "CASTER", -- 262 - Elemental - (CASTER_DPS)
                [2] = "DAMAGER",  -- 263 - Enhancement - (MELEE_DPS)
                [3] = "HEALER", -- 264 - Restoration - (HEALER)
        },
        WARLOCK = {
                [1] = "CASTER", -- 265 - Affliction - (CASTER_DPS)
                [2] = "CASTER", -- 266 - Demonology - (CASTER_DPS)
                [3] = "CASTER", -- 267 - Destruction - (CASTER_DPS)
        },
        WARRIOR = {
                [1] = "DAMAGER",        -- 71 - Arms - (MELEE_DPS)
                [2] = "DAMAGER",        -- 72 - Furry - (MELEE_DPS)
                [3] = "TANK",        -- 73 - Protection - (TANK)
        },
}

local _, playerClass = UnitClass("player")
local playerRole
local function CheckRole()
        local talentTree = GetSpecialization()

        if(type(classRoles[playerClass]) == "string") then
                playerRole = classRoles[playerClass]
        elseif(talentTree) then
                playerRole = classRoles[playerClass][talentTree]
        end
end

local eventHandler = CreateFrame("Frame")
eventHandler:RegisterEvent("PLAYER_ENTERING_WORLD")
eventHandler:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
eventHandler:RegisterEvent("PLAYER_TALENT_UPDATE")
eventHandler:RegisterEvent("CHARACTER_POINTS_CHANGED")
eventHandler:SetScript("OnEvent", CheckRole)

Thanks Agian
Coke

myrroddin 11-18-18 08:24 PM

Quote:

Originally Posted by Xrystal (Post 330871)
You might have to look at the code of the Ace libraries and see how and when they are using the specialization stuff.

Ace doesn't touch specialization (or really any event handling except ADDON_LOADED and PLAYER_ENTERING_WORLD).

What Ace does do is want coders to use OnInitialize to set up one-time, fire-and-forget things like LDB setup, slash commands, and registering your saved variables. OnEnable is where coders should be registering events and things that AddOns need when they are enabled. OnDisable is used for unregistering events and doing shutdown things like wiping variables.

myrroddin 11-18-18 08:37 PM

What you are probably seeing, as to why Ace3 is giving you "Beast Mastery" whereas non-Ace3 is "No Spec" is because of what I said above. OnInitialize registers ADDON_LOADED, but then unregisters ADDON_LOADED behind the scenes. OnEnable, behind the scenes, does the same thing with PEW, meaning the character has fully loaded into the game at that point.

Following that logic, without Ace3, if you want your specialization data, register for PEW, get your data, then unregister.

Xrystal 11-18-18 08:46 PM

Thanks for clarifying myrroddin. I don't use Ace myself but know some things don't work until certain addons are loaded or events are called. I always used ADDON_LOADED and/or PLAYER_ENTERING_WORLD with my addons so never even considered those events being the missing link rofl.

jlam 11-20-18 10:32 PM

Quote:

Originally Posted by myrroddin (Post 330874)
What you are probably seeing, as to why Ace3 is giving you "Beast Mastery" whereas non-Ace3 is "No Spec" is because of what I said above. OnInitialize registers ADDON_LOADED, but then unregisters ADDON_LOADED behind the scenes. OnEnable, behind the scenes, does the same thing with PEW, meaning the character has fully loaded into the game at that point.

Following that logic, without Ace3, if you want your specialization data, register for PEW, get your data, then unregister.

I don't think that's quite right. AceAddon-3.0 probably registers PLAYER_LOGIN to trigger all of the OnEnable() methods of any Ace3 addons, since OnEnable is only run once per login. PLAYER_ENTERING_WORLD is the event that fires when your UI gets that loading screen. Regardless, PLAYER_ENTERING_WORLD is usually a good event to register if you want to get game information -- it's the same one that the Blizzard addons usually register for that same purpose.

Vrul 11-21-18 07:50 AM

You can get rid of hard coding each class with:
Code:

--Check Player's Role

local playerRole
local function CheckRole()
    local specIndex = GetSpecialization()
    if specIndex then
        local _, _, _, _, _, role, priStat = GetSpecializationInfo(index)
        playerRole = role == "DAMAGER" and priStat == 4 and "CASTER" or role
    else
        playerRole = nil
    end
end

local eventHandler = CreateFrame("Frame")
eventHandler:RegisterEvent("PLAYER_ENTERING_WORLD")
eventHandler:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
eventHandler:RegisterEvent("PLAYER_TALENT_UPDATE")
eventHandler:RegisterEvent("CHARACTER_POINTS_CHANGED")
eventHandler:SetScript("OnEvent", CheckRole)

Or you could just use the normal roles and replace
Code:

elseif playerRole == "HEALER" or playerRole == "CASTER" then
with
Code:

elseif isCaster then
by using
Code:

--Check Player's Role

local playerRole, isCaster
local function CheckRole()
    local specIndex = GetSpecialization()
    if specIndex then
        local _, priStat
        _, _, _, _, _, playerRole, priStat = GetSpecializationInfo(index)
        isCaster = priStat == 4
    else
        playerRole = nil
    end
end

local eventHandler = CreateFrame("Frame")
eventHandler:RegisterEvent("PLAYER_ENTERING_WORLD")
eventHandler:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
eventHandler:RegisterEvent("PLAYER_TALENT_UPDATE")
eventHandler:RegisterEvent("CHARACTER_POINTS_CHANGED")
eventHandler:SetScript("OnEvent", CheckRole)


myrroddin 11-21-18 08:16 PM

Quote:

Originally Posted by jlam (Post 330889)
I don't think that's quite right. AceAddon-3.0 probably registers PLAYER_LOGIN to trigger all of the OnEnable() ...

I sit corrected. I haven't actually looked at Ace3's code in ages.

cokedrivers 11-22-18 09:25 AM

Quote:

Originally Posted by Vrul (Post 330891)
You can get rid of hard coding each class with:
Code:

--Check Player's Role

local playerRole
local function CheckRole()
    local specIndex = GetSpecialization()
    if specIndex then
        local _, _, _, _, _, role, priStat = GetSpecializationInfo(index)
        playerRole = role == "DAMAGER" and priStat == 4 and "CASTER" or role
    else
        playerRole = nil
    end
end

local eventHandler = CreateFrame("Frame")
eventHandler:RegisterEvent("PLAYER_ENTERING_WORLD")
eventHandler:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
eventHandler:RegisterEvent("PLAYER_TALENT_UPDATE")
eventHandler:RegisterEvent("CHARACTER_POINTS_CHANGED")
eventHandler:SetScript("OnEvent", CheckRole)


The Above code throws this error:
Code:

2x BasicUILite\Modules/Datatext.lua:185: Usage: GetSpecializationInfo(specIndex[, isInspect[, isPet[, inspectTarget[, sex]]]])
[C]: in function `GetSpecializationInfo'
BasicUILite\Modules/Datatext.lua:185: in function <BasicUILite\Modules/Datatext.lua:182>

Locals:
(*temporary) = nil


Quote:

Originally Posted by Vrul (Post 330891)
by using
Code:

--Check Player's Role

local playerRole, isCaster
local function CheckRole()
    local specIndex = GetSpecialization()
    if specIndex then
        local _, priStat
        _, _, _, _, _, playerRole, priStat = GetSpecializationInfo(index)
        isCaster = priStat == 4
    else
        playerRole = nil
    end
end

local eventHandler = CreateFrame("Frame")
eventHandler:RegisterEvent("PLAYER_ENTERING_WORLD")
eventHandler:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
eventHandler:RegisterEvent("PLAYER_TALENT_UPDATE")
eventHandler:RegisterEvent("CHARACTER_POINTS_CHANGED")
eventHandler:SetScript("OnEvent", CheckRole)


The above code throws this error:
Code:

9x BasicUILite\Modules/Datatext.lua:188: Usage: GetSpecializationInfo(specIndex[, isInspect[, isPet[, inspectTarget[, sex]]]])
[C]: in function `GetSpecializationInfo'
BasicUILite\Modules/Datatext.lua:188: in function <BasicUILite\Modules/Datatext.lua:184>

Locals:
(*temporary) = nil

I would love to use one of these for less code in the coding but they seem not to work.

Thank You for trying.
Coke

Rilgamon 11-22-18 10:15 AM

Lua Code:
  1. GetSpecializationInfo(index)
Replace index with specIndex

cokedrivers 11-22-18 11:36 AM

Quote:

Originally Posted by Rilgamon (Post 330900)
Lua Code:
  1. GetSpecializationInfo(index)
Replace index with specIndex

That works for the one plugin for spec but i have another that uses the CASTER or HEALER for stats.

Code:

        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(cfg.font, cfg.fontSize,'THINOUTLINE')
        PlacePlugin(cfg.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..playerName.."'s"..hexb.." Statistics")
                GameTooltip:AddLine' '               
                if playerRole == nil then
                        GameTooltip:AddLine("Choose a Specialization to see Stats")
                else
                        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 == "HEALER" or 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 == "DAMAGER" 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
                        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 = 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_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)                       
                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 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 playerRole == nil then
                        Text:SetText(hexa.."No Stats"..hexb)
                else
                        if playerRole == "TANK" then
                                UpdateTank(self)
                        elseif playerRole == "HEALER" or playerRole == "CASTER" then
                                UpdateCaster(self)
                        elseif playerRole == "DAMAGER" then
                                UpdateDamager(self)
                        end
                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)

How would i adjust for the new code?

Coke


All times are GMT -6. The time now is 07:06 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI