• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Ability - Set Ability Real Field doesn't change tooltip

Status
Not open for further replies.
Level 8
Joined
Oct 2, 2013
Messages
288
Does anyone know if there's a way to refresh or update the tooltip of a spell after changing a real or integer value in it?

Normally a chain lightning spell uses <ACcl,DataA1> to refer to it's damage. But after changing the Real field via triggers, the tooltip text still states the same damage. I know I can change this by changing the tooltip field as well via triggers but that's going to become a lot of work it seems.

Is there a way to simply make it update?

PS: I already tried setting the string field to the same, it didn't work. It just writes <ACcl,DataA1> instead of the damage.
 
Level 12
Joined
Feb 5, 2018
Messages
521
I think the datafields needs to be referenced to your "custom data". You need to change to codefields to match the custom data IIRC.
 
Level 2
Joined
Apr 26, 2020
Messages
2
I realize this thread is over a year old now, but I was also trying to figure out how best to update ability tooltips after changing the ability values such as damage and duration. The theory was easy, but I was getting tripped up by data types. Either way I thought I'd share what I found in case anyone else comes across this thread.

I'm using Lua for this, but this should be possible without Lua so I'll just roughly outline how I accomplished this without any code:

  1. Cache the original ability value you plan to change in a variable. (The value the map was saved with. I fetch this once when a hero learns an ability.)
  2. Get the ability tooltip and replace the original value with your new value, using whatever string replace method your chosen programming language provides. (This is one reason why we cached the original value.)
  3. Set the ability tooltip to your modified tooltip.

If you'd prefer to see some mock Lua code, here you go: (Using ability duration as an example.)
Lua:
local originalDuration = BlzGetAbilityRealLevelField(ability, ABILITY_RLF_DURATION_NORMAL, abilityLevel - 1) -- 0 based index, so 0 is level 1, 1 is level 2, ect..
local tooltip = BlzGetAbilityExtendedTooltip(abilityID, abilityLevel - 1)

-- We handle both integer values and float values below.
if string.find(tooltip, (duration .. " seconds")) then
    -- If we find the float verison of the value we replace it.
    local findText = originalDuration .. " seconds" -- Find this text.
    local newText = string.format("%%.2f", newDuration) .. " seconds" -- Replace findText with this text when found.
    BlzSetAbilityExtendedTooltip(abilityID, tooltip:gsub((findText), newText), abilityLevel - 1)
elseif string.find(tooltip, (math.floor(duration) .. " seconds")) then
    -- If we find the integer verison of the value we replace it.
    local findText = math.floor(originalDuration) .. " seconds" -- Find this text.
    local newText = string.format("%%.2f", newDuration) .. " seconds" -- Replace findText with this text when found.
    BlzSetAbilityExtendedTooltip(abilityID, tooltip:gsub((findText), newText), abilityLevel - 1)
end

-- gsub() finds the requested text and replaces it.
-- math.floor() rounds a floating point number down to the nearest whole number (integer): 43.9 becomes 43 as does 43.0
-- string.format() trims off any more than 2 decimal places: 43.6254 becomes 43.62
-- Encapsulate BlzSetAbilityExtendedTooltip in an 'if' block, checking against GetLocalPlayer(), to only change the tooltip for a specific player.
 
Last edited:
Status
Not open for further replies.
Top