• 🏆 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!

Problem with a trigger concerning damage detection

Status
Not open for further replies.
Hello guys,
I'm trying to prevent units from getting lured. I don't want to decrease the acquisition range.
So, i tried making triggers that pause units in a specific region and if a unit in that region gets attacked or an enemy unit enters that region, the units will be unpaused.

Here i pause the units in the region 171.
  • Pause Units
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in Region 171 <gen>) and do (Unit - Pause (Picked unit))

If an enemy unit enters that region:
  • Unpause attack 1
    • Events
      • Unit - A unit enters Region 171 <gen>
    • Conditions
      • (Owner of (Triggering unit)) Equal to Player 1 (Red)
    • Actions
      • Trigger - Turn off (This trigger)
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in Region 171 <gen>) and do (Unit - Unpause (Picked unit))
If a unit inside the region gets attacked:
  • Unpause attack 2
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Region 171 <gen> contains (Triggering unit)) Equal to True
    • Actions
      • Trigger - Turn off (This trigger)
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in Region 171 <gen>) and do (Unit - Unpause (Picked unit))
The problem is that this works only if the unit gets attacked, if it receives damage from a spell it doesn't work.
And the Even Units receives damage requires a specific unit so i can't use that.

Any suggestions?

Thank you.
 
Level 6
Joined
Aug 28, 2015
Messages
213
I would do something like:
Pause units trigger:
Set myHostileUnitGroup = units in Region171
Pick every unit in myHostileUnitGroup and do action
-add trigger event(unpause by attack trigger) (picked unit gets damaged)
unpause by attack trigger:
If triggering unit is in group(myHostileUnitGroup) then
-Pick every unit in myHostileUnitGroup and do action
--unpause picked unit
Else
--
-//endloop
Clear and remove group(myHostileUnitGroup)
 
Level 2
Joined
Nov 1, 2010
Messages
19
Well you´ll need a damage detection system to do that, also isnt your trigger turning off before doing anything?
 
Level 9
Joined
Jul 30, 2018
Messages
445
Yep. You need a damage detection system. There are good ones here in Hive.

isnt your trigger turning off before doing anything?

The trigger is ran through even if it was turned off right at the start. This is very common if you need a trigger to only trigger once or on certain cases. Turning off trigger actually kind of just turns the event off, like it can still be ran with another trigger (using Run (trigger)) even if it was turned off.
 
I would do something like:
Pause units trigger:
Set myHostileUnitGroup = units in Region171
Pick every unit in myHostileUnitGroup and do action
-add trigger event(unpause by attack trigger) (picked unit gets damaged)
unpause by attack trigger:
If triggering unit is in group(myHostileUnitGroup) then
-Pick every unit in myHostileUnitGroup and do action
--unpause picked unit
Else
--
-//endloop
Clear and remove group(myHostileUnitGroup)
Can you please transform this into actual Gui and attach the map? :)
 
Level 6
Joined
Aug 28, 2015
Messages
213
For all others here are the triggers:
  • Initialize Hostile Group
    • Events
      • Time - Elapsed game time is 0.30 seconds
    • Conditions
    • Actions
      • -------- The Amount of different groups you want to pause --------
      • Set Lure_GroupAmount = 3
      • -------- I think on your map are more then just one group --------
      • -------- thats why I store everything in arrays --------
      • -------- Set the Regions to loop through later on --------
      • Set Lure_HostileRegions[1] = HostileRegion01 <gen>
      • Set Lure_HostileRegions[2] = HostileRegion02 <gen>
      • Set Lure_HostileRegions[3] = HostileRegion03 <gen>
      • -------- Loop through all Regions and save their contained units in groups --------
      • For each (Integer Lure_Index) from 1 to Lure_GroupAmount, do (Actions)
        • Loop - Actions
          • Set Lure_HostileGroup[Lure_Index] = (Units in Lure_HostileRegions[Lure_Index])
          • -------- Loop through all units and filter the right one to add them to the unpause trigger --------
          • Unit Group - Pick every unit in Lure_HostileGroup[Lure_Index] and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Owner of (Picked unit)) Equal to Player 2 (Blue)
                • Then - Actions
                  • Trigger - Add to Unpause Hostile Group <gen> the event (Unit - (Picked unit) Takes damage)
                  • Unit - Pause (Picked unit)
                • Else - Actions
                  • -------- If the unit is not fitting remove it from the group again --------
                  • Unit Group - Remove (Picked unit) from Lure_HostileGroup[Lure_Index]
  • Unpause Hostile Group
    • Events
    • Conditions
    • Actions
      • -------- Loop through all groups to check wich one to unpause --------
      • For each (Integer Lure_Index) from 1 to Lure_GroupAmount, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Triggering unit) is in Lure_HostileGroup[Lure_Index]) Equal to True
            • Then - Actions
              • -------- unpause the group --------
              • Unit Group - Pick every unit in Lure_HostileGroup[Lure_Index] and do (Actions)
                • Loop - Actions
                  • Unit - Unpause (Picked unit)
              • Custom script: call DestroyGroup(udg_Lure_HostileGroup[udg_Lure_Index])
            • Else - Actions
