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

Komaqtion

You can change this now in User CP.
Reaction score
469
Please, anyone wanna help me with this ?!

I'm not sure if that's the newest version, so I'll post the code again...
JASS:
scope SpiritLink // requires T32, LineSegment, TimerUtils

    globals
        private constant integer SPELL_ID = 'SPIR'                      // 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


Btw, do you think this is worth submitting on the forum ? :eek:
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
Here's snippet I did 2-3 days ago. It'sn't done yet. But the UnitEnterCircle function works well :)

Maybe it can help you. I need to do the UnitLeaveCircle tho...

JASS:
library Circle uses T32, Event

    globals
        private group Group = CreateGroup()
        private group Last = null
        
        private unit Enter = null
        private Circle Ancestor
    endglobals
    
    private function avoidLeak takes nothing returns boolean
        return true
    endfunction

    struct Circle
    
        private Event evt
        private group last
        real centerX
        real centerY
        real radius
            
        
        // Remove units that aren&#039;t the the circle anymore from the group    
        private static method Clean takes nothing returns nothing
            local unit u = GetEnumUnit()
            if (IsUnitInGroup(u, Group) == false) then
                call GroupRemoveUnit(Last, u)
            endif
            set u = null
        endmethod
        
        private method periodic takes nothing returns nothing
            local unit u = null
            set Last = .last
            call GroupEnumUnitsInRange(Group, .centerX, .centerY, .radius, Filter(function avoidLeak))
            call ForGroup(.last, function thistype.Clean)
            set .last = Last
            loop
                set u = FirstOfGroup(Group)
                exitwhen u == null
                // If the unit just entered circle, fire.
                // If the unit was already in a circle, do nothing
                if (IsUnitInGroup(u, .last) == false) then
                    call GroupAddUnit(.last, u)
                    set Enter = u
                    set Ancestor = this
                    call .evt.fire()
                endif
                call GroupRemoveUnit(Group, u)
            endloop
        endmethod
        
        static method Create takes nothing returns integer
            // Instance a new struct
            local thistype this = thistype.allocate()
            set this.evt = Event.create()
            set this.last = CreateGroup()
            return this
        endmethod
        
        method Register takes trigger t returns nothing
            // Start Checking for units in the circle
            call .evt.register(t)
            call .startPeriodic()
        endmethod
        
        method Destroy takes nothing returns nothing
            // Stop Checking for units in the circle
            call .evt.destroy()
            call .stopPeriodic()
            call .deallocate()
            call DestroyGroup(.last)
            set .last = null
        endmethod
        
        implement T32x
    endstruct
    
    // Interface
    
    function GetCircleTriggerUnit takes nothing returns unit
        return Enter
    endfunction
    
    function GetTriggerCircle takes nothing returns Circle
        return Ancestor
    endfunction
    
endlibrary


Example of use:

JASS:
function Act takes nothing returns boolean
    call BJDebugMsg(&quot;Debug works. Entering: &quot; + GetUnitName(GetCircleTriggerUnit()))
    call BJDebugMsg(&quot;In Circle : &quot; + I2S(GetTriggerCircle()))
    return false
endfunction

function InitTrig_Sample takes nothing returns nothing
    local trigger t = CreateTrigger()
    local Circle d = Circle.Create()
    set d.centerX = 0.00
    set d.centerY = 0.00
    set d.radius = 700.00
    call TriggerAddCondition(t, Condition(function Act))
    call d.Register(t)
endfunction
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Well, I've already done all that... And it works fine ;)
But thanks anyways :D

But I just want to know if there anything I can do better, and how (Or if) I should use the FREEZE_OR_TERMINATE and MAX_DISTANCE constants...

What do you think ? :eek:
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top