• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Lack of another home.

Status
Not open for further replies.
Level 9
Joined
May 28, 2007
Messages
365
This is just a library I played with, I'm removing it now though so I thought I'd let this be it's burying ground.

It creates an 'explosion' of units to burst from the point. To use simply call

UnitPile.create( <OwningPlayer>, <x Position>, <y Position> )

JASS:
library UnitExplosion initializer Init requires TimerUtils
    
    globals
        private constant string EFFECT_PATH = "Abilities\\Weapons\\ChimaeraAcidMissile\\ChimaeraAcidMissile.mdl"
        private constant integer AMOUNT  = 12
        private constant integer UNIT_ID = 'nmpe'
    endglobals
    
    private function PolarProjectionX takes real x, real dist, real angle returns real
        return x + dist * Cos(angle)
    endfunction

    private function PolarProjectionY takes real y, real dist, real angle returns real
        return y + dist * Sin(angle)
    endfunction
    
    private struct UnitPile 
        unit array units[AMOUNT]
        real size               = 0.35
        real x                  = 0.
        real y                  = 0.
        real v                  = 24.
        
        static method Callback takes nothing returns nothing 
            local timer t = GetExpiredTimer()
            local UnitPile d = GetTimerData(t)
            local integer i = AMOUNT
            local real x
            local real y
            
            set d.size = d.size + 0.03
            set d.v = d.v*0.975
            
            loop
            exitwhen i <= 0 
                set x = PolarProjectionX( GetUnitX(d.units[i]), d.v, GetUnitFacing(d.units[i])*bj_DEGTORAD )
                set y = PolarProjectionY( GetUnitY(d.units[i]), d.v, GetUnitFacing(d.units[i])*bj_DEGTORAD )
                
                call SetUnitX( d.units[i], x )
                call SetUnitY( d.units[i], y )                
                call SetUnitScale( d.units[i], d.size, d.size, d.size )
                
                if( d.size >= 0.6 and d.size < 0.7 ) then
                    call SetUnitFlyHeight( d.units[i], 0, 800 )
                endif
                if( d.size >= 1 ) then
                    call PauseUnit( d.units[i], false )
                    call SetUnitPathing( d.units[i], TRUE )
                    call IssuePointOrder( d.units[i], "attack", d.x, d.y )
                    call d.destroy()
                    call ReleaseTimer(t)
                endif
            set i = i-1
            endloop            
            
            
        endmethod
        
        static method create takes player p, real x, real y returns UnitPile
            local timer t = NewTimer()
            local thistype up = UnitPile.allocate()
            local integer i = AMOUNT
            set up.x = x
            set up.y = y
            
            loop
            exitwhen i <= 0
                set up.units[i] = CreateUnit( p, UNIT_ID, up.x, up.y, (360/AMOUNT)*i )
                call DestroyEffect( AddSpecialEffectTarget(EFFECT_PATH, up.units[i], "origin" ))
                call UnitAddAbility( up.units[i], 'Amrf' )
                call UnitRemoveAbility( up.units[i], 'Amrf' )
                call SetUnitPathing( up.units[i], false )
                call SetUnitX( up.units[i], up.x )
                call SetUnitY( up.units[i], up.y )
                call PauseUnit( up.units[i], true )
                call SetUnitScale( up.units[i], up.size, up.size, up.size )
                call SetUnitFlyHeight( up.units[i], GetRandomReal(800, 1250), 800 )
            set i = i-1
            endloop
            
            call SetTimerData( t, integer(up) )
            call TimerStart( t, 0.03, true, function UnitPile.Callback )
            return up
        endmethod
    endstruct

    private function Action takes nothing returns nothing 
        local unit u = GetTriggerUnit()
        local player p = GetOwningPlayer(u)
        local real x = GetUnitX(u)
        local real y = GetUnitY(u)
        
        call UnitResetCooldown( u )
        call UnitPile.create(p, x, y)       
    endfunction
    
    private function Cond takes nothing returns boolean
        return GetSpellAbilityId() == 'AHwe'
    endfunction
    
    function Init takes nothing returns nothing 
        local trigger t = CreateTrigger()

        call TriggerAddCondition( t, Condition(function Cond) )
        call TriggerAddAction( t, function Action )
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)        
    endfunction

endlibrary
 
Status
Not open for further replies.
Top