• 🏆 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!

[LUA] Spell and Tooltip-update System

Level 3
Joined
Dec 20, 2017
Messages
13
Hi everyone! I've been making a system for automatically updating tooltips (and optionally for creating spells, but I go won't into that). I'm considering uploading it as a resource but want to know if people are actually interested since it requires a lot of work. It should be compatible with other spell systems if you only use the functionality for updating the tooltips. I'll just give a small overview. The system is MUI of course, for example multiple heroes can have the same ability and have their tooltips individually updated based on their own int. While it's primarily meant for hero-abilities, it more or less works on normal unit abilities too.

Ex 1. Lets create a tooltip for the blizzard spell. The base spell is completely unchanged. The code below only updates the tooltip, without actually changing anything else about the ability. This is the part I think should be compatible with almost all other spell systems.
Lua:
do -- Blizzard
    local tooltip = "Calls down waves of freezing ice shards that each deals $anyName (2*level*int) in a target area."
 
    ---@param thisAbility WAbility -- Here we set the values of any variables.
    local function update(thisAbility)
        thisAbility.vars.anyName = 2*thisAbility.level*GetHeroInt(thisAbility.owner, true)
    end

    WSpell.Create('AHbz', tooltip, update) --AHbz is the abilityId for blizzard
end
"$someVariable" is used to identify a variable that will be continually updated during the game. The value has to be set in the update function. It's always located in "thisAbility.vars".
For performance reasons it's also possible to create constants, for showing things like AoE, cooldown etc. that might not change: "$$someConstant". There can be any number of variables and constants in a tooltip. They can be tables.
As you might have noticed, the variable isn't displayed while learning the ability. This is because the learning tooltip is shared for all units. It's possible to pass another argument for learning tooltip.

Ex 2. Lets create a MUI rain of fire spell that actually deals damage this time. Damage is 1, 3, 7*int depending on level. The base spell is completely unchanged except for the maximum damage per wave, which is set to 99999 for all levels.
Lua:
do -- Rain of fire
    local tooltip = "Calls down $$waves waves of fire that each deals $dmg ($$scaling*int) in a target area."
    WUtils.AddColor("dmg", "green")
    ---@param thisAbility WAbility
        local function update(thisAbility)
            local lvl = thisAbility.level
            local dmg = thisAbility.consts.scaling[lvl]*GetHeroInt(thisAbility.owner, true)
            thisAbility.vars.dmg = dmg
            thisAbility:SetRealLevelField('Hbz2', dmg) -- Hbz2 is the fieldId for Rain of fire -> damage
        end
     
    ---@param spell WSpell -- consts are always set in init. Because they are set before any actual ability exists.
        local function init(spell)
            spell.consts.waves = {5, 7, 10} -- I'll skip actually updating the number of waves.
            spell.consts.scaling = {1, 3, 7}
        end
    WSpell.Create('ANrf', tooltip, update, init) --ANrf is the abilityId for Rain of Fire
end

This is a pretty brief, so I'll be happy to elaborate on the code above if it's unclear There are other features too, e.g. it's possible to access EVENT_UNIT_SPELL_EFFECT and other events.
It's basically done, but I'm about to rewrite parts of the system soon to make it less messy. So I'm mainly looking for 2 things:
  1. How many are interested in this?
  2. Any ideas and suggestions about convenient features!
Have a nice day!
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,468
I do have a bit of input I can share:

The API naming should reflect what it does. The W- prefix is probably just something that worked in your map, but in a public resource, imagine there being hundreds of different systems. Yours should be named something specific, like AutoTooltip for example.

If you intend to convey arithmetic in a tooltip, the readable format is to use ' x ' rather than '*'. The asterisk is only used in programming languages, because there are variable names that could be named "x". But in a string like this, 1 x 10 x int would be more readable than 1*10*int.

This is not to say that conveying math in a tooltip is a good idea. I'm just saying if there is no better way, how I perceive it as being more reable with "x".
 
Level 3
Joined
Dec 20, 2017
Messages
13
Thanks for the feedback!

I'll consider the name after I rewrite it and know the exact features.

You're totally right about '*' now that I think about it. I'll change it for my map since I've been bother by the ugliness :) But it doesn't really matter for the quality of the system, since the user of the resource can write whatever character they want. If I make a resource I'll try to remember to change it for the examples too.

I'm not too familiar with the tools for Warcraft today. Is this something that is already present in many maps or made obsolete by or is incompatible with the tools commonly used?
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,468
Have a look at how League of Legends does it:
1705992798114.png

I think this is a very good way to represent the data.
 
Level 3
Joined
Dec 20, 2017
Messages
13
I'm a bit uncertain of what you mean. I agree that it's really good and looked at league too, but my system doesn't work with frames, so I can't really change the appearance of the tooltip. My intention was to simply have it update values like the magic damage below without forcing a specific formatting on the user.
1706195781459.png

Are you suggesting I standardize the formatting?
 
Level 3
Joined
Dec 20, 2017
Messages
13
Isn't that what I show it can do with the second spell, Rain of Fire? Also, I think there's a misunderstanding. That's not really a part of the system itself. Just like you can use a formula or plain numbers in normal tooltips, you can do here.
 
Top