AoE Shackle trap (Requires channeling) help

LearningCode

New Member
Reaction score
24
Yea, Here is my problem:
I want to store each created dummy in a unit array.

But for some reason, the dummy units keep on getting stored in array '0' instead of this:

1st created dummy stored in array 0
2nd created dummy stored in array 1
etc.
etc.

I want to do this, so that when the caster channeling the ability stops channeling (by whatever means, stun, movement, attacking), I can just remove the dummies and null the array immediately.

But, only one unit is getting shackled and many dummies are being created.

Hoping someone will spot my mistake xD

JASS:

scope Grasp initializer DemonsGrasp
   
   globals
      unit array dummydg
      integer inte
   endglobals
   
   private struct Demon
      private static Demon data = 0
      private static hashtable ht = InitHashtable()
      unit caster
      unit filter
      group g = CreateGroup()
      group shackled
      timer t
      integer A024Level
      real x
      real y
      integer ticks = 0
      real range
      integer done = 0
         
         static method Group takes nothing returns boolean
            local Demon dg = Demon.data
            set inte = 0
            set dg.filter = GetFilterUnit()
               if IsUnitEnemy(dg.filter, GetOwningPlayer(dg.caster)) == true and IsUnitInGroup(dg.filter, dg.shackled) == false then
                  loop
                  exitwhen inte == 400
                     if dummydg[inte] == null then
                        set dummydg[inte] = CreateUnit(GetOwningPlayer(dg.caster), 'h01O', dg.x, dg.y, bj_UNIT_FACING)
                        set dg.done = 1
                     endif
                  exitwhen dg.done == 1
                  set inte = inte + 1
                  endloop
                  call BJDebugMsg("Unit stored in Array "+I2S(inte))
                  call UnitAddAbility(dummydg[inte], 'A028')
                  call IssueTargetOrder(dummydg[inte], "magicleash", dg.filter)
                  call UnitApplyTimedLife(dummydg[inte], 'BTLF', 5.50)
                  call GroupAddUnit(dg.shackled, dg.filter)
               endif
            set dg.filter = null
            return false
         endmethod  
         
         static method Grouping takes nothing returns nothing
            local Demon dg = LoadInteger(Demon.ht, GetHandleId(GetExpiredTimer()), 0)
            if dg.ticks < 641 and GetUnitCurrentOrder(dg.caster) == OrderId("revive") then
               call GroupEnumUnitsInRange(dg.g, dg.x, dg.y, dg.range, function Demon.Group)
               set dg.ticks = dg.ticks + 1
               set Demon.data = dg
            else
               call dg.destroy()
            endif
         endmethod
         
         static method Grasp takes nothing returns nothing
            local Demon dg = Demon.allocate()
            set dg.shackled = CreateGroup()
            set dg.caster = GetTriggerUnit()
            set dg.t = CreateTimer()
            set dg.A024Level = GetUnitAbilityLevel(dg.caster, 'A024')
            set dg.x = GetUnitX(dg.caster)
            set dg.y = GetUnitY(dg.caster)
            set dg.range = I2R(GetUnitAbilityLevel(dg.caster, 'A024')) * 100.00
            call TimerStart(dg.t, 0.03125, true, function Demon.Grouping)
            call SaveInteger(dg.ht, GetHandleId(dg.t), 0, dg)
         endmethod
         
         method onDestroy takes nothing returns nothing
            local integer i = 0
            call BJDebugMsg("Destroy what?")
            call PauseTimer(.t)
            call DestroyTimer(.t)
            set .t = null
            call GroupClear(.shackled)
            call DestroyGroup(.shackled)
            set .shackled = null
            set .caster = null
            loop
            exitwhen i == inte
            call RemoveUnit(dummydg<i>)
            set dummydg<i> = null
            set i = i+1
            endloop
            set inte = 1
         endmethod
         
   endstruct

private function GraspCond takes nothing returns boolean
   return GetSpellAbilityId() == &#039;A024&#039;
endfunction

//===========================================================================
private function DemonsGrasp takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    local integer i = 0
    loop
    exitwhen i == 8
    call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    set i=i+1
    endloop
    call TriggerAddCondition(t, Condition(function GraspCond))
    call TriggerAddAction( t, function Demon.Grasp )
endfunction

endscope

</i></i>
 

Ayanami

칼리
Reaction score
288
Just a suggestion. Why not add the dummy units in a group rather than storing them as unit arrays?
 

LearningCode

New Member
Reaction score
24
I cannot believe this -___-
After posting my problem up, I messed with the trigger for the sake of it..

And I solved it -____-

I should have thought of using groups xD
Oops, I'll keep that in mind, lol

This:
JASS:
                  call UnitAddAbility(dummydg[inte], &#039;A028&#039;)
                  call IssueTargetOrder(dummydg[inte], &quot;magicleash&quot;, dg.filter)
                  call UnitApplyTimedLife(dummydg[inte], &#039;BTLF&#039;, 5.50)



Becomes this:
JASS:
                  call UnitAddAbility(dummydg[inte-1], &#039;A028&#039;)
                  call IssueTargetOrder(dummydg[inte-1], &quot;magicleash&quot;, dg.filter)
                  call UnitApplyTimedLife(dummydg[inte-1], &#039;BTLF&#039;, 5.50)



This:
JASS:
            loop
            call RemoveUnit(dummydg<i>)
            set dummydg<i> = null
            set i = i+1
            exitwhen i == inte
            endloop
</i></i>



Becomes this:
JASS:
            loop
            call RemoveUnit(dummydg<i>)
            set dummydg<i> = null
            set i = i+1
            exitwhen i == inte+1
            endloop
</i></i>




Haiz, now I'd like to know why I have to do that, lol.
I don't get it.
 
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