More trouble with spells

edited July 2015 in Questions

I have this idea of two spells. The first will be a targeted projectile that does minor damage and when it hits its target leaves a de buff on the target. If I target a unit which already has the de buff I want it to stack. The second ability will have no target and when activated it will deal x amount of damage * the amounts of stacks from the first skill and pull the unit towards the caster. This is very similar to Shadow daemon's shadow poison. I would rather create the spell from scratch for learning purposes and not look at shadow poison. I'm not sure where to start with this spell (combo?) and any help or starting points would be appreciated.

Comments

  • edited July 2015 Posts: 1,670

    OnProjectileHitUnit you'll want to RunScript to keep track of which units have you debuffed, so they are easily iterable when you hit the 2nd spell.

    This "tracking" can be done like this:

    function SpellProjectileHit( event )
        local target = event.target -- The unit hit by the projectile
        local ability = event.ability -- The ability handle
    
        -- Initialize the table 
        if not ability.units_hit then
            ability.units_hit = {}
        end
    
        -- Add the unit to the table
        table.insert(ability.units_hit, target)
    end
    

    Then when you hit your 2nd no target spell, you iterate over the units you have stored, checking if they are valid (are alive + have the debuff)

    function DealDamageToDebuffedUnits( event )
        local caster = event.caster
    
        -- Find with the name of the main ability here
        local main_ability = caster:FindAbilityByName("main_projectile_ability")
    
        -- If we found the ability and a list of units hit, proceed
        if main_ability and main_ability.units_hit then
            -- Recover the table and iterate
            local units_hit = main_ability.units_hit
    
            for _,unit in pairs(units_hit)
                -- Use your modifier debuff name here
                if IsValidEntity(unit) and unit:HasModifier("your_main_modifier_name")
                    -- Deal damage based on stacks
                    local stacks = unit:GetModifierStackCount("your_main_modifier_name", caster)
                    print("Deal damage for "..stacks.." stacks to unit "..unit:GetUnitName())
                end
            end
    
            -- Finally, reset the table
            main_ability.units_hit = {}
        end
    end
    

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

  • Posts: 15

    Thanks again Noya :D