• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

[Lua] SetAbilityExtendedTooltip only works in certain conditions.

Status
Not open for further replies.
Level 2
Joined
Sep 5, 2015
Messages
10
I'm trying to make a system that updates hero tooltips based on their stats, however, player 1 and 2 both share the tooltips text based on player 1. I haven't tested with more than 2 players at the moment.

ALL of the code that contains anything to do with tooltips is below.

Lua:
function HeroCreated()
    local trigger = CreateTrigger()
    TriggerRegisterEnterRectSimple(trigger, bj_mapInitialPlayableArea)
    TriggerAddAction(trigger, function()
        if Hero_Initialized[GetTriggerUnit()] == nil and IsHeroUnitId(GetUnitTypeId(GetTriggerUnit())) then
            local u = GetTriggerUnit()
            local h = GetUnitTypeId(u)
            for i = MIN_PRIMARY, MAX_PRIMARY, 1 do
                Hero_Base_Stats[i][u] = Hero_Base_Stats[i][h]
                Hero_Scaling[i][u] = Hero_Scaling[i][h]
            end
            Hero_Initialized[u] = true
            Hero_Previous_Level[u] = GetHeroLevel(u)
            UnitAddAbility(u, FourCC('A00E'))
            SetUnitAbilityLevel(u, FourCC('A00E'), GetPlayerId(GetOwningPlayer(u)))
            UpdateStats(u)
        end
    end)
end

Lua:
  BlzSetAbilityTooltip(FourCC('A00E'), GetHeroProperName(u) .. ", the " .. GetUnitName(u), GetPlayerId(GetOwningPlayer(u)))
print("Player_Number " .. GetPlayerId(GetOwningPlayer(u)))
BlzSetAbilityExtendedTooltip(FourCC('A00E'), s, GetPlayerId(GetOwningPlayer(u)))

Lua:
function UpdateMilitiaDesc(h)
    local i = GetPlayerId(GetOwningPlayer(h))
    SetUnitAbilityLevel(h, FourCC('A00D'), i)
    SetUnitAbilityLevel(h, FourCC('A00J'), i)
    SetUnitAbilityLevel(h, FourCC('A00K'), i)

    local a = FourCC('A00D') -- Heavy Strike: Deal Physical Damage to a target enemy and knock them back.
    M_Heavy_Strike_Dmg[h] = Hero_Total_Stats[Damage.id][h] * 1.6
    M_Heavy_Strike_CD[h] = CalculateCooldown(8., h, a)
    local s = "Cleave the enemy with your pickaxe, dealing |c00ff80ff" .. math.floor(M_Heavy_Strike_Dmg[h] + 0.5) .. "|r|c00808080 (160%% AD)|r|c00ff0000 Physical Damage|r and knocking the enemy back a short distance.\n\n|c00808080Cooldown: " .. Round(M_Heavy_Strike_CD[h], 2) .." seconds|r"
    BlzSetAbilityExtendedTooltip(a, s, i)

    a = FourCC('A00J') -- Vigor: Restore mana and health over time after using an ability.
    M_Vigor_Hps[h] = (0.012 * GetUnitState(h, UNIT_STATE_MAX_LIFE))
    M_Vigor_Mps[h] = (0.006 * GetUnitState(h, UNIT_STATE_MAX_MANA))
    s = "Your body is prepared for your upcoming battles. Whenever you use an ability you gain |c00ff80ff" .. Round(M_Vigor_Hps[h], 2) .. "|r|c00808080 (1.2%% hp)|r Health Regeneration and |c00ff80ff" .. Round(M_Vigor_Mps[h], 2) .. "|r|c00808080 (0.6%% mp)|r Mana Regeneration for |c00ffff005|r seconds."
    BlzSetAbilityExtendedTooltip(a, s, i)

    a = FourCC('A00K') -- Taunt: Force all nearby enemies to attack you, restoring max hp for each taunted.
    M_Taunt_Healing[h] = GetUnitState(h, UNIT_STATE_MAX_LIFE) * 0.02
    M_Taunt_CD[h] = CalculateCooldown(12., h, a)
    s = "Let out a battle cry, forcing all enemies caught in the radius to attack you.\n\nFor each enemy taunted by this ability you restore |c00ffff002%%|r|c00ff80ff ("..Round(M_Taunt_Healing[h], 1)..")|r of your |c00ff8080Maximum Health|r.\n\n|c00808080Cooldown: ".. Round(M_Taunt_CD[h], 2) .. " seconds|r"
    BlzSetAbilityExtendedTooltip(a, s, i)
end

Here's the thing, when I try to switch all of the GetPlayerId() with GetConvertedPlayerId() OR GetPlayerId() + 1 the tooltips stop working entirely, nothing updates anymore and each ability has the base text. Each ability has 10 levels, so it's not because of the PlayerId going too high.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
Pretty much all of these new functions use an index starting at 0.

So when you use BlzSetAbilityExtendedTooltip and reference i, you're referencing a Level higher than you intended to. Try using:
Lua:
BlzSetAbilityExtendedTooltip(a, s, i-1)
 
Status
Not open for further replies.
Top