Modifying slarks ability but it is not working

edited February 2017 in Questions

When I kill a hero the ability is supposed to apply the debuff and buff it normally would from his regular attack but instead does nothing I am not sure what is wrong. Modified code snipet from Spell Library Library tool

  "slark_essence_shift_datadriven"
{

    // General
    //-------------------------------------------------------------------------------------------------------------
    "BaseClass"                     "ability_datadriven"
    "AbilityBehavior"               "DOTA_ABILITY_BEHAVIOR_PASSIVE"
    "SpellImmunityType"             "SPELL_IMMUNITY_ENEMIES_YES"
    "AbilityTextureName"            "slark_essence_shift"
    "MaxLevel"            "1"

    // Special
    //-------------------------------------------------------------------------------------------------------------
    "AbilitySpecial"
    {
        "01"
        {
            "var_type"              "FIELD_INTEGER"
            "agi_gain"              "1"
        }
        "02"
        {
            "var_type"              "FIELD_INTEGER"
            "stat_loss"             "-1"
        }


    }


    "Modifiers"
    {
        "modifier_slark_essence_shift_datadriven"  //This modifier is always on Slark and simply triggers a script when an autoattack lands on an enemy.
        {
            "Passive"   "0"
            "IsHidden"  "1"

            "OnHeroKilled"
            {
                "RunScript"
                {
                    "ScriptFile"                "essence_shift.lua"
                    "Function"                  "modifier_slark_essence_shift_datadriven_on_attack_landed"
                    "StatLoss"                  "%stat_loss"
                }
            }
        }
        "modifier_slark_essence_shift_datadriven_buff_counter"  //A visible counter that will appear in Slark's modifier bar.
        {

            "Passive"           "0"
            "IsHidden"          "0"
        }
        "modifier_slark_essence_shift_datadriven_debuff_counter"  //A visible counter that will appear in Slark's target's modifier bar.
        {

            "Passive"           "0"
            "IsHidden"          "0"
            "IsBuff"            "0"
            "IsDebuff"          "1"
            "IsPurgable"        "0"
        }
        "modifier_slark_essence_shift_datadriven_buff"
        {

            "Passive"               "0"
            "IsHidden"              "1"
            "Attributes"            "MODIFIER_ATTRIBUTE_MULTIPLE | MODIFIER_ATTRIBUTE_PERMANENT"

            "Properties"
            {
                "MODIFIER_PROPERTY_STATS_AGILITY_BONUS"     "%agi_gain"
                "MODIFIER_PROPERTY_STATS_STRENGTH_BONUS"     "%agi_gain"
                "MODIFIER_PROPERTY_STATS_INTELLECT_BONUS"     "%agi_gain"
            }


        }
        "modifier_slark_essence_shift_datadriven_debuff"
        {

            "Passive"               "0"
            "IsHidden"              "1"
            "Attributes"            "MODIFIER_ATTRIBUTE_MULTIPLE | MODIFIER_ATTRIBUTE_PERMANENT"

            "Properties"
            {
                "MODIFIER_PROPERTY_STATS_STRENGTH_BONUS"        "%stat_loss"
                "MODIFIER_PROPERTY_STATS_AGILITY_BONUS"         "%stat_loss"
                "MODIFIER_PROPERTY_STATS_INTELLECT_BONUS"       "%stat_loss"
            }


        }
    }
}

using the original code for calculations

function modifier_slark_essence_shift_datadriven_on_attack_landed(keys)
    if keys.target:IsHero() and keys.target:IsOpposingTeam(keys.caster:GetTeam()) then
        --For the affected enemy, increment their visible counter modifier's stack count.
        local previous_stack_count = 0
        if keys.target:HasModifier("modifier_slark_essence_shift_datadriven_debuff_counter") then
            previous_stack_count = keys.target:GetModifierStackCount("modifier_slark_essence_shift_datadriven_debuff_counter", keys.caster)

            --We have to remove and replace the modifier so the duration will refresh (so it will show the duration of the latest Essence Shift).
            keys.target:RemoveModifierByNameAndCaster("modifier_slark_essence_shift_datadriven_debuff_counter", keys.caster)
        end
        keys.ability:ApplyDataDrivenModifier(keys.caster, keys.target, "modifier_slark_essence_shift_datadriven_debuff_counter", nil)
        keys.target:SetModifierStackCount("modifier_slark_essence_shift_datadriven_debuff_counter", keys.caster, previous_stack_count + 1)      

        --Apply a stat debuff to the target StatLoss number of times.  Attributes bottom out at 0, so we do not need to worry about
        --applying more debuffs than attribute points the target currently has.  This is the way the stock Essence Shift works.
        local i = 0
        local stat_loss_abs = math.abs(keys.StatLoss)
        while i < stat_loss_abs do
            keys.ability:ApplyDataDrivenModifier(keys.caster, keys.target, "modifier_slark_essence_shift_datadriven_debuff", nil)
            i = i + 1
        end

        --For Slark, update his visible counter modifier's stack count and duration, and raise his Agility.  The full amount of Agility is gained
        --even if the target does not have any more attributes to steal.
        previous_stack_count = 0
        if keys.caster:HasModifier("modifier_slark_essence_shift_datadriven_buff_counter") then
            previous_stack_count = keys.caster:GetModifierStackCount("modifier_slark_essence_shift_datadriven_buff_counter", keys.caster)

            --We have to remove and replace the modifier so the duration will refresh (so it will show the duration of the latest Essence Shift).
            keys.caster:RemoveModifierByNameAndCaster("modifier_slark_essence_shift_datadriven_buff_counter", keys.caster)
        end
        keys.ability:ApplyDataDrivenModifier(keys.caster, keys.caster, "modifier_slark_essence_shift_datadriven_buff_counter", nil)
        keys.caster:SetModifierStackCount("modifier_slark_essence_shift_datadriven_buff_counter", keys.caster, previous_stack_count + 1)

        --Apply an Agility buff for Slark.
        keys.ability:ApplyDataDrivenModifier(keys.caster, keys.caster, "modifier_slark_essence_shift_datadriven_buff", nil)
    end
end

Comments

  • Posts: 96

    Just a quick reminder, since the code is literally taken straight from this KV file and this lua file in public spell library, so please do give credit to contributor.

    The error in your code would be changing from "OnHeroKilled" to "OnAttackLanded" or "OnHeroKill" if you still want it to still have behavior from geetting stat from killing hero. Refer to this guide if you're not yet familiar with the datadriven ability yet.

  • Posts: 14

    Okay thanks I updated that also I have taken a look at that and i still cant find my answer I just tested copying the entire spell over without modifying it and adding it to the hero with hero:AddAbility("slark_essence_shift_datadriven") when the game starts... it gets added but the ability does not work

  • edited February 2017 Posts: 96

    Make sure your lua file is in correct path in

    • /game/.../scripts/vscripts/heroes/hero_slark/essence_shift.lua (from original code)

    or

    • /game/.../scripts/vscripts/essence_shift.lua (from the code provided above)
  • Posts: 14

    @kritth okay I think that would be it since i dont have it in vscripts i have it in the npc folder with my custom abilities code (slark ability). I didn't know the default path it would search was in vscripts