- Joined
- May 9, 2014
- Messages
- 1,820
Good day, reader. This mission is about dynamic indexing.
As we all know, dynamic indexing is one method used to achieve MUI. This snippet will help you understand how it works.
As our demonstration, we will have an active ability that damages a targeted enemy unit.
Per demonstration, the rawcode of the passive ability is
- v.1.0 - Creation of thread.
- v.1.1 - Changed the example from an AoE damage aura to a concentrated blast of damage dealt to a specific unit over 2.00 seconds.
- v.1.2 - Changed the example from damage to heal. Also removed the caster variable.
- v.1.2.1 - Added the Submission tag as it did not have one before...
As we all know, dynamic indexing is one method used to achieve MUI. This snippet will help you understand how it works.
As our demonstration, we will have an active ability that damages a targeted enemy unit.
Per demonstration, the rawcode of the passive ability is
'A000'
Unnamed tab 1
Changelog
JASS:
scope HealUnits initializer Init
globals
// This acts as our control variable
private integer index = 0
// This will come into play later...
private constant timer DAMAGE_TIMER = CreateTimer()
// This is a unit array variable used for those who will get healed.
private unit array target
private real array ticks
endglobals
private function onTickHeal takes nothing returns nothing
local integer i = 1
if index == 0 then
call PauseTimer(DAMAGE_TIMER)
return
endif
loop
exitwhen i > index
if ticks[i] <= 0 or GetWidgetLife(target[i]) < 0.405 then
// Unit must be dead, so we remove the unit from our array list by
// jamming the values of the last index into our to-be-removed index...
set target[i] = target[index]
set ticks[i] = ticks[index]
set caster[index] = null
set index = index - 1
else
call SetWidgetLife(target[i], GetWidgetLife(target[i]) + 2.5)
set ticks[i] = ticks[i] - 1/32.
set i = i + 1
endif
endloop
endfunction
private function Cond takes nothing returns nothing
if GetSpellAbilityId() == 'A000' then
// We check if the index was 0 (index == 0). If it is, we start the timer.
// To be sure, I just use (index <= 0)
if index <= 0 then
// set index = 0
call TimerStart(DAMAGE_TIMER, 1/32., true, function onTickHeal)
endif
// We increment the index to allow for a new target.
set index = index + 1
set target[index] = GetSpellTargetUnit()
set ticks[index] = 2/(1/32.)
endif
endfunction
// This function will be called when the game initializes
// Thank the initializer keyword for that.
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Filter(function Cond))
set t = null
endfunction
- v.1.0 - Creation of thread.
- v.1.1 - Changed the example from an AoE damage aura to a concentrated blast of damage dealt to a specific unit over 2.00 seconds.
- v.1.2 - Changed the example from damage to heal. Also removed the caster variable.
- v.1.2.1 - Added the Submission tag as it did not have one before...
Last edited: