Spell Magic Missile

gref

New Member
Reaction score
33
Magic Missile

MUI: Yes.
Leakless: Yes.
Lagless: Yes.
JESP: Yes.
Jass/GUI: Jass

Screenshot:
MagicMissileScreen.jpg


Description:
This is a spell in the spirit of the Baldur's Gate spell Magic Missile. This spell creates one missile per level of the ability, which darts forth from the wizard's finger-tip to unerringly strikes its target, dealing X damage per missile.
This will go up to at least 100 missiles. I tested that, but thought going any further was ridiculous.

Made in Jass
JASS:
//===============================>
// Magic Missile by gref.
//===============================>

scope MagicMissile
    // Follows JESP
    
    //===========================>
    //Constants
    //===========================>
    globals
        private constant integer AbilCode = 'A000' //Name of triggering ability
        private constant integer UnitCode = 'h000' //Name of unit used for missile
        private constant real width_factor = .002 // width of flight factor
        private constant real distance_per_tick = 30.0 // speed
        private constant real damage_amount = 100.0 //Amount of damage per missile  
        // The effect used when the missile hits the target.         
        private constant string missile_effect = "Abilities\\Spells\\Undead\\DeathCoil\\DeathCoilSpecialArt.mdl" 
    endglobals          
    //===========================>
    //Data Types
    //===========================>
    struct MissileStruct
        unit missile
        real factor
        real covered
        real distance
        real angle
        real speed
        unit target
        
        real x
        real y
        
        method onDestroy takes nothing returns nothing   
            call UnitDamageTarget(.missile, .target, damage_amount, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS)
            call DestroyEffect(AddSpecialEffect(missile_effect, GetUnitX(.missile), GetUnitY(.missile)))
            
            call CleanAttachedVars(.missile)
            call RemoveUnit(.missile)
            
            set .missile = null
            set .target = null
        endmethod
        
        static method create takes unit missile, real distance, real angle, unit target returns MissileStruct
            local MissileStruct m = MissileStruct.allocate()
            
            set m.distance = distance
            set m.missile = missile
            set m.covered = 0
            set m.x = GetUnitX(missile) 
            set m.y = GetUnitY(missile)
            set m.angle = angle
            set m.target = target
            set m.speed = 1
            
            return m
        endmethod
        
        method advance takes nothing returns boolean
            local real x 
            local real y 
            local real offset
            local real angle
            
            
            if(.covered < .distance/2) then 
                set .covered = .covered + distance_per_tick*.speed           
                set offset = -1*.factor*(.covered*.covered-.distance*.covered)            
                                                                        
                set x = .x + .covered*Cos(.angle*bj_DEGTORAD)
                set y = .y + .covered*Sin(.angle*bj_DEGTORAD) 
            
                set x = x + offset*Cos((.angle+90)*bj_DEGTORAD)
                set y = y + offset*Sin((.angle+90)*bj_DEGTORAD)
            
                call SetUnitPosition(.missile, x, y)   
            else
                set angle = bj_RADTODEG * Atan2(GetUnitY(.target) - GetUnitY(.missile), GetUnitX(.target) - GetUnitX(.missile))
                set x = GetUnitX(.missile)+distance_per_tick*.speed*Cos(angle*bj_DEGTORAD)
                set y = GetUnitY(.missile)+distance_per_tick*.speed*Sin(angle*bj_DEGTORAD)
                call SetUnitPosition(.missile, x, y)
            endif    
            set .speed = .speed*1.025   
            
            set y = (GetUnitY(.missile)-GetUnitY(.target))
            set x = (GetUnitX(.missile)-GetUnitX(.target))
                        
            if(SquareRoot(x*x+y*y) < 50.0) then
                return true
            endif    
            
            return false    
        endmethod
            
    endstruct
    
    struct SpellStruct
        group g
        
        method onDestroy takes nothing returns nothing
            call DestroyGroup(.g)             
            set .g = null
        endmethod
        
        static method create takes player owner, unit target, real distance, real x, real y, integer number, real angle returns SpellStruct
            local SpellStruct s = SpellStruct.allocate()
            local unit u
            local real factor
            local MissileStruct m 
            local integer i = 1
            
            set s.g = CreateGroup()
            
                    //Create the right number of missiles.
            loop
                exitwhen i > number 
                set u = CreateUnit(owner, UnitCode, x, y, 0 )
                call GroupAddUnit(s.g, u)
                set m = MissileStruct.create(u, distance, angle, target)
                
                if(((number/2)*2) != number) then //Number is odd
                    if(i == (number/2+1)) then //Center missile
                        set m.factor = 0
                    else
                        set m.factor = (((number/2+1)-i)*width_factor)/((distance/500) ) 
                    endif
                else 
                    if(i <= (number/2)) then
                        set m.factor = (((number/2+1)-i)*width_factor)/((distance/500) )  
                    else                        
                        set m.factor = (((number/2)-i)*width_factor)/((distance/500) ) 
                    endif                     
                endif
                
                //Large number error checking.
                if(number>10) then
                    set m.factor = m.factor*.3 
                endif
                
                call AttachInt(u, "MissileStruct", m)
            
                set i = i + 1
            endloop
        
            set u = null
            return s
        endmethod        
    endstruct 
    //===========================>
    //Private Functions
    //===========================>
    
    function TimerTick takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local SpellStruct s = GetAttachedInt(t, "SpellStruct")
        local MissileStruct m
        local unit u     
        local group g = CreateGroup()   
        
        loop
            set u = FirstOfGroup(s.g)
            exitwhen u == null
            
            set m = GetAttachedInt(u, "MissileStruct")  
            
            if(m.advance()) then
                call MissileStruct.destroy(m)
            else      
                call GroupAddUnit(g, u)
            endif
            
            call GroupRemoveUnit(s.g, u)
        endloop        
        
        if (FirstOfGroup(g) == null) then //all missiles hit.
            call SpellStruct.destroy(s)
            call CleanAttachedVars(t)
            call DestroyTimer(t)    
        else 
            call DestroyGroup(s.g)       
            set s.g = g
        endif
        
        set u = null
        set g = null
        set t = null
    endfunction


    

    //===========================>
    //Trigger Functions
    //===========================>
    function Trig_MagicMissile_Conditions takes nothing returns boolean
        return GetSpellAbilityId() == AbilCode
    endfunction

    function Trig_MagicMissile_Actions takes nothing returns nothing 
        local timer t = CreateTimer()                   
        
        local real face = GetUnitFacing(GetTriggerUnit())           
        local real x = GetUnitX(GetTriggerUnit()) + 100*Cos(face*bj_DEGTORAD)
        local real y = GetUnitY(GetTriggerUnit()) + 100*Sin(face*bj_DEGTORAD)
                                                                                        
        local real x1 = GetUnitX(GetSpellTargetUnit())
        local real y1 = GetUnitY(GetSpellTargetUnit())
        local real distance = SquareRoot((x1-x)*(x1-x)+(y1-y)*(y1-y))        
        
        local SpellStruct s = SpellStruct.create(GetOwningPlayer(GetTriggerUnit()), GetSpellTargetUnit(), distance, x, y, GetUnitAbilityLevel(GetTriggerUnit(), AbilCode), face)
        
        call AttachInt(t, "SpellStruct", s)
        call TimerStart(t, 0.05, true, function TimerTick)
        
        set t = null
    endfunction
