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

Auto Re-Target Hero Script not working

Status
Not open for further replies.
Level 3
Joined
Dec 31, 2008
Messages
46
Basically the script is supposed to auto re-target your hero when they select another target, not including when they don't have a hero (hero select) and when they are within X distance of their target, and their target belongs to player 9.

Ways it is working:
Letting me select a hero.
Auto re-target hero when selecting NPC.

Ways its not working:
Not allowing to target player 9's units
Canceling use of targeted spells. (Re-selecting the hero is canceling the action)

This is the only trigger I have with selection, and when its disabled everything works (not including the auto re-target).

Please post if anyone has any questions about this trigger. Also not worries about leaks right now, after all the triggers are set up I will go through and begin removing leaks.

  • Lock to Hero
    • Events
      • Player - Player 1 (Red) Selects a unit
      • Player - Player 2 (Blue) Selects a unit
      • Player - Player 3 (Teal) Selects a unit
      • Player - Player 4 (Purple) Selects a unit
      • Player - Player 5 (Yellow) Selects a unit
      • Player - Player 6 (Orange) Selects a unit
      • Player - Player 7 (Green) Selects a unit
      • Player - Player 8 (Pink) Selects a unit
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • (Number of units in (Units owned by (Triggering player) matching (((Matching unit) is A Hero) Equal to True))) Equal to 0
              • And - All (Conditions) are true
                • Conditions
                  • (Number of units in (Units owned by (Triggering player) matching (((Matching unit) is A Hero) Equal to True))) Equal to 1
                  • (Distance between (Position of (Triggering unit)) and (Position of (Random unit from (Units owned by (Triggering player) matching (((Matching unit) is A Hero) Equal to True))))) Less than or equal to 300.00
                  • (Color of (Owner of (Triggering unit))) Equal to Gray
        • Then - Actions
          • Do nothing
        • Else - Actions
          • Selection - Select (Random unit from (Units owned by (Triggering player) matching (((Matching unit) is A Hero) Equal to True))) for (Triggering player)
 
Level 4
Joined
Mar 20, 2014
Messages
67
It's because in your If/Then/Else you have it saying And - All Conditions are True, and in there you have it equal to player 9. If you want him to be able to select player nine's units then put another or in there and have it be if the owner is equal to gray. As for the canceling of targeted spells it shouldn't do that as far as I know. Because technically you're not untargeting him with a spell.
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
I believe zachhandley has found your problem.

Things you should also no though.
Never use do nothing. It does actually do something and that is slow down your triggers.
You leak multiple unit groups and locations. You should look at the things that leak tutorial.
Anything used twice or more should be stored into a variable and the variable should be used. This is to increase speed and efficiency of your triggers. You can look at my tutorial Things you should know when using triggers / gui.
 
Level 3
Joined
Dec 31, 2008
Messages
46
It's because in your If/Then/Else you have it saying And - All Conditions are True, and in there you have it equal to player 9. If you want him to be able to select player nine's units then put another or in there and have it be if the owner is equal to gray. As for the canceling of targeted spells it shouldn't do that as far as I know. Because technically you're not untargeting him with a spell.

I have a general grasp of what your saying but when I go back into the editor my brain is melting, do you mind posting what you're meaning? (I'm extremely tired, and have a massive headache at the moment.)
 
Level 3
Joined
Dec 31, 2008
Messages
46
I believe zachhandley has found your problem.

Things you should also no though.
Never use do nothing. It does actually do something and that is slow down your triggers.
You leak multiple unit groups and locations. You should look at the things that leak tutorial.
Anything used twice or more should be stored into a variable and the variable should be used. This is to increase speed and efficiency of your triggers. You can look at my tutorial Things you should know when using triggers / gui.

I didn't know that do nothing did that.

As for the memory leaks I already said I'd be going over the triggers when I was finished and remove the memory leaks.

I am using variables for some things, but I am seeing how often I am using the unit for selecting a players hero, so I believe I'm going to convert that into a variable as well.

Anyway thank you for replying! I am actually a semi-experienced WC3 map maker, as well as an actual web and game programmer, I just started on this map yesterday and want to iron out the basics before I start going in and making all the minor tweaks.
 
Level 3
Joined
Dec 31, 2008
Messages
46
Also just mentioning that I only want them to be able to target the units from Player 9 when they are within 300 distance from them.
 
Last edited:
Level 3
Joined
Dec 31, 2008
Messages
46
I THINK I FOUND THE PROBLEM!

I believe since it selecting the hero at the end of the trigger, it is going to repeat the trigger because its part of the event.

I will post the results of fiddling with it.
 
Level 3
Joined
Dec 31, 2008
Messages
46
I got it fixed!

  • Lock to Hero
    • Events
      • Player - Player 1 (Red) Selects a unit
      • Player - Player 2 (Blue) Selects a unit
      • Player - Player 3 (Teal) Selects a unit
      • Player - Player 4 (Purple) Selects a unit
      • Player - Player 5 (Yellow) Selects a unit
      • Player - Player 6 (Orange) Selects a unit
      • Player - Player 7 (Green) Selects a unit
      • Player - Player 8 (Pink) Selects a unit
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • (Number of units in (Units owned by (Triggering player) matching (((Matching unit) is A Hero) Equal to True))) Equal to 0
              • And - All (Conditions) are true
                • Conditions
                  • (Distance between (Position of (Triggering unit)) and (Position of (Random unit from (Units owned by (Triggering player) matching (((Matching unit) is A Hero) Equal to True))))) Less than or equal to 300.00
                  • (Color of (Owner of (Triggering unit))) Equal to Gray
        • Then - Actions
        • Else - Actions
          • Selection - Select (Random unit from (Units owned by (Triggering player) matching (((Matching unit) is A Hero) Equal to True))) for (Triggering player)
          • Trigger - Run Lock to Hero Loop Fix <gen> (checking conditions)
          • Trigger - Turn off (This trigger)
  • Lock to Hero Loop Fix
    • Events
    • Conditions
    • Actions
      • Wait 0.01 seconds
      • Trigger - Turn on Lock to Hero <gen>
 
Status
Not open for further replies.
Top