Request spell that contain timer

8uY_YoU

New Member
Reaction score
4
I want spell that using timer like Damage over time spell, Dashing spell, Projectile spell, or other

Because i want to learn it and make my own custom spell

I have looked some spell tutorial map that contain this, but i still don't understand because some comment of that spell only explain "how to copy this spell to your map?"

Can you make me one or give me a link to a thread that useful for me?

Also please add comment for every line of the code if you want to making one!
 

Viikuna

No Marlo no game.
Reaction score
265
Ill make you a simple Dash.

edit. You want some image trail stuff for it, or just a simple dash with all basic timer and unit moving stuff?

Here it is. Its pretty quikcly made, but I tried to add some comments.

Ask if you dont understand something.

JASS:
scope Dash initializer init

globals

  private constant integer  SPELL_ABILITY_ID      =      'Dash' 
  private constant real     TIMER_TIMEOUT         =      .025
  
  private constant real     MAX_DASHING_RANGE     =      1500. 
  private constant real     COLLINSION_SIZE       =      75.
  
  private constant real     INITIAL_VELOCITY      =      300.
  private constant real     MAX_VELOCITY          =      1500.
  private constant real     ACCELERATION          =      50.
  
  private constant string   DAMAGE_EFFECT_PATH    =      "Objects\\Spawnmodels\\Orc\\Orcblood\\BattrollBlood.mdl"
  private constant integer  RUN_ANIMATION_INDEX   =      7
  
endglobals

private constant function SPELL_DAMAGE takes integer level returns real
    return level * 25. + 25.
endfunction



// private struct image

    // If you want to create some image  trail stuff, 
    // you can have a own struct for each image and
    // use image array inside that ability struct

// endstruct

