How to make a rect/region non-rectangual ? (Cross-line spell)

Komaqtion

You can change this now in User CP.
Reaction score
469
Hi !

I was just making a spell request by Avaleirra (Official thread here and though there has already been submissions, I'll make it anyway XD) and I thought I could use a rect as the "line" between the units, meaning that it would always stay the same size, just turn and move...

But I noticed that the [ljass]MoveRectTo[/ljass] native takes newCenterX and newCenterY which means that it can't "turn" in the way I wanted :(

And then I ran into more trouble with it, as I noticed when I tested the spell (Which might not be done yet, but I'd believe it should work up to that point at least...)

I now know that rects are always rectangular (Which I kinda new before, but was just hoping I was wrong XD)

But the spell I'm making needs to register when units pass through a "line", and this was the only way I could think of :(

Any ideas ofmaking this spell work as intended ? :S

JASS:
scope SpiritLink initializer Init// requires T32

    globals
        private constant integer SPELL_ID = 'SPIR'
        
        private constant real DURATION = 20.0
        
        private constant attacktype ATTACK_TYPE = ATTACK_TYPE_NORMAL
        private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_UNKNOWN
        private constant weapontype WEAPON_TYPE = WEAPON_TYPE_WHOKNOWS
    endglobals
    
    private constant function Damage takes integer spellvl returns real
        return spellvl * 50.0
    endfunction
    
    private constant function Heal takes integer spellvl returns real
        return spellvl * 50.0
    endfunction
    
    globals
        private location Z = Location( 0.0, 0.0 )
        private group new = CreateGroup()
        private unit c = null
        private player owner = null
        private integer lvl = 0
    endglobals
    
    native UnitAlive takes unit id returns boolean
    
    private struct Link extends array
        //! runtextmacro AIDS()
    
        lightning light
        unit cast
        unit targ
        rect r
        integer tick
        group check
        
        
        private method AIDS_onCreate takes nothing returns nothing
            set this.tick = R2I( DURATION / T32_PERIOD )
            set this.check = CreateGroup()
        endmethod
        
        private static method Filters takes nothing returns boolean            
            return UnitAlive( GetFilterUnit() ) == true
        endmethod
        
        private static method CheckGroups takes nothing returns nothing
            local unit u = GetEnumUnit()
            
            if IsUnitInGroup( u, new ) != true then
                
                if IsUnitEnemy( u, owner ) then
                    call UnitDamageTarget( c, u, Damage( lvl ), true, false, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE )
                    call DisplayTextToPlayer( Player( 0 ), 0.0, 0.0, "Damage dealt: " + R2S( Damage( lvl ) ) )
                else
                    call SetWidgetLife( u, GetWidgetLife( u ) + Heal( lvl ) )
                    call DisplayTextToPlayer( Player( 0 ), 0.0, 0.0, "Damage healed: " + R2S( Heal( lvl ) ) )
                endif
                
            else
                call GroupRemoveUnit( new, u )
                call DisplayTextToPlayer( Player( 0 ), 0.0, 0.0, "The unit hasn't moved..." )
            endif
            
        endmethod
        
        private method periodic takes nothing returns nothing
            local real x1 = GetUnitX( this.cast )
            local real x2 = GetUnitX( this.targ )
            local real y1 = GetUnitY( this.cast )
            local real y2 = GetUnitY( this.targ )
            local real z1
            local real z2
            
            set this.tick = this.tick - 1
            
            call DisplayTextToPlayer( Player( 0 ), 0.0, 0.0, "Tick !" )
            
            if this.tick >= 0 then
            
                // ========================================================== \\
                
                call MoveLocation( Z, x1, y1 )
        
                set z1 = GetLocationZ( Z ) + GetUnitFlyHeight( cast )
                
                // This is to get the height of both the caster and target <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" /> \\
                
                call MoveLocation( Z, x2, y2 )
        
                set z2 = GetLocationZ( Z ) + GetUnitFlyHeight( targ )
                
                // ========================================================== \\
            
                call MoveLightningEx( this.light, true, x1, y1, z1, x2, y2, z2 )
                call RemoveRect( this.r )
            
                set this.r = Rect( x1, y1, x2, y2 )
                
                set owner = GetOwningPlayer( this.cast )
                set cast = this.cast
                set lvl = GetUnitAbilityLevel( this.cast, SPELL_ID )
                
                call GroupEnumUnitsInRect( new, this.r, Filter( function thistype.Filters ) )
                call ForGroup( this.check, function thistype.CheckGroups )
            else
                call DestroyLightning( this.light )
                call RemoveRect( this.r )
                call this.stopPeriodic()
            endif
        endmethod
        
        implement T32xs
        
        method StartPeriod takes unit caster, unit target, lightning light, rect r returns nothing
            set this.cast = caster
            set this.targ = target
            set this.light = light
            set this.r = r
            set owner = GetOwningPlayer( caster )
            
            call GroupEnumUnitsInRect( this.check, this.r, Filter( function thistype.Filters ) )
            
            call this.startPeriodic()
        endmethod
    
    endstruct

    private function Actions takes nothing returns boolean
        local unit u = GetTriggerUnit()
        local unit t = GetSpellTargetUnit()
        local player p = GetOwningPlayer( u )
        local real x1 = GetUnitX( u )
        local real x2 = GetUnitX( t )
        local real y1 = GetUnitY( u )
        local real y2 = GetUnitY( t )
        local real z1
        local real z2
        
        if GetSpellAbilityId() == SPELL_ID then
            call MoveLocation( Z, x1, y1 )
        
            set z1 = GetLocationZ( Z ) + GetUnitFlyHeight( u )
        
            call MoveLocation( Z, x2, y2 )
        
            set z2 = GetLocationZ( Z ) + GetUnitFlyHeight( t )
            
            call Link[ u ].StartPeriod( u, t, AddLightningEx( &quot;SPLK&quot;, false, x1, y1, z1, x2, y2, z2 ), Rect( x1, y1, x2, y2 ) )
        endif
        
        return false
    endfunction

    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger() // Here we&#039;re creating the trigger <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
        local integer i = 0               // This will be used for looping through the players
        
        loop
            call TriggerRegisterPlayerUnitEvent( t, Player( i ), EVENT_PLAYER_UNIT_SPELL_EFFECT, null ) // And here the looping goes.
                                                                                                 // And also, registering the events to the previusly created trigger
            set i = i + 1
            exitwhen i &gt;= 12
        endloop
        
        call TriggerAddCondition( t, Condition( function Actions ) ) // And here we&#039;re adding the condition/action to the trigger
    endfunction
    
endscope
 

_whelp

New Member
Reaction score
54
I don't think a rect is a good way to do this... maybe use a group to check if anyone is between both of the units...
 

Sickle

New Member
Reaction score
13
It would be a much better idea to simply trace along the line and enumerate units along points in the line at certain intervals. Rects are a terrible to use for a spell such as this..
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Well, would that really work if you'd have a quite fast unit ? :S
I don't think so, since it might get through the line between the periods...
 

Sooda

Diversity enchants
Reaction score
318
Only reasonable way to code it is like Sickle and _whelp suggested. Global declaration (vJASS) was invented to handle such problems. Use GetNewGroup/ ReleaseGroup system. At each new spell instance acquire unit group, release it in the end of spell.
Unit group acquiring range (radius*2 aka diameter) divided with missile speed and you get interval after what you have to acquire new targets. Repeat this process until spell distance is achieved. Use timer (again use some Get/ReleaseTimer) to wait intervals.

You can use radius instead diameter, it makes sure all units get hit by line damage. You need second group for already damaged units because with radius both radius checks overlap.

Are you new to JASS?

EDIT:

There is way to make it with coordinates comparison, but I don't remember it from my school days.

> Make the period 0.03125!~

There is a point, but most units travel at 522 or less. Radius of 256 / missile speed of 522 means timer timeout below 1 second, which is quite fast.
 

Viikuna

No Marlo no game.
Reaction score
265
Vexorians Disintegrate spell is a good example, if you wanna know how to group units in some line.

Its basicly just some math you gotta do to find out if units are in the line.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, but where in that code is that maths ? :S XD

Somewhere in this struct maybe ? :eek:

JASS:
   private struct instance
      unit u
      integer level
      real x2
      real y2
      lightning li
      boolean   end = false
      real      acum = 0.0
      real      elapsed=0.0
      xefx    fx
      static instance current

      static method unitInRectEnum takes nothing returns boolean
       local instance this=.current
       local unit     u=this.u
       local unit     t=GetFilterUnit()
       local real    x1=GetUnitX(u)
       local real    y1=GetUnitY(u)
       local real    x2=this.x2
       local real    y2=this.y2
       local real     a=x2-x1
       local real     b=y2-y1
       local real     cx
       local real     cy
       local real     s=(a*( GetUnitX(t) -x1)+b*( GetUnitY(t)-y1))/(a*a+b*b)
       local real    fc

          if(s&lt;0) then
              set s=0.0
          elseif(s&gt;1) then
              set s=1.0
          endif
          set cx=x1+s*a
          set cy=y1+s*b
          if IsUnitInRangeXY(t, cx, cy, radius(this.level) ) then
              if damageconf[this.level].damageTarget(u,t, damagePerSecond(this.level)*TIMER_PERIOD ) then
                  if(PSEUDO_EXPLODE and  (GetWidgetLife(t)&lt;=0.405) ) then
                      //call ShowUnit(t,false)
                      call DestroyEffect( AddSpellEffectTargetById(GetUnitTypeId(t), EFFECT_TYPE_SPECIAL, t, &quot;origin&quot; ) )
                  endif
                  if(this.acum == 0.0) then
                      call DestroyEffect( AddSpellEffectTargetById(SPELL_ID,EFFECT_TYPE_TARGET, t, &quot;origin&quot; ) )
                  endif
              endif
          endif
         set u=null
         set t=null
       return false
      endmethod

      method process takes nothing returns boolean
       local real a
       local real x1
       local real y1
       local real x2
       local real y2

         if(.end) then
             return false
         endif
         set a=GetUnitState(this.u, UNIT_STATE_MANA)
         if (a &lt; requiredMana(this.level) ) and (this.elapsed&gt;=BEGINNING_DURATION) then
             call PauseUnit(this.u, true)
             call IssueImmediateOrder(this.u, &quot;stop&quot;)
             call PauseUnit(this.u, false)
         endif
         call SetUnitState(this.u, UNIT_STATE_MANA, a- this.level * manaDrainPerSecond(this.level)* TIMER_PERIOD )


         set x1=GetUnitX(this.u)
         set y1=GetUnitY(this.u)
         set x2=this.x2
         set y2=this.y2
         set a=Atan2(y2-y1,x2-x1)
         set x1=x1+LASER_START_OFFSET*Cos(a)
         set y1=y1+LASER_START_OFFSET*Sin(a)

         set a=XE_MAX_COLLISION_SIZE + radius(this.level)
         call MoveLightningEx(this.li, false, x1,y1,GetZ(x1,y1)+LASER_HEIGHT, x2,y2,GetZ(x2,y2)+LASER_HEIGHT)

         //set the rect: (painful stuff, yes)
         if(x1 &lt; x2) then
             if( y1 &lt; y2) then
                 call SetRect(enumrect, x1-a,y1-a,x2+a,y2+a)
             else
                 call SetRect(enumrect, x1-a,y2-a,x2+a,y1+a)
             endif
         else
             if( y1 &lt; y2) then
                 call SetRect(enumrect, x2-a,y1-a,x1+a,y2+a)
             else
                 call SetRect(enumrect, x2-a,y2-a,x1+a,y1+a)
             endif
         endif

         set .current = this
         call GroupEnumUnitsInRect(enumgroup, enumrect, Condition(function instance.unitInRectEnum) )
         set .acum=.acum+TIMER_PERIOD
         set .elapsed=.elapsed + TIMER_PERIOD
         if(.acum&gt;= TARGET_FX_PERIOD) then
             set .acum=0.0
         endif

         return true
      endmethod

      method onDestroy takes nothing returns nothing
          call DestroyLightning(this.li)
          call unitsInstance.flush(this.u)
          call this.fx.destroy()
      endmethod
   endstruct
 

Viikuna

No Marlo no game.
Reaction score
265
I kinda thought you can read Jas well enough to do that.


Well, it basicly:

-creates a rect. ( Look for SetRect - function calls )
-groups units in that rect. ( Look for GroupEnum -function call )
-filters away some not on the line units, and damages the rest ( You regonize that filter function already, I hope )
 

Komaqtion

You can change this now in User CP.
Reaction score
469
I'll try that one ! :D
Thanks ;)

EDIT: Ok, so I implemented LineSegment here now, and I've tried to clean up the code a bit but now it seems to only heal the caster ?! :(

At least there are only special effect being created at him XD

JASS:
scope SpiritLink initializer Init// requires T32, LineSegment

    globals
        private constant integer SPELL_ID = &#039;SPIR&#039;
        
        private constant real DURATION = 20.0
        
        private constant real DISTANCE = 1.0                           // How close they have to be to the lightning effect to be considered crossing it...
        
        private constant attacktype ATTACK_TYPE = ATTACK_TYPE_NORMAL
        private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_UNKNOWN
        private constant weapontype WEAPON_TYPE = WEAPON_TYPE_WHOKNOWS
        
        private constant string LIGHTNING_TYPE = &quot;SPLK&quot;
        private constant string EFFECT_DMG = &quot;Abilities\\Spells\\Demon\\DarkPortal\\DarkPortalTarget.mdl&quot;
        private constant string ATTACH_POINT_DMG = &quot;origin&quot;
        private constant string EFFECT_HEAL = &quot;Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl&quot;
        private constant string ATTACH_POINT_HEAL = &quot;origin&quot;
    endglobals
    
    private constant function Damage takes integer spellvl returns real
        return spellvl * 50.0
    endfunction
    
    private constant function Heal takes integer spellvl returns real
        return spellvl * 50.0
    endfunction
    
    globals
        private location Z = Location( 0.0, 0.0 )
        private group new = CreateGroup()
        private integer temp = 0
    endglobals
    
    native UnitAlive takes unit id returns boolean
    
    private struct Link extends array
        //! runtextmacro AIDS()
    
        group check
        integer tick
        integer lvl
        lightning light
        player owner
        unit cast
        unit targ
        
        private method AIDS_onCreate takes nothing returns nothing
            set this.tick = R2I( DURATION / T32_PERIOD )
            set this.check = CreateGroup()
        endmethod
        
        private static method Filters takes nothing returns boolean            
            return UnitAlive( GetFilterUnit() ) and ( IsUnit( GetFilterUnit(), Link(temp).cast ) != true or IsUnit( GetFilterUnit(), Link(temp).targ ) )
        endmethod
        
        private static method CheckGroups takes nothing returns nothing
            local unit u = GetEnumUnit()
            local thistype this = temp
            
            if IsUnitInGroup( u, new ) != true then
                
                if IsUnitEnemy( u, this.owner ) then
                    call UnitDamageTarget( this.cast, u, Damage( this.lvl ), true, false, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE )
                    call DestroyEffect( AddSpecialEffectTarget( EFFECT_DMG, u, ATTACH_POINT_DMG ) )
                else
                    call SetWidgetLife( u, GetWidgetLife( u ) + Heal( this.lvl ) )
                    call DestroyEffect( AddSpecialEffectTarget( EFFECT_HEAL, u, ATTACH_POINT_HEAL ) )
                endif
                
            else
                call GroupRemoveUnit( new, u )
            endif
            
            call GroupAddUnit( this.check, u )
            
        endmethod
        
        private method periodic takes nothing returns nothing
            local real x1 = GetUnitX( this.cast )
            local real x2 = GetUnitX( this.targ )
            local real y1 = GetUnitY( this.cast )
            local real y2 = GetUnitY( this.targ )
            local real z1
            local real z2
            
            set this.tick = this.tick - 1
            
            if this.tick &gt;= 0 then
            
                // ========================================================== \\
                
                call MoveLocation( Z, x1, y1 )
        
                set z1 = GetLocationZ( Z ) + GetUnitFlyHeight( cast )
                
                // This is to get the height of both the caster and target <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" /> \\
                
                call MoveLocation( Z, x2, y2 )
        
                set z2 = GetLocationZ( Z ) + GetUnitFlyHeight( targ )
                
                // ========================================================== \\
            
                call MoveLightningEx( this.light, true, x1, y1, z1, x2, y2, z2 )
                
                set temp = this
                
                call GroupEnumUnitsInRangeOfSegment( new, x1, y1, x2, y2, DISTANCE, Filter( function thistype.Filters ) )
                call ForGroup( this.check, function thistype.CheckGroups )
            else
                call DestroyLightning( this.light )
                call this.stopPeriodic()
                
                set this.cast = null
                set this.targ = null
                set this.owner = null
                set this.light = null
            endif
        endmethod
        
        implement T32xs
        
        method StartPeriod takes unit caster, unit target, lightning light returns nothing
            local real x1 = GetUnitX( caster )
            local real x2 = GetUnitX( target )
            local real y1 = GetUnitY( caster )
            local real y2 = GetUnitY( target )
            
            set this.cast = caster
            set this.targ = target
            set this.light = light
            set this.owner = GetOwningPlayer( caster )
            set this.lvl = GetUnitAbilityLevel( this.cast, SPELL_ID )
            
            call GroupEnumUnitsInRangeOfSegment( this.check, x1, y1, x2, y2, DISTANCE, Filter( function thistype.Filters ) )
            
            call this.startPeriodic()
        endmethod
    
    endstruct

    private function Actions takes nothing returns boolean
        local unit u = GetTriggerUnit()
        local unit t = GetSpellTargetUnit()
        local player p = GetOwningPlayer( u )
        local real x1 = GetUnitX( u )
        local real x2 = GetUnitX( t )
        local real y1 = GetUnitY( u )
        local real y2 = GetUnitY( t )
        local real z1
        local real z2
        
        if GetSpellAbilityId() == SPELL_ID then
            call MoveLocation( Z, x1, y1 )
        
            set z1 = GetLocationZ( Z ) + GetUnitFlyHeight( u )
        
            call MoveLocation( Z, x2, y2 )
        
            set z2 = GetLocationZ( Z ) + GetUnitFlyHeight( t )
            
            call Link[ u ].StartPeriod( u, t, AddLightningEx( LIGHTNING_TYPE, false, x1, y1, z1, x2, y2, z2 ) )
        endif
        
        return false
    endfunction

    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger() // Here we&#039;re creating the trigger <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
        local integer i = 0               // This will be used for looping through the players
        
        loop
            call TriggerRegisterPlayerUnitEvent( t, Player( i ), EVENT_PLAYER_UNIT_SPELL_EFFECT, null ) // And here the looping goes.
                                                                                                 // And also, registering the events to the previusly created trigger
            set i = i + 1
            exitwhen i &gt;= 12
        endloop
        
        call TriggerAddCondition( t, Condition( function Actions ) ) // And here we&#039;re adding the condition/action to the trigger
    endfunction
    
endscope


Anyone can spot the problem ? :S
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
I dunno, but shouldn't your filter be [ljass]return UnitAlive(GetFilterUnit()) and IsUnit(GetFilterUnit(), Link(temp).cast) != true and IsUnit(GetFilterUnit(), Link(temp).targ) != true and IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) != true[/ljass]?

Also, to more directly address your original question, I started by looking at Shvegait's RegionAddLineSeg but gave up when I didn't see any [ljass]EnumUnitsInRegion()[/ljass]. :(
 

Komaqtion

You can change this now in User CP.
Reaction score
469
I dunno, but shouldn't your filter be return UnitAlive(GetFilterUnit()) and IsUnit(GetFilterUnit(), Link(temp).cast) != true and IsUnit(GetFilterUnit(), Link(temp).targ) != true and IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) != true?

Yeah, it should XD
My bad ! :p

Also, to more directly address your original question, I started by looking at Shvegait's RegionAddLineSeg but gave up when I didn't see any EnumUnitsInRegion().

Yeah, I looked there too but didn't find it either :(

Anyone else have anything to say about the code ? :S
 

Zwiebelchen

You can change this now in User CP.
Reaction score
60
Ever heard of coordinate transformation? Spells that get objects in a non-circular shape are always done the best with coordinate transformation.

just get the coordinates of the corner points of your area and apply the transformation matrix.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
I'm sorry but that didn't really help...

What is coordinate transformation ?!
 

Hatebreeder

So many apples
Reaction score
381
you could also get the distance and the angle from point a to b, and loop through in a line from point a to b. the number of indices and range would be up to you.

Just use:

loop
exitwhen i == Indice
set i = i + 1
[ljass] set X = SomeXPoint + Distance/Indice * i * Cos(Angle) [/ljass]
[ljass] set Y = SomeYPoint + Distance/indice * i * Sin(Angle) [/ljass]
endloop


fairly simple, no?
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, so I think the spell is done now ! (YAY !! :D)

It got pretty lengthy, and this is actually the first time I've used AIDS quite sucessfully, without any help ! :D:D
And there is some quite good stuff in it (According to me XD)

So I'm really happy about it ;)
Just hope I've done the stuff correctly :S

Please take a look at it ! :D
Here's the code:

JASS:
scope SpiritLink // requires T32, LineSegment, TimerUtils

    globals
        private constant integer SPELL_ID = &#039;SPIR&#039;                      // This is the rawcode of the spell which is to be used !
        
        private constant real DISTANCE = 1.0                            // How close they have to be to the lightning effect to be considered crossing it...
        private constant real IMMUNITY_TIME = 2.0                       // The time that, after a unit has been hit by this spell, it can be hit again...
        
        private constant attacktype ATTACK_TYPE = ATTACK_TYPE_NORMAL    // The attack-type of the damage dealt !
        private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_UNKNOWN   // The damage-type of the damage dealt !
        private constant weapontype WEAPON_TYPE = WEAPON_TYPE_WHOKNOWS  // The weapon-type of the damage dealt !
        
        private constant string LIGHTNING_TYPE = &quot;SPLK&quot;                 // The rawcode of the lightning to be used !
        private constant string EFFECT_DMG = &quot;Abilities\\Spells\\Demon\\DarkPortal\\DarkPortalTarget.mdl&quot;    // The special-effect when units get damaged !
        private constant string ATTACH_POINT_DMG = &quot;origin&quot;                                                  // The attachment point of the special-effect when units get damaged !
        private constant string EFFECT_HEAL = &quot;Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl&quot;   // The special-effect when units get healed !
        private constant string ATTACH_POINT_HEAL = &quot;origin&quot;                                                 // The attachment point of the special-effect when units get healed !
        private constant string EFFECT_FINISH = &quot;Abilities\\Spells\\Orc\\HealingWave\\HealingWaveTarget.mdl&quot;  // The special-effect when the spell is done !
        private constant string ATTACH_POINT_FINISH = &quot;origin&quot;
    endglobals
    
    // How long the spell will last !
    
    private constant function Duration takes integer spellvl returns real
        return 20.0
    endfunction
    
    // The damage which will be dealt when the units cross the lightning !
    
    private constant function Damage takes integer spellvl returns real
        return spellvl * 50.0
    endfunction
    
    // The damage which will be healed when the units cross the lightning !
    
    private constant function Heal takes integer spellvl returns real
        return spellvl * 50.0
    endfunction
    
    //// END OF CONFIGURATION \\\\
    //// END OF CONFIGURATION \\\\
    //// END OF CONFIGURATION \\\\
    
    globals
    
        // Just some globals needed, and for efficiency ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
        
        private location Z = Location( 0.0, 0.0 )
        private group new = CreateGroup()
        private integer temp = 0
    endglobals
    
    // The new native &quot;discovered&quot; by Azlier !
    
    native UnitAlive takes unit id returns boolean
    
    private struct Link extends array
    
        // =========================================================== \\
    
        // Since we&#039;re using AIDS...
        
        //! runtextmacro AIDS()
        
        // =========================================================== \\
        
        group check
        integer tick
        integer lvl
        lightning light
        
        // Don&#039;t mind these <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" /><img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />
        
        player owner
        unit cast
        unit targ
        timer t
        boolean immune
        
        // =========================================================== \\
        
        private method AIDS_onCreate takes nothing returns nothing
            set this.check = CreateGroup()
            set this.immune = false
        endmethod
        
        private static method Filters takes nothing returns boolean
            return UnitAlive( GetFilterUnit() ) and IsUnit( GetFilterUnit(), Link(temp).cast ) != true and IsUnit( GetFilterUnit(), Link(temp).targ ) != true
        endmethod
        
        private static method Immunity takes nothing returns nothing
            
            // =========================================================== \\
            
            local timer t = GetExpiredTimer()
            
            // Locals to prevent leakage, and such <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
            
            local thistype this = GetTimerData( t )
            
            // =========================================================== \\
            
            call ReleaseTimer( t )
            
            // Here we make the unit un-immune again ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
            
            set this.immune = false
            
            // =========================================================== \\
            
            // Just some anti-leakage again <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
            
            set t = null
            set this.t = null
        endmethod
        
        private static method CheckGroups takes nothing returns nothing
        
            // =========================================================== \\
        
            local unit u = GetEnumUnit()
            
            // The usual, locals ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
            
            local thistype this = temp

            // =========================================================== \\
            
            // Here we check if the new units aren&#039;t in the old group, meaning
            // that they have crossed the lightning, and should be damaged/healed
            
            if IsUnitInGroup( u, new ) != true and thistype[ u ].immune != true then
                
                if IsUnitEnemy( u, this.owner ) then
                
            // =========================================================== \\
                
                    call UnitDamageTarget( this.cast, u, Damage( this.lvl ), true, false, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE )
                    
                    // If they aren&#039;t in the group, and is an enemy
                    // damage them !
                    
                    call DestroyEffect( AddSpecialEffectTarget( EFFECT_DMG, u, ATTACH_POINT_DMG ) )
                
            // =========================================================== \\
                
                else
                
            // =========================================================== \\
            
                    call SetWidgetLife( u, GetWidgetLife( u ) + Heal( this.lvl ) )
                    
                    // If they aren&#039;t in the group, and is an ally
                    // heal them !
                    
                    call DestroyEffect( AddSpecialEffectTarget( EFFECT_HEAL, u, ATTACH_POINT_HEAL ) )
                
            // =========================================================== \\
                
                endif
                
                set thistype[ u ].immune = true
                set thistype[ u ].t = NewTimer()
                
                call SetTimerData( thistype[ u ].t, thistype[ u ] )
                call TimerStart( thistype[ u ].t, IMMUNITY_TIME, false, function thistype.Immunity )
            
            endif
            
            // Small leak-cleaning here ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
            
            set u = null
            
        endmethod
        
        private static method ChangeGroups takes nothing returns nothing
            local thistype this = temp
            local unit u = GetEnumUnit()
            
            call GroupRemoveUnit( new, u )
            call GroupAddUnit( this.check, u )
            
            set temp = this
            
            set u = null
        endmethod
        
        private method periodic takes nothing returns nothing
        
            // =========================================================== \\
        
            local real x1 = GetUnitX( this.cast )
            local real x2 = GetUnitX( this.targ )
            local real y1 = GetUnitY( this.cast )
            
            // Same as before... Locals for JASS usage/storage ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
            
            local real y2 = GetUnitY( this.targ )
            local real z1
            local real z2
            
            // =========================================================== \\
            
            set this.tick = this.tick - 1 // This will count how many times the period has run.
                                          // And when it&#039;s 0, then it&#039;s time to stop the lighting !
            
            if this.tick &gt;= 0 then
            
            // =========================================================== \\
                
                call MoveLocation( Z, x1, y1 )
        
                set z1 = GetLocationZ( Z ) + GetUnitFlyHeight( cast )
                
                // Here we take count for the height of both the terrain and
                // when we move the lightning <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
                
                call MoveLocation( Z, x2, y2 )
        
                set z2 = GetLocationZ( Z ) + GetUnitFlyHeight( targ )
            
                // Here we move the lighting to the new coordinates !
            
                call MoveLightningEx( this.light, true, x1, y1, z1, x2, y2, z2 )
                
            // =========================================================== \\
                
                set temp = this
                
                // First we use a globals to be able to use the struct members
                // in the static method &quot;CheckGroups&quot; is...
                // Then we group the units in a line from the caster to the target
                // (Yet again), and then check which to damage and which to heal !
                
                call GroupEnumUnitsInRangeOfSegment( new, x1, y1, x2, y2, DISTANCE, Filter( function thistype.Filters ) )
                call ForGroup( this.check, function thistype.CheckGroups )
                call GroupClear( this.check )
                
                set temp = this
                
                call ForGroup( new, function thistype.ChangeGroups )
                
            // =========================================================== \\
                
            else
            
            // =========================================================== \\
            
                call DestroyEffect( AddSpecialEffectTarget( EFFECT_FINISH, this.cast, ATTACH_POINT_FINISH ) )
                
                // Just some eye-candy so you know when the spell is done <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
                
                call DestroyEffect( AddSpecialEffectTarget( EFFECT_FINISH, this.targ, ATTACH_POINT_FINISH ) )
            
            // =========================================================== \\
                
                call DestroyLightning( this.light )
                call this.stopPeriodic()
                
                // Though, if this.tick has become 0, that means the spell is done
                // and we need to clean some stuff up, like destroying the lightning
                // and stopping the periodic stuff from running <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
                
                set this.cast = null
                set this.targ = null
                set this.owner = null
                set this.light = null
                
            // =========================================================== \\
                
            endif
        endmethod
        
        implement T32xs
        
        private static method StartPeriod takes nothing returns boolean
        
            // =========================================================== \\
        
            local unit caster = GetTriggerUnit()
            local unit target = GetSpellTargetUnit()
            local player p = GetOwningPlayer( caster )
            local thistype this = thistype[ caster ]
            local real x1 = GetUnitX( caster )
            
            // Just the locals we &quot;need&quot; when using JASS ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
            
            local real x2 = GetUnitX( target )
            local real y1 = GetUnitY( caster )
            local real y2 = GetUnitY( target )
            local real z1
            local real z2
            
            // =========================================================== \\
            
            if GetSpellAbilityId() == SPELL_ID then
            
            // =========================================================== \\
            
                call MoveLocation( Z, x1, y1 )
                
                set z1 = GetLocationZ( Z ) + GetUnitFlyHeight( caster )
                
                // Here we take count for the height of both the terrain and
                // when we move the lightning <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
                
                call MoveLocation( Z, x2, y2 )
                
                set z2 = GetLocationZ( Z ) + GetUnitFlyHeight( target )
                
            // =========================================================== \\
                
                set this.cast = caster
                set this.targ = target
                set this.light = AddLightningEx( LIGHTNING_TYPE, false, x1, y1, z1, x2, y2, z2 )
                
                // Here we set stuff necessary for future struct usage <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
                
                set this.owner = p
                set this.lvl = GetUnitAbilityLevel( caster, SPELL_ID )
                set this.tick = R2I( Duration( GetUnitAbilityLevel( caster, SPELL_ID ) ) / T32_PERIOD )
                
            // =========================================================== \\
            
                call GroupEnumUnitsInRangeOfSegment( this.check, x1, y1, x2, y2, DISTANCE, Filter( function thistype.Filters ) )
            
                // Here we group all units in a line from the caster to the
                // target, which will be used to damage the units later <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
                // We also start the periodic check to check which units to damage ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
            
                call this.startPeriodic()
                
            // =========================================================== \\
            
            endif
            
            // Just some leak-cleaning here ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
            
            set caster = null
            set target = null
            set p = null
            
            return false
        endmethod
        
        private static method AIDS_onInit takes nothing returns nothing
            local trigger t = CreateTrigger() // Here we&#039;re creating the trigger <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
            local integer i = 0               // This will be used for looping through the players
        
            loop
                call TriggerRegisterPlayerUnitEvent( t, Player( i ), EVENT_PLAYER_UNIT_SPELL_EFFECT, null ) // And here the looping goes.
                                                                                                 // And also, registering the events to the previusly created trigger
                set i = i + 1
                exitwhen i &gt;= 12
            endloop
        
            call TriggerAddCondition( t, Condition( function thistype.StartPeriod ) ) // And here we&#039;re adding the condition/action to the trigger
        endmethod
    
    endstruct
    
endscope
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, just gonna bump this, and hopefully get some response on the code ! :D
What do you think ? :eek:
As I stated in the first post, this was first only for Avaleirra, but I'm considering submittid it :S

Anyways, I just want someone to take a look at the code, and see if they find something unuseful, or something bad XD

Here's an update on the code :D
(I've added two new globals, MAX_DISTANCE and FREEZE_OR_TERMINATE, which is supposed to handle the max distance between the units but I'm very unsure about the last one, and now quite sure of how to handle the first one :S
Any ideas ?)

JASS:
scope SpiritLink // requires T32, LineSegment, TimerUtils

    globals
        private constant integer SPELL_ID = &#039;SPIR&#039;                      // This is the rawcode of the spell which is to be used !
        
        private constant real RADIUS = 1.0                              // How close they have to be to the lightning effect to be considered crossing it...
        private constant real IMMUNITY_TIME = 2.0                       // The time that, after a unit has been hit by this spell, it can be hit again...
        private constant real MAX_DISTANCE = 0.0                        // The maximum distance the linked units can be from eachother. Set to 0.0 for infinite range <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
        
        private constant boolean FREEZE_OR_TERMINATE = false            // When the maximum distance is reached, what to do ? Set to false to terminate the spell,
                                                                        // or to true to make the units unable to move further away <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
        
        private constant attacktype ATTACK_TYPE = ATTACK_TYPE_NORMAL    // The attack-type of the damage dealt !
        private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_UNKNOWN   // The damage-type of the damage dealt !
        private constant weapontype WEAPON_TYPE = WEAPON_TYPE_WHOKNOWS  // The weapon-type of the damage dealt !
        
        private constant string LIGHTNING_TYPE = &quot;SPLK&quot;                                                                  // The rawcode of the lightning to be used !
        private constant string EFFECT_DMG = &quot;Abilities\\Spells\\Demon\\DarkPortal\\DarkPortalTarget.mdl&quot;                // The special-effect when units get damaged !
        private constant string ATTACH_POINT_DMG = &quot;origin&quot;                                                              // The attachment point of the special-effect when units get damaged !
        private constant string EFFECT_HEAL = &quot;Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl&quot;               // The special-effect when units get healed !
        private constant string ATTACH_POINT_HEAL = &quot;origin&quot;                                                             // The attachment point of the special-effect when units get healed !
        private constant string EFFECT_FINISH = &quot;Abilities\\Spells\\Undead\\ReplenishHealth\\ReplenishHealthCaster.mdl&quot;  // The special-effect when the spell is done !
        private constant string ATTACH_POINT_FINISH = &quot;origin&quot;
        
        // ================================================================================================================================================================================== \\
        
        // PLEASE, DON&#039;T TOUCH THESE GLOBALS ! THANK YOU <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
        
        private location Z = Location( 0.0, 0.0 )
        private group new = CreateGroup()
        private integer temp = 0
        
        // PLEASE, DON&#039;T TOUCH THESE GLOBALS ! THANK YOU <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
        
        // ==================================================================================================================================================================================
    
    endglobals
    
    // How long the whole spell will last !
    
    private constant function Duration takes integer spellvl returns real
        return 20.0
    endfunction
    
    // The damage which will be dealt when the units cross the lightning !
    
    private constant function Damage takes integer spellvl returns real
        return spellvl * 50.0
    endfunction
    
    // The damage which will be healed when the units cross the lightning !
        
    private constant function Heal takes integer spellvl returns real
        return spellvl * 50.0
    endfunction
    
    // The new native &quot;discovered&quot; by Azlier !
    // Don&#039;t change ! XD (Don&#039;t know why you ever would, but still <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />)
    
    native UnitAlive takes unit id returns boolean
    
    // There is a filter inside the struct below which you also can change freely <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
    // It&#039;s called &quot;Filters&quot; and is the first method you&#039;ll see <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
    
    private struct Link extends array
    
        // =========================================================== \\
    
        // Since we&#039;re using AIDS...
        
        //! runtextmacro AIDS()
        
        // =========================================================== \\
        
        // The filter for which units to be damaged/healed !
    
        private static method Filters takes nothing returns boolean
            local thistype this = temp
    
            return UnitAlive( GetFilterUnit() ) and IsUnit( GetFilterUnit(), this.cast ) != true and /*
            */IsUnit( GetFilterUnit(), this.targ ) != true and IsUnitType( GetFilterUnit(), UNIT_TYPE_STRUCTURE ) != true
        endmethod
        
        //// END OF CONFIGURATION \\\\
        //// END OF CONFIGURATION \\\\
        //// END OF CONFIGURATION \\\\
        
        private group check         // The group we use to check which units are to be damaged/healed
        private integer tick        // So we know how many times the periods should run ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
        private integer lvl         // The level of the spell being cast
        private lightning light     // The lightning of the spell
        
        // Don&#039;t mind these <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" /><img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />
        
        private player owner        // Owner of the caster
        private unit cast           // Caster, duh ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />
        private unit targ           // Target ;P
        private timer t             // A timer which controlls how long you are &quot;immune&quot;
                                    // to the spell after being damaged/healed by it <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
        private boolean immune      // An easy boolean check to know if you currently are immune !
        
        // =========================================================== \\
        
        private method AIDS_onCreate takes nothing returns nothing
            set this.check = CreateGroup()
            set this.immune = false
        endmethod
        
        private static method Immunity takes nothing returns nothing
            
            // =========================================================== \\
            
            local timer t = GetExpiredTimer()
            
            // Locals to prevent leakage, and such <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
            
            local thistype this = GetTimerData( t )
            
            // =========================================================== \\
            
            call ReleaseTimer( t )
            
            // Here we make the unit un-immune again ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
            
            set this.immune = false
            
            // =========================================================== \\
            
            // Just some anti-leakage again <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
            
            set t = null
            set this.t = null
        endmethod
        
        private static method CheckGroups takes nothing returns nothing
        
            // =========================================================== \\
        
            local unit u = GetEnumUnit()
            
            // The usual, locals ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
            
            local thistype this = temp

            // =========================================================== \\
            
            // Here we check if the new units aren&#039;t in the old group, meaning
            // that they have crossed the lightning, and should be damaged/healed
            
            if IsUnitInGroup( u, new ) != true and thistype[ u ].immune != true then
                
                if IsUnitEnemy( u, this.owner ) then
                
            // =========================================================== \\
                
                    call UnitDamageTarget( this.cast, u, Damage( this.lvl ), true, false, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE )
                    
                    // If they aren&#039;t in the group, and is an enemy
                    // damage them !
                    
                    call DestroyEffect( AddSpecialEffectTarget( EFFECT_DMG, u, ATTACH_POINT_DMG ) )
                
            // =========================================================== \\
                
                else
                
            // =========================================================== \\
            
                    call SetWidgetLife( u, GetWidgetLife( u ) + Heal( this.lvl ) )
                    
                    // If they aren&#039;t in the group, and is an ally
                    // heal them !
                    
                    call DestroyEffect( AddSpecialEffectTarget( EFFECT_HEAL, u, ATTACH_POINT_HEAL ) )
                
            // =========================================================== \\
                
                endif
                
                set thistype[ u ].immune = true
                set thistype[ u ].t = NewTimer()
                
                call SetTimerData( thistype[ u ].t, thistype[ u ] )
                call TimerStart( thistype[ u ].t, IMMUNITY_TIME, false, function thistype.Immunity )
            
            endif
            
            // Small leak-cleaning here ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
            
            set u = null
            
        endmethod
        
        private static method ChangeGroups takes nothing returns nothing
            local thistype this = temp
            local unit u = GetEnumUnit()
            
            call GroupRemoveUnit( new, u )
            call GroupAddUnit( this.check, u )
            
            set temp = this
            
            set u = null
        endmethod
        
        private method periodic takes nothing returns nothing
        
            // =========================================================== \\
        
            local real x1 = GetUnitX( this.cast )
            local real x2 = GetUnitX( this.targ )
            local real y1 = GetUnitY( this.cast )
            
            // Same as before... Locals for JASS usage/storage ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
            
            local real y2 = GetUnitY( this.targ )
            local real z1
            local real z2
            
            // =========================================================== \\
            
            set this.tick = this.tick - 1 // This will count how many times the period has run.
                                          // And when it&#039;s 0, then it&#039;s time to stop the lighting !
            
            if this.tick &gt;= 0 then
            
            // =========================================================== \\
                
                call MoveLocation( Z, x1, y1 )
        
                set z1 = GetLocationZ( Z ) + GetUnitFlyHeight( cast )
                
                // Here we take count for the height of both the terrain and
                // when we move the lightning <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
                
                call MoveLocation( Z, x2, y2 )
        
                set z2 = GetLocationZ( Z ) + GetUnitFlyHeight( targ )
            
                // Here we move the lighting to the new coordinates !
            
                call MoveLightningEx( this.light, true, x1, y1, z1, x2, y2, z2 )
                
            // =========================================================== \\
                
                set temp = this
                
                // First we use a globals to be able to use the struct members
                // in the static method &quot;CheckGroups&quot; is...
                // Then we group the units in a line from the caster to the target
                // (Yet again), and then check which to damage and which to heal !
                
                call GroupEnumUnitsInRangeOfSegment( new, x1, y1, x2, y2, RADIUS, Filter( function thistype.Filters ) )
                call ForGroup( this.check, function thistype.CheckGroups )
                call GroupClear( this.check )
                
                set temp = this
                
                call ForGroup( new, function thistype.ChangeGroups )
                
            // =========================================================== \\
                
            else
            
            // =========================================================== \\
            
                call DestroyEffect( AddSpecialEffectTarget( EFFECT_FINISH, this.cast, ATTACH_POINT_FINISH ) )
                
                // Just some eye-candy so you know when the spell is done <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
                
                call DestroyEffect( AddSpecialEffectTarget( EFFECT_FINISH, this.targ, ATTACH_POINT_FINISH ) )
            
            // =========================================================== \\
                
                call DestroyLightning( this.light )
                call this.stopPeriodic()
                
                // Though, if this.tick has become 0, that means the spell is done
                // and we need to clean some stuff up, like destroying the lightning
                // and stopping the periodic stuff from running <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
                
                set this.cast = null
                set this.targ = null
                set this.owner = null
                set this.light = null
                
            // =========================================================== \\
                
            endif
        endmethod
        
        implement T32xs
        
        private static method StartPeriod takes nothing returns boolean
        
            // =========================================================== \\
        
            local unit caster = GetTriggerUnit()
            local unit target = GetSpellTargetUnit()
            local player p = GetOwningPlayer( caster )
            local thistype this = thistype[ caster ]
            local real x1 = GetUnitX( caster )
            
            // Just the locals we &quot;need&quot; when using JASS ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
            
            local real x2 = GetUnitX( target )
            local real y1 = GetUnitY( caster )
            local real y2 = GetUnitY( target )
            local real z1
            local real z2
            
            // =========================================================== \\
            
            if GetSpellAbilityId() == SPELL_ID then
            
            // =========================================================== \\
            
                call MoveLocation( Z, x1, y1 )
                
                set z1 = GetLocationZ( Z ) + GetUnitFlyHeight( caster )
                
                // Here we take count for the height of both the terrain and
                // when we move the lightning <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
                
                call MoveLocation( Z, x2, y2 )
                
                set z2 = GetLocationZ( Z ) + GetUnitFlyHeight( target )
                
            // =========================================================== \\
                
                set this.cast = caster
                set this.targ = target
                set this.light = AddLightningEx( LIGHTNING_TYPE, false, x1, y1, z1, x2, y2, z2 )
                
                // Here we set stuff necessary for future struct usage <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
                
                set this.owner = p
                set this.lvl = GetUnitAbilityLevel( caster, SPELL_ID )
                set this.tick = R2I( Duration( GetUnitAbilityLevel( caster, SPELL_ID ) ) / T32_PERIOD )
                set temp = this
                
            // =========================================================== \\
            
                call GroupEnumUnitsInRangeOfSegment( this.check, x1, y1, x2, y2, RADIUS, Filter( function thistype.Filters ) )
            
                // Here we group all units in a line from the caster to the
                // target, which will be used to damage the units later <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
                // We also start the periodic check to check which units to damage ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
            
                call this.startPeriodic()
                
            // =========================================================== \\
            
            endif
            
            // Just some leak-cleaning here ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
            
            set caster = null
            set target = null
            set p = null
            
            return false
        endmethod
        
        private static method AIDS_onInit takes nothing returns nothing
            local trigger t = CreateTrigger() // Here we&#039;re creating the trigger <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
            local integer i = 0               // This will be used for looping through the players
        
            loop
                call TriggerRegisterPlayerUnitEvent( t, Player( i ), EVENT_PLAYER_UNIT_SPELL_EFFECT, null ) // And here the looping goes.
                                                                                                 // And also, registering the events to the previusly created trigger
                set i = i + 1
                exitwhen i &gt;= 12
            endloop
        
            call TriggerAddCondition( t, Condition( function thistype.StartPeriod ) ) // And here we&#039;re adding the condition/action to the trigger
        endmethod
    
    endstruct
    
endscope
 
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