and the map.
Edit:
Improved the system again now you just need to enter your regions and the rest is done by the system itself.
Triggers:
  • Lure System Initialize
    • Events
      • Time - Elapsed game time is 0.30 seconds
    • Conditions
    • Actions
      • -------- I think on your map are more then just one group --------
      • -------- thats why I store everything in arrays --------
      • -------- Set the Regions to loop through later on --------
      • Set Lure_HostileRegions[1] = HostileRegion01 <gen>
      • Set Lure_HostileRegions[2] = HostileRegion02 <gen>
      • Set Lure_HostileRegions[3] = HostileRegion03 <gen>
      • -------- Because the entering unit event fires before the unit is inside the Region --------
      • -------- we have to create points in offset around the unit to check wich region is entered --------
      • Set Lure_PointOffset = 60.00
      • -------- Loop through all Regions and save their contained units in groups --------
      • For each (Integer Lure_Index) from 0 to Lure_GroupAmount, do (Actions)
        • Loop - Actions
          • -------- check if there will be more groups --------
          • Custom script: if ( not(udg_Lure_HostileRegions[udg_GroupAmount + 1 ] == null)) then
          • Set Lure_GroupAmount = (Lure_GroupAmount + 1)
          • Set Lure_HostileGroup[Lure_GroupAmount] = (Units in Lure_HostileRegions[Lure_GroupAmount])
          • -------- Loop through all units and filter the right one to add them to the unpause trigger --------
          • Unit Group - Pick every unit in Lure_HostileGroup[Lure_GroupAmount] and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Owner of (Picked unit)) Equal to Player 2 (Blue)
                • Then - Actions
                  • Trigger - Add to Lure System Unpause By Attack <gen> the event (Unit - (Picked unit) Takes damage)
                  • Unit - Pause (Picked unit)
                • Else - Actions
                  • -------- If the unit is not fitting remove it from the group again --------
                  • Unit Group - Remove (Picked unit) from Lure_HostileGroup[Lure_GroupAmount]
          • -------- If the group is empty after filtering the units clear memory --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in Lure_HostileGroup[Lure_GroupAmount]) Equal to 0
            • Then - Actions
              • Custom script: call DestroyGroup(udg_Lure_HostileGroup[udg_Lure_GroupAmount])
            • Else - Actions
          • -------- Add Region to entering trigger --------
          • Trigger - Add to Lure System Unpause By Enter <gen> the event (Unit - A unit enters Lure_HostileRegions[Lure_GroupAmount])
          • Custom script: endif
  • Lure System Unpause By Attack
    • Events
    • Conditions
    • Actions
      • -------- Loop through all groups to check wich one to unpause --------
      • For each (Integer Lure_Index) from 1 to Lure_GroupAmount, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Triggering unit) is in Lure_HostileGroup[Lure_Index]) Equal to True
            • Then - Actions
              • -------- unpause the group --------
              • Unit Group - Pick every unit in Lure_HostileGroup[Lure_Index] and do (Actions)
                • Loop - Actions
                  • Unit - Unpause (Picked unit)
              • Custom script: call DestroyGroup(udg_Lure_HostileGroup[udg_Lure_Index])
            • Else - Actions
  • Lure System Unpause By Enter
    • Events
    • Conditions
    • Actions
      • Set TempPoint = (Position of (Triggering unit))
      • -------- we have to create a area around the triggering unit to be able to check in wich region the unit is --------
      • Set Lure_Points[1] = (TempPoint offset by ((Lure_PointOffset x -1.00), (Lure_PointOffset x -1.00)))
      • Set Lure_Points[2] = (TempPoint offset by ((Lure_PointOffset x -1.00), Lure_PointOffset))
      • Set Lure_Points[3] = (TempPoint offset by (Lure_PointOffset, Lure_PointOffset))
      • Set Lure_Points[4] = (TempPoint offset by (Lure_PointOffset, (Lure_PointOffset x -1.00)))
      • -------- Check in wich region the unit is --------
      • For each (Integer Lure_Index) from 1 to Lure_GroupAmount, do (Actions)
        • Loop - Actions
          • -------- add here all your filters you want underneath the "or" condition --------
          • -------- My example is if the unit is a hero... --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • (Lure_HostileRegions[Lure_Index] contains Lure_Points[1]) Equal to True
                  • (Lure_HostileRegions[Lure_Index] contains Lure_Points[2]) Equal to True
                  • (Lure_HostileRegions[Lure_Index] contains Lure_Points[3]) Equal to True
                  • (Lure_HostileRegions[Lure_Index] contains Lure_Points[4]) Equal to True
              • ((Triggering unit) is A Hero) Equal to True
            • Then - Actions
              • -------- unpause the group --------
              • Unit Group - Pick every unit in Lure_HostileGroup[Lure_Index] and do (Actions)
                • Loop - Actions
                  • Unit - Unpause (Picked unit)
              • Custom script: call DestroyGroup(udg_Lure_HostileGroup[udg_Lure_Index])
            • Else - Actions
      • -------- Remove Memory leaks --------
      • Custom script: call RemoveLocation(udg_TempPoint)
      • Custom script: call RemoveLocation(udg_Lure_Points[1])
      • Custom script: call RemoveLocation(udg_Lure_Points[2])
      • Custom script: call RemoveLocation(udg_Lure_Points[3])
      • Custom script: call RemoveLocation(udg_Lure_Points[4])
and the map:
 

Attachments

  • LureSystem.w3x
    17.8 KB · Views: 22
Last edited:
Status
Not open for further replies.
Top