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

[Trigger] Ordering a Computer to Attack a Unit

Status
Not open for further replies.
Level 1
Joined
May 4, 2009
Messages
5
Hello Hive! I'm having a bit of trouble with a certain trigger. I am trying to make a spell that, when cast, causes a group of computer controlled units to attack that specific target until either it dies or the spell is used on a different target. The spell is simple enough to trigger, but the computer units will not stay focused on that target. They will instead act like an attack-move command is issued and target the weakest/closest target. Any idea on how to fix this? Here's the trigger:

  • Assault On
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) equal to Assault
    • Actions
      • Set AssaultTarget = (Target unit of ability being cast)
      • Unit - Order (Casting unit) to Stop
      • Unit Group - Pick every unit in ComputerUnits and do (Actions)
        • Loop - Actions
          • Unit - Order (Picked Unit) to Attack AssaultTarget
The computer units will run towards the target, but will instead attack a closer target. Help would be very much appreciated. Thanks!
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
You need to provide more information on your ComputerUnits group. It seems to me like this trigger isn't the problem, and that something else that is lurking in your code could be interfering with the "proper" execution of this trigger.
 
Level 11
Joined
Jan 25, 2009
Messages
572
Well this is what u need to do. This is if you have 2 computer players then you must do this. (If you have three you just create one more unit group variable and store the computer units into that one)
  • Actions
    • Set AssaultTarget = (Target unit of ability being cast)
    • Set ComputersUnitsP11 = (Units owned by Player 11 (Dark Green))
    • Set ComputerUnitsP12 = (Units owned by Player 12 (Brown))
    • Unit Group - Add all units of ComputersUnitsP11 to ComputersUnits
    • Unit Group - Add all units of ComputerUnitsP12 to ComputersUnits
    • Unit Group - Pick every unit in ComputersUnits and do (Actions)
      • Loop - Actions
        • Unit - Order (Picked unit) to Attack (AssaultTarget)
        • Custom script: call DestroyGroup(udg_ComputerUnitsP11)
        • Custom script: call DestroyGroup(udg_ComputerUnitsP12)
        • Custom script: call DestroyGroup(udg_ComputerUnits)
Try this, and if it's not working quote me.
 
Level 1
Joined
May 4, 2009
Messages
5
The map is a single player RPG where you control only one unit of your party at a time (Player 1). The other two party members are controlled by a computer (Player 2) and follow the controlled member around.

I'll include all of the triggers I have for the system, but to test the problem I created a hero owned by computer player 3 whom I have no triggers for, did nothing but ordered him to attack a golem surrounded by murlocs, and he still ignored the golem and went straight for the closest murloc. When I changed the owner of that hero to human player 1, the hero attacked only the golem with no problems. This leads me to believe that the problem is with the default computer AI, though I'm still relatively new the triggering, so I could be entirely wrong. :xxd:

Here are the involved triggers:
  • Initialization
    • Events
      • Time - Elapsed game time is 0.01 seconds
    • Conditions
    • Actions
      • Unit - Create 1 Arthas (wielding Frostmourne) for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
      • Set ControlledUnit = (Last created unit)
      • Set HeroAngle = (Facing of ControlledUnit)
      • Unit - Create 1 Muradin Bronzebeard for Player 1 (Red) at ((Position of ControlledUnit) offset by 200.00 towards (HeroAngle + 140) degrees) facing Default building facing degrees
      • Set PartyMember[0] = (Last created unit)
      • Unit Group - Add (PartyMember[0]) to ComputerUnits
      • Unit - Change ownership of PartyMember[0] to Player 2 (Blue) and Retain color
      • Unit - Create 1 Jaina for Player 1 (Red) at ((Position of ControlledUnit) offset by 200.00 towards (HeroAngle - 140) degrees) facing Default building facing degrees
      • Set PartyMember[1] = (Last created unit)
      • Unit Group - Add (PartyMember[1]) to ComputerUnits
      • Unit - Change ownership of PartyMember[0] to Player 2 (Blue) and Retain color
The trigger has more actions, but none are relevant to the Assault ability.

  • Assault On
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) equal to Assault
    • Actions
      • Set AssaultTarget = (Target unit of ability being cast)
      • Unit - Order (Casting unit) to Stop
      • Set Assaulting = True
      • Trigger - Turn on Assault Off <gen>
      • Unit Group - Pick every unit in ComputerUnits and do (Actions)
        • Loop - Actions
          • Unit - Order (Picked Unit) to Attack AssaultTarget
