• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

what condition to add to stop infinite loop? [GUI]

Status
Not open for further replies.
Level 15
Joined
Jul 9, 2008
Messages
1,552
its been a very long time since iv done map editing and iv got this basic knock back spell that infin loops and im unsure what i have to add to stop it

first off im using this to detect attacks witch is gui freindly
JASS:
//*********************************************************************************************
//* GUI-Friendly Damage Detection -- v1.2.0 -- by Weep                                        *
//*    [url]http://www.thehelper.net/forums/showthread.php?t=137957[/url]                                *
//*                                                                                           *
//*    Requires: only this trigger and its variables.                                         *
//*                                                                                           *
//* -- What? --                                                                               *
//*    This snippet provides a leak-free, GUI-friendly implementation of an "any unit takes   *
//*    damage" event.  It requires no JASS knowledge to use.                                  *
//*                                                                                           *
//*    It uses the Game - Value Of Real Variable event as its method of activating other      *
//*    triggers, and passes the event responses through a few globals.                        *
//*                                                                                           *
//* -- Why? --                                                                                *
//*    The traditional GUI method of setting up a trigger than runs when any unit is damaged  *
//*    leaks trigger events.  This snippet is easy to implement and removes the need to do    *
//*    you own GUI damage detection setup.                                                    *
//*                                                                                           *
//* -- How To Implement --                                                                    *
//*    0. Before you copy triggers that use GDD into a new map, you need to copy over GDD     *
//*       with its GDD Variable Creator trigger, or the variables won't be automatically      *
//*       created correctly.                                                                  *
//*                                                                                           *
//*    1. Be sure "Automatically create unknown variables while pasting trigger data" is      *
//*       enabled in the World Editor general preferences.                                    *
//*    2. Copy this trigger category ("GDD") and paste it into your map.                      *
//*       (Alternately: create the variables listed in the globals block below, create a      *
//*       trigger named "GUI Friendly Damage Detection", and paste in this entire text.)      *
//*    3. Create your damage triggers using Game - Value Of Real Variable as the event,       *
//*       select GDD_Event as the variable, and leave the rest of the settings to the default *
//*       "becomes Equal to 0.00".                                                            *
//*       The event responses are the following variables:                                    *
//*          GDD_Damage is the amount of damage, replacing Event Response - Damage Taken.     *
//*          GDD_DamagedUnit is the damaged unit, replacing Event Response - Triggering Unit. *
//*          GDD_DamageSource is the damaging unit, replacing Event Response - Damage Source. *
//*                                                                                           *
//* -- Notes --                                                                               *
//*    Don't write any values to the variables used as the event responses, or it will mess   *
//*    up any other triggers using this snippet for their triggering.  Only use their values. *
//*                                                                                           *
//*    This uses arrays, so can have a maximum of 8190 instances at a time, and cleans up     *
//*    data at a rate of 33.33 per second.  This should be enough for most maps.              *
//*                                                                                           *
//* -- Credits --                                                                             *
//*    Captain Griffin on wc3c.net for the research and concept of GroupRefresh.              *
//*                                                                                           *
//*    Credit in your map not needed, but please include this README.                         *
//*                                                                                           *
//* -- Version History --                                                                     *
//*    1.2.0: Made this snippet work properly with recursive damage.                          *
//*    1.1.1: Added a check in order to not index units with the Locust ability (dummy units).*
//*           If you wish to check for damage taken by a unit that is unselectable, do not    *
//*           give the unit-type Locust in the object editor; instead, add the Locust ability *
//*           'Aloc' via a trigger after its creation, then remove it.                        *
//*    1.1.0: Added a check in case a unit gets moved out of the map and back.                *
//*    1.0.0: First release.                                                                  *
//*                                                                                           *
//*********************************************************************************************

//globals
//    real udg_GDD_Event
//    real udg_GDD_Damage
//    unit udg_GDD_DamagedUnit
//    unit udg_GDD_DamageSource
//    trigger array udg_GDD__TriggerArray
//    integer array udg_GDD__Integers
//    unit array udg_GDD__UnitArray
//    group udg_GDD__LeftMapGroup
//endglobals

