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

[General] Detect nearby enemy

Status
Not open for further replies.
Level 4
Joined
Dec 16, 2013
Messages
84
Sorry for my english

How to make trigger like this

I have a barrel, when im attacking it and there is no nearby enemy, the attacking hero will back to the base
but
if there is nearby enemy, the barrel will kill everyunit nearby included my hero

I need a trigger guys, dont give me any tips please coz i tried it many times with if/then/else still failed

but if its too complicated, then giving a hints is okay

See my trigger
  • Barrel explode
    • Events
      • Unit - BarrelRemove 0011 <gen> Is attacked
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units within 1500.00 of (Center of Region 007 <gen>)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Watery Minion
            • Then - Actions
              • Unit - Kill (Picked unit)
              • Unit - Kill (Attacking unit)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Equal to Adventurer
                • Then - Actions
                  • Unit - Move (Attacking unit) instantly to (Center of Region 004 <gen>)
                  • Selection - Select (Attacking unit)
                  • Camera - Pan camera for Player 1 (Red) to (Center of Region 004 <gen>) over 0.00 seconds
                • Else - Actions
It does work, but it kinda bug
when there is nearby enemy, my hero death at the base and the camera pan to the base too
it supposed to be death at current location and camera stay still
 
Level 31
Joined
Aug 6, 2015
Messages
635
what u mean "hero will back to the base"
if hero will atack the barrel and there is no enemy , he will stop atacking and go to base?
to remove leaks try put barrel position to a variable(for example name it BarrelPosition), and then pick units pick all units in 1500 of posotion of variable.
also after that use custom script : call RemoveLocation(udg_BarrelPosition) to remove any leaks.
in your trigger in second part, after Else
if u want to move Adventurer, move not the atacking unit, but the adventurer.
 
Level 31
Joined
Aug 6, 2015
Messages
635
1st. Create a Variable of type point (call it BarrelPosition)
2st. Set Position of Barrel=BarrelPosition (your variable) u can do it in Set Variable = ...
3st. Unit Group - Pick every unit in (Units within 1500.00 of (Position of BarrelPosition ) and do (Actions)
4st. Custom script : call RemoveLocation(udg_BarrelPosition)
5st.
in your trigger in second part, after Else
if u want to move Adventurer, move not the atacking unit, but the adventurer.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
First of all, this trigger will run when any unit attacks that specific barrel.
This has in my eyes, 2 things that can improve at this point.

1, instead of having the specific event, use the generic event and check if the unit type of the attacked unit is equal to the barrel unit type.
2, add a condition (second condition already) to check if the attacking unit is a hero.
This can be found in Boolean comparison.

Also when selecting the units for your unit group, I suggest you to take the location of the barrel instead of the location of a region. (Except if that is a different location which you want to have.)

The remaining part of the trigger is pretty simple.
You make a boolean variable (TempBoolean for example) and set it to false before the for loop.
Then during the for loop, you check if the picked unit is an enemy of the owner of the attacking unit. This means that there is an enemy inside the range, so that unit has to be killed. We also set that TempBoolean to true.
That is all what that unit loop does.

After the loop, we add another If/Then/Else where we check if TempBoolean is equal to false.
If it is false, there are no nearby enemy units and the attacking unit can be moved to his base (I suggest using starting point of the player as the location to teleport to.)
If it is true, there was a nearby enemy unit (which have all been killed by now) so you kill the attacking unit as well.

Be sure to remove both location and group leaks and store units and players in variables if you use them multiple times.

Sorry for not giving a trigger but this should explain clearly how it would have to look like.
 
Level 4
Joined
Dec 16, 2013
Messages
84
First of all, this trigger will run when any unit attacks that specific barrel.
This has in my eyes, 2 things that can improve at this point.

1, instead of having the specific event, use the generic event and check if the unit type of the attacked unit is equal to the barrel unit type.
2, add a condition (second condition already) to check if the attacking unit is a hero.
This can be found in Boolean comparison.

Also when selecting the units for your unit group, I suggest you to take the location of the barrel instead of the location of a region. (Except if that is a different location which you want to have.)

The remaining part of the trigger is pretty simple.
You make a boolean variable (TempBoolean for example) and set it to false before the for loop.
Then during the for loop, you check if the picked unit is an enemy of the owner of the attacking unit. This means that there is an enemy inside the range, so that unit has to be killed. We also set that TempBoolean to true.
That is all what that unit loop does.

After the loop, we add another If/Then/Else where we check if TempBoolean is equal to false.
If it is false, there are no nearby enemy units and the attacking unit can be moved to his base (I suggest using starting point of the player as the location to teleport to.)
If it is true, there was a nearby enemy unit (which have all been killed by now) so you kill the attacking unit as well.

Be sure to remove both location and group leaks and store units and players in variables if you use them multiple times.

Sorry for not giving a trigger but this should explain clearly how it would have to look like.

1st. Create a Variable of type point (call it BarrelPosition)
2st. Set Position of Barrel=BarrelPosition (your variable) u can do it in Set Variable = ...
3st. Unit Group - Pick every unit in (Units within 1500.00 of (Position of BarrelPosition ) and do (Actions)
4st. Custom script : call RemoveLocation(udg_BarrelPosition)
5st.

thank you guys, but i dont need it anymore hhe
 
Status
Not open for further replies.
Top