Ball Lightning v2
718
lvl: 27

ID:

255

Author:

axllow

Rarity:

rare

Status:

Approved

Description:

It's a hot potato.

Latest Upload Comment:

myeh
Ball Lightning
Every 3 seconds this item jumps to another tower. If no other tower in  1500 range has an empty slot, this item will fly to stash.
Specials:
+150% attackspeed
Download

Toggle Triggers

Header

goldcost: 0
                globals
        ProjectileType BallLightning
    endglobals
    
    private function BallLightningJump takes Projectile Ball returns nothing
        local Tower tower = Ball.getCaster()
        local Iterate towersInRange
        local Item itm = Ball.userInt
        local Tower targetTower = Ball.userInt2
        local Tower towerInRange
        
        if not itm.pickup(targetTower) then
            set towersInRange = Iterate.overUnitsInRangeOfCaster(tower, TARGET_TYPE_PLAYER_TOWERS, 1500.00)
            loop
                set towerInRange = towersInRange.nextRandom()
                exitwhen towerInRange == 0
                if towerInRange != tower and towerInRange != targetTower and towerInRange.countFreeSlots() > 0 then
                    exitwhen true
                endif
            endloop
            
            if towerInRange != 0 then
                set Ball = Projectile.createBezierInterpolationFromUnitToUnit(BallLightning, tower, 0, 0, targetTower, towerInRange, 1.2, 0.0, 0.5, false)
                set Ball.userInt = itm
                set Ball.userInt2 = towerInRange
                call towersInRange.destroy()
            else
                call SetItemVisible(itm.getItem(), true)
                call itm.flyToStash(0.0)
            endif
        endif
    endfunction
    
    //Do not remove or rename this function!
    //Put your initialization tasks here, this function will be called on map init
    private function init takes nothing returns nothing
         set BallLightning = ProjectileType.createInterpolate("Abilities\\Weapons\\FarseerMissile\\FarseerMissile.mdl", 300)
        call BallLightning.setEventOnCleanup(BallLightningJump)

    endfunction
        

Periodic

PERIODIC_period: 3.0 goldcost: -20800
function periodic takes Item itm returns nothing
            
    local Tower tower = itm.getCarrier()
    local Projectile Ball
    local Iterate towersInRange = Iterate.overUnitsInRangeOfCaster(tower, TARGET_TYPE_PLAYER_TOWERS, 1500.00)
    local Tower towerInRange

    call itm.drop()

    loop
        set towerInRange = towersInRange.nextRandom()
        if towerInRange != tower and towerInRange.countFreeSlots() > 0 then
            call SetItemVisible(itm.getItem(), false)
            set Ball = Projectile.createBezierInterpolationFromUnitToUnit(BallLightning, tower, 0, 0, tower, towerInRange, 1.2, 0.0, 0.5, false)
            set Ball.userInt = itm
            set Ball.userInt2 = towerInRange
            exitwhen true
        endif
        exitwhen towerInRange == 0
    endloop

    if towerInRange != 0 then
        call towersInRange.destroy()
    else
        call itm.flyToStash(0.0)
    endif

        
endfunction