private struct ability

     // image array Trail[10]
     
     
     
     // This variable is used to store our dashing unit
     
     unit unit
     
     // These variables hold some reals that are needed for our 
     // mathematical calculations
     
     real x
     real y
     real sin
     real cos
     real velocity
     real acceleration
     real maxvelocity
     real distance
     
     // Real damage tells us how much damage spell does
     // Group damaged is used to store those units who 
     // have already been damaged by spell, 
     // so we dont damage them more than once
    
     real damage
     group damaged
     

     // These are important variables. 
     // They are for making a MUI timer spell.
     
     // We basicly have all the active spell instances
     // in an array called 'array'
     
     // Then we loop trought that array and do actions for all those 
     // dashing units.
     
     // This uses some basic array sorting.
     
     static ability array array
     static timer timer=CreateTimer()
     static integer Count=0
     
     // These are for grouping units who come in our way:
     
     static filterfunc filter
     static group group=CreateGroup()
     static ability temp
     
     
     // This method is used to create make some unti dash
     // it creates a new ability struct instance 
     // and starts activates our systems
    
     
     static method create takes unit dasher, location target returns ability
         // allocate new ability instance:
        
         local ability this=ability.allocate()
         
         // set variables and calculate math stuff:
         
         local real x=GetUnitX(dasher)
         local real y=GetUnitY(dasher)
         local real dx=GetLocationX(target)-x
         local real dy=GetLocationY(target)-y
         local real angle=Atan2(dy,dx)
         call RemoveLocation(target)
         set .x=x
         set .y=y
         set .cos=Cos(angle)
         set .sin=Sin(angle)
         set .distance=SquareRoot(dx*dx+dy*dy)
         if .distance>MAX_DASHING_RANGE then
             set .distance=MAX_DASHING_RANGE
         endif
         set .unit=dasher
         set .damage=SPELL_DAMAGE(GetUnitAbilityLevel(dasher,SPELL_ABILITY_ID))
         set .velocity= INITIAL_VELOCITY * TIMER_TIMEOUT
         set .maxvelocity = MAX_VELOCITY * TIMER_TIMEOUT
         set .acceleration = ACCELERATION * TIMER_TIMEOUT
         
         // we should maybe pause our dasher for dash duration and set
         // its animation to run
         call IssueImmediateOrder(dasher,"stop")
         call SetUnitPathing(dasher,false)
         call PauseUnit(dasher,true)
         call SetUnitTimeScale(dasher,3.)
         call SetUnitAnimationByIndex(dasher,RUN_ANIMATION_INDEX)
         
         // if our damaged group doesnt exist yet we create it:
         // We might have damaged group already, 
         // because struct ids are recycled
         
         if .damaged==null then
            set .damaged=CreateGroup()
         else
            call GroupClear(.damaged)
         endif
         
         // Now we set this struct to an array, 
         // so that our timer can take care of dashing
         
         // if there is no dashes going on, we start timer
         if .Count==0 then
             call TimerStart(.timer,TIMER_TIMEOUT,true,function ability.Periodic)
         endif
         set .array[.Count]=this
         set .Count=.Count+1
         
         // we must return our struct instance,
         // because thats how struct syntax is
         return this
     endmethod
     
     
     private static method Periodic takes nothing returns nothing
          
          // This is our main method
          // It is called by the timer, every TIMEOUT seconds.
          // We use loop to do the actions for all ability instances in array 
          
          local integer i=0
          local ability this
          loop
            exitwhen i>=.Count
            set this=.array<i>
            
            // Here we do some math and move our dashing guy:
            
            set .x=.x+.velocity*.cos
            set .y=.y+.velocity*.sin
            set .distance=.distance-.velocity
            if .velocity&lt;.maxvelocity then
                set .velocity=.velocity+.acceleration
            endif
            
            // some SafeX&amp;Y would be nice, 
            // so unit cant dash away from map and crash the game
            
            call SetUnitX(.unit,.x)
            call SetUnitY(.unit,.y)
            
            // Here we damage all the enemies who get in our way:
            // Check method DamageTarget
            set .temp=this
            call GroupEnumUnitsInRange(.group,.x,.y,COLLINSION_SIZE,.filter)
            
            
            // If there is no distance left between dasher and the target,
            // we will end the spell and sort the array, so that there will be
            // no empty spots in it and we can safely continue our looping
            // ( Or pause the timer if there is no dashers dashing ) 
            if .distance&lt;=0.0 then
            
                // unpause and reset animation
                call PauseUnit(.unit,false)
                call SetUnitTimeScale(.unit,1.)
                call SetUnitAnimation(.unit,&quot;stand&quot;)
                call SetUnitPathing(.unit,true)
                
                // destroy struct and sort array
                call .destroy()
                set .Count=.Count-1
                if .Count&gt;0 then
                    set .array<i>=.array[.Count]
                    set i=i-1
                else
                    call PauseTimer(.timer)
                endif
            endif
            set i=i+1
            
        endloop
     endmethod
     
     private static method DamageTarget takes nothing returns boolean
         
         // When we call GroupEnum with this filter function, it will damage 
         // all those units who match our conditions.
         // We use .temp to pass the correct ability instance to this filter
         
         local unit u=GetFilterUnit()
         if not IsUnitInGroup(u,.temp.damaged) and GetWidgetLife(u)&gt;.405 and IsUnitEnemy(.temp.unit,GetOwningPlayer(u)) then
             call GroupAddUnit(.temp.damaged,u)
             call UnitDamageTarget(.temp.unit,u,.temp.damage,false,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_MAGIC,null)
             call DestroyEffect(AddSpecialEffectTarget(DAMAGE_EFFECT_PATH,u,&quot;chest&quot;))
         endif
         set u=null
         return false
     endmethod
     

     static method onInit takes nothing returns nothing
     
 // onInit is called at map Init, so we use it to create our filter
         
         set .filter=Filter(function ability.DamageTarget)
     endmethod
     
endstruct


private function SpellEffect takes nothing returns boolean
    
    // Here we check if casted spell is our dash spell
    // If it is, we create a new ability instance 
    // and the spell code will start doing its actions
    
    local location l
    if GetSpellAbilityId()==SPELL_ABILITY_ID then
        set l=GetSpellTargetLoc()
        call ability.create(GetTriggerUnit(),l)
        call RemoveLocation(l)
        set l=null
    endif
    return false
endfunction

private function init takes nothing returns nothing
    
    // Here we create a trigger, which will detect spell casting
    // and then call function Spell Effect
    
    local trigger t=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function SpellEffect))
endfunction

endscope</i></i>
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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 The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top