When Assault begins casting, the target is set but the caster stops before the spell is fully cast to prevent mob aggro. The two computer units owned by Player 2 are ordered to Attack the target.

  • Assault Off (Initially Off)
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Dying unit) Equal to AssaultTarget
    • Actions
      • Set Assaulting = False
      • Trigger - Turn on Combat Check <gen>
      • Trigger - Turn off (This trigger)
When AssaultTarget dies, the computer controlled units will go back to their default behavior.

  • Combat Check
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Set CombatEnemies = Units within 500.00 of (Position of ControlledUnit) matching (((Matching unit) belongs to an enemy of Player 1 (Red)) Equal to True) and (((Matching unit) is alive) Equal to True)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Assaulting Equal to False
          • (CombatEnemies is empty) Equal to True
        • Then - Actions
          • Set InCombat = False
        • Else - Actions
          • Set InCombat = True
Checks whether there are any enemies close to Player 1 and whether the Assault ability has been used. If so, it prevents the following trigger:

  • Movement P0
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
      • (Owner of ControlledUnit) Equal to Player 1 (Red)
      • InCombat Equal to False
    • Actions
      • Unit - Order PartyMember[0] to Attack-Move To ((Position of ControlledUnit) offset by 200.00 towards (HeroAngle + 140 degrees)
      • Unit - Order PartyMember[1] to Attack-Move To ((Position of ControlledUnit) offset by 200.00 towards (HeroAngle - 140 degrees)
If InCombat is set to False, the computer units will continuously Attack-Move into a triangle formation behind the controlled hero. HeroAngle is set in a separate trigger that, along with other angle and camera related actions, sets HeroAngle to Player 1's hero's facing angle every 0.01 second.

The only one I can see that could even remotely affect the Assault ability other than the default computer AI is Movement P0's Attack-Move Actions, but those should be disabled until AssaultTarget is killed and it should have not affect computer player 3's unit at all. Also, as I said above, I am pretty new to triggering, so if you spot any leaks or funky triggering, please let me know. Thanks again!
 
Level 6
Joined
Jan 31, 2009
Messages
166
At a glance I would guess the problem is that your using "A unit begins casting an ability" instead of "A unit begins the affects of the ability" because the first starts before the ability is actually cast there is no valid target. Even if this is not your problem it is still a better Idea to use beings the affects of an ability because otherwise if you quickly cancel it you can cast the ability without cool down or mana cost.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Kuai90 said:
When Assault begins casting, the target is set but the caster stops before the spell is fully cast to prevent mob aggro. The two computer units owned by Player 2 are ordered to Attack the target.

Arcmage said:
Even if this is not your problem it is still a better Idea to use beings the affects of an ability because otherwise if you quickly cancel it you can cast the ability without cool down or mana cost.

He uses "Starts casting an ability" for a specific reason, in this case its okay.

EpiK_Phail said:
  • Unit - Change ownership of PartyMember[0] to Player 2 (Blue) and Retain color

You do this twice in the Initialization trigger, you should be doing it for PartyMember[0] and PartyMember[1].

Also, why are you doing a loop through your Unit Group when there are only 2 units that you need to address, PartyMember[0] and PartyMember[1]. You could just issue them each to attack the target individually. Try it and see if they successfully attack the target.
 
Level 1
Joined
May 4, 2009
Messages
5
Nice catch on the typo, thanks!

I'm mainly using a Unit Group because I intend to allow the player to switch control to a different party member by using an ability. It just saves me from having to create 3 separate triggers for Assault based on which of the 3 party members the player is currently controlling. Just to be safe, I tried ordering the two units individually. They attacked the Assault target for a second or two, then switched to a weaker nearby unit.

I double checked that AssaultTarget was actually being set to the unit by creating a special effect above AssaultTarget every couple of seconds. The unit is indeed being set correctly.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
How about this.

Make a separate trigger in your map that detects when a unit is issued a point or target order. When this happens, display on-screen the order string of the issued order. Since this event responds to trigger-executed orders, it should tell you which orders are being issued, and you'll see when. Once you get that working show what your results were (the messages displayed). They should be "attack" right after the spell is used, and then (as you have stated) the unit will be issued another order that cancels his attacking of the targeted unit.
 
Level 1
Joined
May 4, 2009
Messages
5
There we go! I gave the ability to the two computer units as well to make implementing the party member switching trigger easier. It turns out the computers were casting the spell themselves on the weaker units. I'll just have to add and remove the ability for the controlled unit with triggers. Thank you so much for the help! :grin:
 
Last edited:
Status
Not open for further replies.
Top