How do I get this loop to run once every 0.2 seconds?

MasterRofl

New Member
Reaction score
8
JASS:
private function Actions takes nothing returns nothing
    local location TargetPoint = GetSpellTargetLoc()
    local group TargetUnits
    local unit TargetUnit
    local location TargetUnitLoc
    local unit DummyUnit
    set udg_Map_TempPlayer = GetOwningPlayer(GetSpellAbilityUnit())
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 10
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
            set TargetUnits = GetUnitsInRangeOfLocMatching( 400.00, TargetPoint, Condition(function Filter) )
            set TargetUnit = GroupPickRandomUnit( TargetUnits )
            set TargetUnitLoc = GetUnitLoc( TargetUnit )
            set DummyUnit = CreateUnitAtLoc( GetOwningPlayer(GetSpellAbilityUnit()), 'n009', TargetUnitLoc, bj_UNIT_FACING )
            call UnitApplyTimedLife( DummyUnit, 'BTLF', 1.00 )
            call UnitAddAbility( DummyUnit, 'A00J' )
            call SetUnitAbilityLevel( DummyUnit, 'A00J', GetUnitAbilityLevel(GetSpellAbilityUnit(), GetSpellAbilityId()) )
            call IssueTargetOrder( DummyUnit, "chainlightning", TargetUnit )
            call TriggerSleepAction( 0.2 )
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    call RemoveLocation(TargetPoint)
    call RemoveLocation(TargetUnitLoc)
    call DestroyGroup(TargetUnits)
    set TargetPoint = null
    set TargetUnit = null
    set DummyUnit = null
endfunction


When I use this trigger, it only runs once. How can I modify it so that it runs 10x?

Also, does this trigger leak?

Much thanks!
 

cleeezzz

The Undead Ranger.
Reaction score
268
JASS:
private function CB takes nothing returns nothing
    local location TargetPoint = GetSpellTargetLoc()
    local group TargetUnits
    local unit TargetUnit
    local location TargetUnitLoc
    local unit DummyUnit
    set udg_Map_TempPlayer = GetOwningPlayer(GetSpellAbilityUnit())
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 10
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
            set TargetUnits = GetUnitsInRangeOfLocMatching( 400.00, TargetPoint, Condition(function Filter) )
            set TargetUnit = GroupPickRandomUnit( TargetUnits )
            set TargetUnitLoc = GetUnitLoc( TargetUnit )
            set DummyUnit = CreateUnitAtLoc( GetOwningPlayer(GetSpellAbilityUnit()), 'n009', TargetUnitLoc, bj_UNIT_FACING )
            call UnitApplyTimedLife( DummyUnit, 'BTLF', 1.00 )
            call UnitAddAbility( DummyUnit, 'A00J' )
            call SetUnitAbilityLevel( DummyUnit, 'A00J', GetUnitAbilityLevel(GetSpellAbilityUnit(), GetSpellAbilityId()) )
            call IssueTargetOrder( DummyUnit, "chainlightning", TargetUnit )
            call TriggerSleepAction( 0.2 )
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    call RemoveLocation(TargetPoint)
    call RemoveLocation(TargetUnitLoc)
    call DestroyGroup(TargetUnits)
    set TargetPoint = null
    set TargetUnit = null
    set DummyUnit = null
endfunction

private function Actions takes nothing returns nothing
    local timer t = CreateTimer()
    call TimerStart(t,0.2,true, function CB)
    set t = null
endfunction


add some kind of condition so you tell the trigger when to stop the timer. then destroy the timer.
 

MasterRofl

New Member
Reaction score
8
I would have to put my locals as a struct then, right? and then attach it to the timer

Also, do you have a suggestion for how to stop the timer? <_<

Does using a for loop and 10 one-shot timers work?
 

cleeezzz

The Undead Ranger.
Reaction score
268
yeah i believe so


well it depends what your code does

for example, when unit life becomes less than 5 or something, just add an IF to check the life and then if it is, destroy the struct + timer
if its a 10 second duration spell, you could do some math to find out how many times a the trigger runs in 10 secs. 10/0.2 seconds. and just do an integer check to see if the time is up
 

MasterRofl

New Member
Reaction score
8
JASS:
scope Indignation initializer Init

private struct Indignation
    location TargetPoint
    group TargetUnits
    unit TargetUnit
    location TargetUnitLoc
    unit DummyUnit
    unit Caster
    integer SpellId
    integer RunCount
        method onDestroy takes nothing returns nothing
            set .TargetUnit = null
            set .DummyUnit = null
            set .Caster = null
            call RemoveLocation(.TargetPoint)
            call RemoveLocation(.TargetUnitLoc)
            call DestroyGroup(.TargetUnits)
        endmethod
endstruct

private function Filter takes nothing returns boolean
    return ( IsUnitEnemy(GetFilterUnit(), udg_Map_TempPlayer) == true )
endfunction

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