endscope

//===========================================================================
function InitTrig_MagicMissile takes nothing returns nothing
    set gg_trg_MagicMissile = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_MagicMissile, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_MagicMissile, Condition(function Trig_MagicMissile_Conditions))
    call TriggerAddAction( gg_trg_MagicMissile, function Trig_MagicMissile_Actions )
endfunction
How to Implement:
Spell Requirements:
1. A vJass preprocessor (If you don't have one you can download one from wc3campaigns.net)

How to implement this in your map:
1. Copy the CSCache and MagicMissile triggers to your map. (If you have CSCache, don't worry about it)
2. Copy the unit called Missile in the object editor.
3. Copy the ability called Magic Missile in the object editor.
 

Attachments

  • MagicMissile.w3x
    160.2 KB · Views: 434

Hatebreeder

So many apples
Reaction score
381
Ok, so I have tested you Spell =)
Looks great IMO, but there are a couple things that I disliked.
The Missles have shadows, please remove those =)
Don't Pause the Caster... It's annoying...
Other than that, looks great ;)
May I suggest something?
Put
JASS:
Call Preload("....")
in the last function of your Trigger, I had a short lag at first cast ^^
 

gref

New Member
Reaction score
33
Haha... I was actually debating with myself whether I should preload it or not :)

In the end I thought maybe the map creator would do it. I'll put it now. The caster isn't paused also... I don't know what the problem you had was.
And I'll look at the shadow situation.

(It looks alot cooler when there are 50 of them btw :) )

Edit: Updated, with no shadows, preloaded.
 

Sim

Forum Administrator
Staff member
Reaction score
534
It does pause the target for a short period of time, although I didn't locate any "PauseUnit" in your spell code...

The tooltip definitely needs improvement. :)

Nice work, keep it up!
 

gref

New Member
Reaction score
33
There is no pause... of the caster or the target.
Cast it at a monster that is running either towards you or away, as far as I've seen they don't pause. There's no need for a pause in the spell either, because it accounts for the fact that the target is moving in the code, by homing in after its got to the width of the parabola.
Tooltip should now be up to you exacting standards.:eek:
 

C0mput3r

New Member
Reaction score
20
In Baldurs Gate, wasn't it blue? Annnyways great spell if I ever get the urge to convert Dark Allience into WarCraft:D
 

gref

New Member
Reaction score
33
It was but there are only so many good looking missilies for it --.
I did remove the shadows in the map, I just didn't update the screenshot.
 

Tukki

is Skeleton Pirate.
Reaction score
29
A tad late but who cares..

The 'pause' appears because you use 'Channel' as your base ability and channel has a data field called 'Disable Other Abilties' which currently is marked as true. To remove the 'pause' effect uncheck that data field.
 

Zwiebelchen

You can change this now in User CP.
Reaction score
60
Hm, dunno if Grex is still active here: It would be nice if you could correct the missle dummy's facing. At the moment they just maintain the facing of the caster when the spell is cast, but dont change their facing during the flight.
This results in an odd looking graphic when using non-circular special effects.

The destroyer missle effect would look best with the magic missles, however, without fixing the facing, it just looks strange.
 

Zwiebelchen

You can change this now in User CP.
Reaction score
60
Well good spell but it can be made in GUI MUI with the same efficiency ;)
gui NEVER has the same efficiency as Jass, even when you are not leaking anything (which is unlikely on a complex spell as this).

Why would you ever want to make a spell GUI when u can have it JASS?


@ Spell:

You leak group g on the last run of the Timer function.
 

Romek

Super Moderator
Reaction score
963
Thanks, GY'd.

I'd like to note that these spells can, and will be approved again once fixed. :)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top