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
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      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