• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

Missile Manual Creators

Level 19
Joined
Mar 18, 2012
Messages
1,716

Missile Manual - v.1.4.2

Creators, destructors and module MissileStruct


[self=http://www.hiveworkshop.com/forums/jass-resources-412/missile-265370/]Back to the Missile main thread[/self]

A new Missile instance can be allocated by one the following struct allocators.

Creators & destroy
JASS:
static method create    takes real x, real y, real z, real angle, real distance, real impactZ returns Missile
static method createXYZ takes real x, real y, real z, real impactX, real impactY, real impactZ returns Missile
static method createEx  takes unit dummy, real angle, real distance, real impactZ returns Missile

method destroy takes nothing returns nothing


Missile.create()

Missile.create(x, y, z, angle, distance, impactZ) is the core creator of Missile and used in most cases.
Let's check out an example and you understand it at a glance.
JASS:
    private function OnCast takes nothing returns nothing
        local unit caster = GetTriggerUnit()
        local real x = GetUnitX(caster)
        local real y = GetUnitY(caster)
        local real angle = Atan2(GetSpellTargetY() - y, GetSpellTargetX() - x)
        local Missile missile = Missile.create(x, y, 50., angle, 1000., 50.)
        //
        set missile.speed = 10
        set missile.model = ""
        set missile.collision = 32.
        call MySpell.launch(missile)
    endfunction
Missile.createXYZ()

Missile.createXYZ(x, y, z, impactX, impactY, impactZ) is a wrapper function to Missile.create,
which can be handy in cases where you want to calculate neither angle nor distance of the missile.
Instead you hand to work over to library Missile.
Let's check out an example.
JASS:
    private function OnCast takes nothing returns nothing
        local unit caster = GetTriggerUnit()
        local real x = GetUnitX(caster)
        local real y = GetUnitY(caster)
        local Missile missile = Missile.createXYZ(x, y, 50., GetSpellTargetX(), GetSpellTargetY(), 50.)
        //
        set missile.speed = 10
        set missile.model = ""
        set missile.collision = 32.
        call MySpell.launch(missile)
    endfunction
Missile.createEx()

Missile.createEx(dummy, angle, distance, impactZ) is a very interesting function with much potential.
It allows you to pass in a unit of your choice and transform it into a Missile. For example a hero.
That unit will perform the same physiks like an ordinary missile dummy.
Missile will not recycle that unit when it finished its flight.

I made use of that in my leap spell for the blademaster ( link ).

Let's check an example
JASS:
    private function OnCast takes nothing returns nothing
        local Missile missile = Missile.createEx(GetTriggerUnit(), GetSpellTargetX(), GetSpellTargetY(), 50.)
        //
        set missile.speed = 10
        set missile.model = ""
        set missile.arc = 45*bj_DEGTORAD
        set missile.collision = 32.
        call Leap.launch(missile)
    endfunction
module MissileStruct

In order to make use of Missile you must declare a new struct and implement module MissileStruct into it.
Then you can declare any of the available static methods for missile behaviours, such as static method onCollide.

Missiles fired from this struct will only behave as defined in that struct.

Let's check an example.
JASS:
    private struct Fireball extends array
    
        private static method onCollide takes Missile missile, unit hit returns boolean
            if IsUnitEnemy(hit, missile.owner) and UnitAlive(hit) then
                return UnitDamageTarget(missile.source, hit, missile.damage, false, false, null, null, null)
            endif
            return false
        endmethod
        
        // Enables missile behaviour for struct Fireball.
        // Now onCollide will run, if a missile launched from this struct
        // collides with a unit.
        implement MissileStruct 
    
    endstruct
    
    private function OnCast takes nothing returns nothing
        local unit caster = GetTriggerUnit()
        local real x = GetUnitX(caster)
        local real y = GetUnitY(caster)
        local Missile missile = Missile.createXYZ(x, y, 50., GetSpellTargetX(), GetSpellTargetY(), 50.)
        //
        set missile.source = caster
        set missile.owner = GetTriggerPlayer()
        set missile.speed = 20
        set missile.model = "Abilities\\Weapons\\FireBallMissile\\FireBallMissile.mdl"
        set missile.collision = 32.
        call Fireball.launch(missile)// Launches for struct Fireball.
    endfunction
Last edited:
Top