function GDD_Event takes nothing returns boolean
    local unit damagedcache = udg_GDD_DamagedUnit
    local unit damagingcache = udg_GDD_DamageSource
    local real damagecache = udg_GDD_Damage
    set udg_GDD_DamagedUnit = GetTriggerUnit()
    set udg_GDD_DamageSource = GetEventDamageSource()
    set udg_GDD_Damage = GetEventDamage()
    set udg_GDD_Event = 1.
    set udg_GDD_Event = 0.
    set udg_GDD_DamagedUnit = damagedcache
    set udg_GDD_DamageSource = damagingcache
    set udg_GDD_Damage = damagecache
    set damagedcache = null
    set damagingcache = null
    return false
endfunction

function GDD_AddDetection takes nothing returns boolean
//    if(udg_GDD__Integers[0] > 8190) then
//        call BJDebugMsg("GDD: Too many damage events!  Decrease number of units present in the map or increase recycle rate.")
//        ***Recycle rate is the number used in the TimerStart line at the bottom of this trigger.  Smaller is faster.***
//        return
//    endif
    if(IsUnitInGroup(GetFilterUnit(), udg_GDD__LeftMapGroup)) then
        call GroupRemoveUnit(udg_GDD__LeftMapGroup, GetFilterUnit())
    else
        if(GetUnitAbilityLevel(GetFilterUnit(), 'Aloc') == 0) then
            set udg_GDD__Integers[0] = udg_GDD__Integers[0]+1
            set udg_GDD__UnitArray[udg_GDD__Integers[0]] = GetFilterUnit()
            set udg_GDD__TriggerArray[udg_GDD__Integers[0]] = CreateTrigger()
            call TriggerRegisterUnitEvent(udg_GDD__TriggerArray[udg_GDD__Integers[0]], udg_GDD__UnitArray[udg_GDD__Integers[0]], EVENT_UNIT_DAMAGED)
            call TriggerAddCondition(udg_GDD__TriggerArray[udg_GDD__Integers[0]], Condition(function GDD_Event))
        endif
    endif
    return false
endfunction

function GDD_PresetDetection takes nothing returns nothing
    local group g = CreateGroup()
    local integer i = 0
    set i = 0
    loop
        call GroupEnumUnitsOfPlayer(g, Player(i), Condition(function GDD_AddDetection))
        call GroupClear(g)
        set i = i+1
        exitwhen i == bj_MAX_PLAYER_SLOTS
    endloop
    call DestroyGroup(g)
    set g = null
endfunction

function GDD_GroupRefresh takes nothing returns nothing
//Based on GroupRefresh by Captain Griffen on wc3c.net
    if (bj_slotControlUsed[5063] == true) then
        call GroupClear(udg_GDD__LeftMapGroup)
        set bj_slotControlUsed[5063] = false
    endif
    call GroupAddUnit(udg_GDD__LeftMapGroup, GetEnumUnit())
endfunction

function GDD_Recycle takes nothing returns nothing
    if(udg_GDD__Integers[0] <= 0) then
        return
    elseif(udg_GDD__Integers[1] <= 0) then
        set udg_GDD__Integers[1] = udg_GDD__Integers[0]
    endif
    if(GetUnitTypeId(udg_GDD__UnitArray[udg_GDD__Integers[1]]) == 0) then
        call DestroyTrigger(udg_GDD__TriggerArray[udg_GDD__Integers[1]])
        set udg_GDD__TriggerArray[udg_GDD__Integers[1]] = null
        set udg_GDD__TriggerArray[udg_GDD__Integers[1]] = udg_GDD__TriggerArray[udg_GDD__Integers[0]]
        set udg_GDD__UnitArray[udg_GDD__Integers[1]] = udg_GDD__UnitArray[udg_GDD__Integers[0]]
        set udg_GDD__UnitArray[udg_GDD__Integers[0]] = null
        set udg_GDD__Integers[0] = udg_GDD__Integers[0]-1
    endif
    set udg_GDD__Integers[1] = udg_GDD__Integers[1]-1
