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.
"$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.
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:
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
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:
- How many are interested in this?
- Any ideas and suggestions about convenient features!