Passing AbilitySpecial values into Lua

edited January 2015 in Tutorials

Given this "AbilitySpecial" block in the ability:

"AbilitySpecial"
{
    "01"
    {
        "var_type"  "FIELD_INTEGER"
        "radius"    "300"
    }
    "02"
    {
        "var_type"  "FIELD_INTEGER"
        "mana_per_second"   "5 10 15 20"
    }
}

There are 2 functions to connect these with ua. GetSpecialValueFor and GetLevelSpecialValueFor. Both are applied over an ability.

local event.ability = ability
local radius = ability:GetSpecialValueFor("radius") 
local mana_per_second = ability:GetLevelSpecialValueFor("mana_per_second", (ability:GetLevel() - 1))

The first one can be used only for single level values. If you use GetSpecialValueFor (no Level) on "mana_per_second" it will only get the value for the first level.

The second one is the most common and should be used every time to avoid mistakes.

Note the use of (ability:GetLevel() - 1) as the second parameter (which tells the script which level to take). This is needed because ability levels are 1-indexed but GetLevelSpecialValueFor is 0-indexed.

The concept of Modding Community doesn't go well together with Competitive Business
My Project Page || My GitHub Profile ||

Comments

  • Posts: 1,670

    AbilityDuration tooltips.

    TL;DR: AbilityDuration is a fairly useless keyvalue because whoever coded it forgot to make an automatic tooltip like with AbilityDamage.

    Imagine you want to have an ability apply a modifier for some seconds, duration changing with levels.

    You can fall for the trap and do this:

    "AbilityDuration" "3 2 2"
    

    And then have your modifier refer to %AbilityDuration in the "Duration" modifier key. All fine for now.

    But when when you want to indicate that your ability lasts for said duration, this AbilityDuration doesn't generate a "DURATION:" tooltip by itself, so you have 3 options:

    Option 1. Write "Last 3 seconds at level 1 and then 2 at level 2 and 3" in the _Description.

    This is bad for the reasons explained before.

    Option 2*. Have a "duration" AbilitySpecial in addition to the "AbilityDuration" and keep both values syncronized.

    Suboptimal but decent solution, as it allows you to use ability:GetAbilityDuration() which takes takes its value from AbilityDuration.

    Option 3. Remove AbilityDuration, only keep the AbilitySpecial. Best way as far as I can tell.

    "AbilitySpecial"
    {
        "01"
        {
            "var_type" "FIELD_INTEGER"
            "duration" "3 2 2"
        }
    }
    

    And then do this in a Lua Script if needed.

    function HowToTooltip(event)
       local ability = event.ability
       local duration = ability:GetLevelSpecialValueFor("duration", (ability:GetLevel() - 1))
       local damage = ability:GetAbilityDamage()
    end
    

    Has the same results and works for every scenario.

    The concept of Modding Community doesn't go well together with Competitive Business
    My Project Page || My GitHub Profile ||