private function Callback takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local Indignation d = GetTimerStructA(t)
    if ( d.RunCount &gt; 10 ) then
        call d.destroy()
        call PauseTimer(t)
        call DestroyTimer(t)
        call ClearTimerStructA(t)
    endif
    set d.TargetUnits = GetUnitsInRangeOfLocMatching( 400.00, d.TargetPoint, Condition(function Filter) )
    set d.TargetUnit = GroupPickRandomUnit( d.TargetUnits )
    set d.TargetUnitLoc = GetUnitLoc( d.TargetUnit )
    set d.DummyUnit = CreateUnitAtLoc( GetOwningPlayer(d.Caster), &#039;n009&#039;, d.TargetUnitLoc, bj_UNIT_FACING )
    call UnitApplyTimedLife( d.DummyUnit, &#039;BTLF&#039;, 1.00 )
    call UnitAddAbility( d.DummyUnit, &#039;A00J&#039; )
    call SetUnitAbilityLevel( d.DummyUnit, &#039;A00J&#039;, GetUnitAbilityLevel( d.Caster, d.SpellId) )
    call IssueTargetOrder( d.DummyUnit, &quot;chainlightning&quot;, d.TargetUnit )
    set d.RunCount = d.RunCount + 1
    set t = null
endfunction

private function Actions takes nothing returns nothing
    local Indignation d = Indignation.create()
    local timer t = CreateTimer()
    set d.TargetPoint = GetSpellTargetLoc()
    set d.Caster = GetSpellAbilityUnit()
    set d.SpellId = GetSpellAbilityId()
    set d.RunCount = 1
    set udg_Map_TempPlayer = GetOwningPlayer(GetSpellAbilityUnit())
    call SetTimerStructA(t,d)
    call TimerStart(t, 0.25, true, function Callback)
    set t = null
endfunction

private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, Condition( function Conditions ) )
    call TriggerAddAction( t, function Actions )
endfunction

endscope


Okay, it works now, but it leaks 6-14 handles each time I cast it. What the heck is leaking?

I'm using Romek's Handle-Counting multiboard, btw. (From http://www.thehelper.net/forums/showthread.php?t=108086 )
 

cleeezzz

The Undead Ranger.
Reaction score
268
JASS:
scope Indignation initializer Init

private struct Indignation
    location TargetPoint
    group TargetUnits
    unit TargetUnit
    location TargetUnitLoc
    unit DummyUnit
    unit Caster
    integer SpellId
    integer RunCount
        method onDestroy takes nothing returns nothing
            set .TargetUnit = null
            set .DummyUnit = null
            set .Caster = null
            call RemoveLocation(.TargetPoint)
            call RemoveLocation(.TargetUnitLoc)
            call DestroyGroup(.TargetUnits)
            set .TargetPoint = null
            set .TargetUnitLoc = null
            set .TargetUnits = null
        endmethod
endstruct

private function Filter takes nothing returns boolean
    return ( IsUnitEnemy(GetFilterUnit(), udg_Map_TempPlayer) == true )
endfunction

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

private function Callback takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local Indignation d = GetTimerStructA(t)
    if ( d.RunCount &gt; 10 ) then
        call d.destroy()
        call PauseTimer(t)
        call DestroyTimer(t)
        call ClearTimerStructA(t)
    endif
    set d.TargetUnits = GetUnitsInRangeOfLocMatching( 400.00, d.TargetPoint, Condition(function Filter) )
    set d.TargetUnit = GroupPickRandomUnit( d.TargetUnits )
    set d.TargetUnitLoc = GetUnitLoc( d.TargetUnit )
    set d.DummyUnit = CreateUnitAtLoc( GetOwningPlayer(d.Caster), &#039;n009&#039;, d.TargetUnitLoc, bj_UNIT_FACING )
    call UnitApplyTimedLife( d.DummyUnit, &#039;BTLF&#039;, 1.00 )
    call UnitAddAbility( d.DummyUnit, &#039;A00J&#039; )
    call SetUnitAbilityLevel( d.DummyUnit, &#039;A00J&#039;, GetUnitAbilityLevel( d.Caster, d.SpellId) )
    call IssueTargetOrder( d.DummyUnit, &quot;chainlightning&quot;, d.TargetUnit )
    set d.RunCount = d.RunCount + 1
    set t = null
endfunction

private function Actions takes nothing returns nothing
    local Indignation d = Indignation.create()
    local timer t = CreateTimer()
    set d.TargetPoint = GetSpellTargetLoc()
    set d.Caster = GetSpellAbilityUnit()
    set d.SpellId = GetSpellAbilityId()
    set d.RunCount = 1
    set udg_Map_TempPlayer = GetOwningPlayer(GetSpellAbilityUnit())
    call SetTimerStructA(t,d)
    call TimerStart(t, 0.25, true, function Callback)
    set t = null
endfunction

private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, Condition( function Conditions ) )
    call TriggerAddAction( t, function Actions )
endfunction

endscope


your not nulling
 
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