endfunction

function GDD_LeaveMap takes nothing returns boolean
    local boolean cached = bj_slotControlUsed[5063]
    if(udg_GDD__Integers[2] < 64) then
        set udg_GDD__Integers[2] = udg_GDD__Integers[2]+1
    else
        set bj_slotControlUsed[5063] = true
        call ForGroup(udg_GDD__LeftMapGroup, function GDD_GroupRefresh)
        set udg_GDD__Integers[2] = 0
    endif
    call GroupAddUnit(udg_GDD__LeftMapGroup, GetFilterUnit())
    set bj_slotControlUsed[5063] = cached
    return false
endfunction

//===========================================================================
function InitTrig_GUI_Friendly_Damage_Detection takes nothing returns nothing
    local region r = CreateRegion()
    call RegionAddRect(r, GetWorldBounds())
    call TriggerRegisterEnterRegion(CreateTrigger(), r, Condition(function GDD_AddDetection))
    call TriggerRegisterLeaveRegion(CreateTrigger(), r, Condition(function GDD_LeaveMap))
    call GDD_PresetDetection()
    call TimerStart(CreateTimer(), 0.03, true, function GDD_Recycle)
    set r = null
endfunction

the spell has x amount of chance to push the unit back dealing bonus damage on attacks but the spell is looping witch causes the game to crash.
  • Shunt On
    • Events
      • Game - GDD_Event becomes Equal to 0.00
    • Conditions
      • (Level of Shunt for GDD_DamageSource) Not equal to 0
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in Knockers) Equal to 0
            • Then - Actions
              • Trigger - Turn on Shunt Loop <gen>
            • Else - Actions
          • Set Time2 = (Time2 + 1)
          • Set Hero2[Time2] = GDD_DamageSource
          • Set UnitA[Time2] = GDD_DamagedUnit
          • Unit - Turn collision for UnitA[Time2] Off
          • Unit Group - Add UnitA[Time2] to Knockers
          • Set Knock[1] = (Position of Hero2[Time2])
          • Set KnockPos[1] = (Position of UnitA[Time2])
          • Set Angel[Time2] = (Angle from Knock[Time2] to KnockPos[1])
          • Set SpeedKnock[Time2] = 12.00
          • Set KnockLevel[Time2] = (Level of Shunt for Hero2[Time2])
          • Unit - Cause Hero2[Time2] to damage UnitA[Time2], dealing ((Real((Level of Shunt for Hero2[Time2]))) x 10.00) damage of attack type Spells and damage type Force
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • KnockLevel[Time2] Equal to 1
            • Then - Actions
              • Set DistanceKnock[Time2] = 300.00
              • Set Formula[Time2] = (DistanceKnock[Time2] / SpeedKnock[Time2])
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • KnockLevel[Time2] Equal to 2
                • Then - Actions
                  • Set DistanceKnock[Time2] = 350.00
                  • Set Formula[Time2] = (DistanceKnock[Time2] / SpeedKnock[Time2])
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • KnockLevel[Time2] Equal to 3
                    • Then - Actions
                      • Set DistanceKnock[Time2] = 400.00
                      • Set Formula[Time2] = (DistanceKnock[Time2] / SpeedKnock[Time2])
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • KnockLevel[Time2] Equal to 4
                        • Then - Actions
                          • Set DistanceKnock[Time2] = 450.00
                          • Set Formula[Time2] = (DistanceKnock[Time2] / SpeedKnock[Time2])
                        • Else - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • KnockLevel[Time2] Equal to 5
                            • Then - Actions
                              • Set DistanceKnock[Time2] = 500.00
                              • Set Formula[Time2] = (DistanceKnock[Time2] / SpeedKnock[Time2])
                            • Else - Actions
          • Custom script: call RemoveLocation(udg_Knock[1])
          • Custom script: call RemoveLocation(udg_KnockPos[1])
        • Else - Actions
  • Shunt Loop
    • Events
      • Time - Every 0.02 seconds of game time
    • Conditions
    • Actions
      • For each (Integer Loop2) from 1 to Time2, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (UnitA[Loop2] is in Knockers) Equal to True
            • Then - Actions
              • Set KnockPos[1] = (Position of UnitA[Loop2])
              • Set SpeedKnock[Loop2] = (DistanceKnock[Loop2] / Formula[Loop2])
              • Set SpeedKnock[Loop2] = (SpeedKnock[Loop2] + 1.00)
              • Set KnockPos[2] = (KnockPos[1] offset by SpeedKnock[Loop2] towards Angel[Loop2] degrees)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Terrain pathing at KnockPos[2] of type Walkability is off) Equal to True
                • Then - Actions
                  • Set DistanceKnock[Loop2] = 0.00
                • Else - Actions
                  • Unit - Move UnitA[Loop2] instantly to KnockPos[2]
                  • Special Effect - Create a special effect at KnockPos[1] using Abilities\Weapons\LichMissile\LichMissile.mdl
                  • Special Effect - Destroy (Last created special effect)
                  • Custom script: call RemoveLocation(udg_KnockPos[1])
                  • Custom script: call RemoveLocation(udg_KnockPos[2])
                  • Set DistanceKnock[Loop2] = (DistanceKnock[Loop2] - SpeedKnock[Loop2])
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • DistanceKnock[Loop2] Less than or equal to 3.00
                    • Then - Actions
                      • Unit Group - Remove UnitA[Loop2] from Knockers
                      • Unit - Turn collision for UnitA[Loop2] On
                      • Set SpeedKnock[Loop2] = 0.00
                      • Set KnockLevel[Loop2] = 0
                      • Set DistanceKnock[Loop2] = 0.00
                      • Set Formula[Loop2] = 0.00
                      • Set Angel[Loop2] = 0.00
                      • Custom script: call RemoveLocation(udg_Knock[udg_Loop2])
                      • Set UnitA[Loop2] = No unit
                      • Set Hero2[Loop2] = No unit
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Number of units in Knockers) Equal to 0
                        • Then - Actions
                          • Set Time2 = 0
                          • Trigger - Turn off Shunt Loop <gen>
                        • Else - Actions
                    • Else - Actions
            • Else - Actions

