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
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), 039;h01O039;, 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], 039;A028039;)
call IssueTargetOrder(dummydg[inte], "magicleash", dg.filter)
call UnitApplyTimedLife(dummydg[inte], 039;BTLF039;, 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, 039;A024039;)
set dg.x = GetUnitX(dg.caster)
set dg.y = GetUnitY(dg.caster)
set dg.range = I2R(GetUnitAbilityLevel(dg.caster, 039;A024039;)) * 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;A024039;
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>