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: 435

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
964
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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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