i believe this is whats causing the loop. cause the unit dealing the damage has the spell lvl requirement to set the trigger off

  • Unit - Cause Hero2[Time2] to damage UnitA[Time2], dealing ((Real((Level of Shunt for Hero2[Time2]))) x 10.00) damage of attack type Spells and damage type Force
i could always spawn a dummy unit to deal the damage but this trigger is also firing when the hero casts other spells that deal damage witch is the part i dont know how to get around
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,191
Turn off damage detection trigger, deal damage, then turn it on.

If not possible then you can use a boolean variable as a lock, which is set true at start of trigger and false at end. If the trigger fires while the lock variable is true then it will have triggered itself (infinite loop) so you do nothing.
 
Level 15
Joined
Jul 9, 2008
Messages
1,552
Turn off damage detection trigger, deal damage, then turn it on.

If not possible then you can use a boolean variable as a lock, which is set true at start of trigger and false at end. If the trigger fires while the lock variable is true then it will have triggered itself (infinite loop) so you do nothing.

doing this i believe ill still have the problem of the units being pushed when the unit casts other spells that deal damage.

Weep's GDD can't detect that. GDD can only detect damage.

if you want to detect attacks, use Bribe's DamageEngine or looking_for_help's PDD


where can i find bribe's damageengine or looking_for_help's PDD and witch one would be better for my situation
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
doing this i believe ill still have the problem of the units being pushed when the unit casts other spells that deal damage.
Turning off the trigger helps stop the triggered damage you have in the actions from creating an infinite loop. You turn it on again after the trigger is done. It shouldn't have any other side effects.
 
Status
Not open for further replies.
Top