• 🏆 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!

Kamikaze v1.0

Was made for a spell contest.
Lost by one point.

http://www.youtube.com/watch?v=0TP09U4xG0s
Video.

The gyrocopter heads in full throttle torwards the ground where his foes lay.
Crashing the copter causes a big explosion and creating a sonic boom knocking the enemies.


JASS:
scope Kamikaze initializer onInit // requires TimerUtils, BoundSentinel

    //===================================================\\
    //                  CONFIGURABLES                    \\
    //            You may edit the variables below       \\
    //===================================================\\
    
    globals
        private constant integer SPELL_ID              = 'A000' // The raw code of the ability
        private constant real    TIMER_PERIOD          = 0.03 // How fast the update timer is ran
        private constant real    CRASH_SPEED           = 15 // How much the unit moves per TIMER_PERIOD
        private constant real    SPEED_INC             = .5 // How much the unit speeds up per TIMER_PERIOD + CRASH_SPEED
        private constant real    REQUIRED_DIST         = 300 // How far away the caster has to be to the target
        private constant string  EXPLOSION             = "Objects\\Spawnmodels\\Other\\NeutralBuildingExplosion\\NeutralBuildingExplosion.mdl" // the boom effect.
        private constant string  DUST_FX               = "Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl" // the dust that shows upon crash.
        private constant string  TRAIL_FX              = "" // the effect on the copter (I chose none)
        
        private constant real    KB_SPEED              = 10 // knockback speed.
        private constant real    KB_DEC                = .2 // knockback speed slowdown factor. Making it too low will look wierd.
        private constant real    ARC                   = 0.4 // Crash arc
        
        private constant weapontype WEAPON_TYPE        = WEAPON_TYPE_WHOKNOWS
        private constant damagetype DAMAGE_TYPE        = DAMAGE_TYPE_FIRE
        private constant attacktype ATTACK_TYPE        = ATTACK_TYPE_PIERCE
    endglobals
    
    private constant function SPELL_DAMAGE takes integer level returns real
        return 150.0*level
    endfunction
    
    private constant function SPELL_RANGE takes integer level returns real
        return 600.0 // I like the range to be the same.
    endfunction
    
    private constant function Parabola takes real d, real h, real x returns real // moyack/Spec
        return ( 4 * h / d ) * ( d - x ) * ( x / d )
    endfunction

    //===================================================\\
    //               DO NOT EDIT BELOW THIS LINE         \\
    //                                                   \\
    //===================================================\\
    native UnitAlive takes unit id returns boolean
    private keyword kb
    private keyword data
    globals
        private kb array kbArray
    endglobals
    private struct kb
        static integer count = 0
        static timer timer = CreateTimer()
        static player p
        static data d
        
        unit u
        real face
        real x
        real y
        real sin
        real cos
        real speed = KB_SPEED
        static method enum takes nothing returns boolean
            local unit u = GetFilterUnit()
            if (UnitAlive(u) and IsUnitEnemy(u, kb.p)) then
                call UnitDamageTarget(kb.d.copter, u, kb.d.dmg, true, false, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE)
                if (UnitAlive(u)) then
                    call kb.create(u, kb.d.x, kb.d.y)
                endif
            endif
            set u=null
            return false
        endmethod
        
        static method callback takes nothing returns nothing
            local integer i = 1
            local kb this
            local real x
            local real y
            
            loop
                exitwhen i > kb.count
                set this = kbArray[i]
                set x = this.x - this.speed * this.cos
                set y = this.y - this.speed * this.sin
                set this.x = x
                set this.y = y
                set this.speed = this.speed-KB_DEC
                if (this.speed <= 0) then
                    set kb.count = kb.count-1
                    set kbArray[i] = kbArray[kb.count]
                    call this.destroy()
                    if kb.count == 0 then
                        call PauseTimer(kb.timer)
                    endif
                endif
                call SetUnitX(this.u, x)
                call SetUnitY(this.u, y)
                set i = i + 1
            endloop
        endmethod
        
        static method create takes unit u, real centerX, real centerY returns kb
            local kb this = kb.allocate()
            set this.x = GetUnitX(u)
            set this.y = GetUnitY(u)
            set this.u = u
            set this.face = bj_RADTODEG*Atan2(this.y-centerX,this.x-centerY)
            set this.sin = Sin(face*bj_DEGTORAD)
            set this.cos = Cos(face*bj_DEGTORAD)

            set kb.count = kb.count + 1
            set kbArray[kb.count] = this

            if (kb.count == 1) then
                call TimerStart(kb.timer, TIMER_PERIOD, true, function kb.callback)
            endif
            return this
        endmethod
        
    endstruct
    
    private struct data
        unit copter
        real facing
        real x
        real y
        real sin
        real cos
        real cx
        real cy
        real dmg
        real height
        real range
        real speed = CRASH_SPEED
        real dist
        real d2
        boolean b = false
        boolean b2 = true
        static group GLOBAL = CreateGroup()
        static method callback takes nothing returns nothing
            local data d = GetTimerData(GetExpiredTimer())
            local real x = d.cx + d.speed * d.cos
            local real y = d.cy + d.speed * d.sin
            local integer i = 0
            local real x2
            local real y2
            
            // Increase speed and set new position
            set d.speed = d.speed + SPEED_INC
            set d.cx = x
            set d.cy = y
            call SetUnitX(d.copter, x)
            call SetUnitY(d.copter, y)
            
            // Create FX/Height
            call DestroyEffect(AddSpecialEffectTarget(TRAIL_FX, d.copter, "chest"))
            set d.dist = d.dist-d.speed
            call SetUnitFlyHeight(d.copter, Parabola(d.d2+d.height, d.d2 * ARC, d.dist), 0)
            
            if (d.b2) then // Checks it once instead of every timer interval
                set d.b = IsUnitInRangeXY(d.copter, d.x, d.y, 100)
            endif
            
            // Start crashing stuff
            if (d.b and d.b2) then
                call KillUnit(d.copter)
                
                set kb.p = GetOwningPlayer(d.copter)
                call d.destroy()
                call ReleaseTimer(GetExpiredTimer())
                call DestroyEffect(AddSpecialEffect(EXPLOSION, x, y))
                
                // Dust Circle
                loop
                    exitwhen i >= 360
                    set x2 = x + 200 * Cos(i * bj_DEGTORAD)
                    set y2 = y + 200 * Sin(i * bj_DEGTORAD)
                    call DestroyEffect(AddSpecialEffect(DUST_FX, x2, y2))
                    set i = i + 90
                endloop
                set kb.d  = d
                
                call GroupEnumUnitsInRange(data.GLOBAL, x, y, d.range, Filter(function kb.enum)) // Knockback/Dmg units
                call GroupClear(data.GLOBAL) // Stops possible bugs from occuring.
                set d.b2 = false
            endif
            
        endmethod
        
        static method create takes nothing returns data
            local data d  = data.allocate()
            local real dx
            local real dy
            local integer level
            
            set d.copter  = GetTriggerUnit()
            set level     = GetUnitAbilityLevel(d.copter, SPELL_ID)
            set d.cx      = GetUnitX(d.copter)
            set d.cy      = GetUnitY(d.copter)
            set d.x       = GetSpellTargetX()
            set d.y       = GetSpellTargetY()
            set d.facing  = bj_RADTODEG * Atan2(d.y - d.cy, d.x - d.cx)
            set d.sin     = Sin(d.facing * bj_DEGTORAD)
            set d.cos     = Cos(d.facing * bj_DEGTORAD)
            set d.dmg     = SPELL_DAMAGE(level)
            set dx        = d.x - d.cx
            set dy        = d.y - d.cy
            set d.dist    = SquareRoot(dx * dx + dy * dy)
            set d.d2      = d.dist
            set d.height  = GetUnitFlyHeight(d.copter)
            set d.range   = SPELL_RANGE(level)
            set d.dmg     = SPELL_DAMAGE(level)
            
            call UnitAddAbility(d.copter, 'Amrf')
            call UnitRemoveAbility(d.copter, 'Amrf')
            
            return d
        endmethod
    endstruct
    
    private function Actions takes nothing returns boolean
        local timer t
        if (GetSpellAbilityId() == SPELL_ID) then
            set t = NewTimer()
            call SetTimerData(t, data.create())
            call TimerStart(t, TIMER_PERIOD, true, function data.callback)
        endif
        return false
    endfunction
    
    private function onInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(t, Condition(function Actions))
    endfunction

endscope


Keywords:
knock, back, knockback, plane, copter, helicopter, gyrocopter, kamikaze
Contents

Just another Warcraft III map (Map)

Reviews
17:53, 19th Jan 2010 The_Reborn_Devil: Approved cuz it's awesome and there's nothing wrong. The effects looks good too :D Highly Recommended and Approvz0rd!! Maek moar plz

Moderator

M

Moderator

17:53, 19th Jan 2010
The_Reborn_Devil:

Approved cuz it's awesome and there's nothing wrong.
The effects looks good too :D

Highly Recommended and Approvz0rd!!

Maek moar plz
 
Level 2
Joined
Oct 5, 2009
Messages
30
cool spell triggerhappy, i definately want to use this, cred ofcourse, slight problem i see though , is there anyway to stop the knockback distance from pushing units into the centre of buildings and getting them stuck.. i dont know how to put a structure knockback check, can someone do this please :p
 
Top