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

How to make a unit only attack when certain things happen?

Status
Not open for further replies.
Level 6
Joined
Dec 9, 2014
Messages
176
I'm making a pet system where after summoning a pet, it's then switched to computer control but told to follow your hero. I'm having trouble figuring out how to make the pet only attack when the hero is attacked or attacks and will attack the same target as the hero.

  • Penguin Setup
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Tybalt's Mechanical Penguin
    • Actions
      • Set PenguinPet = (Triggering unit)
      • Wait 0.10 seconds
      • Unit - Change ownership of PenguinPet to Player 2 (Blue) and Retain color
      • Unit - Order PenguinPet to Right-Click Sorceress
      • Unit - Order PenguinPet to Right-Click Wizard
 
Level 6
Joined
Dec 9, 2014
Messages
176
Interesting! Ok, I'll srew around with that. For now I've been messing with these triggers hoping to figure it out.

  • Penguin Setup
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Tybalt's Mechanical Penguin
    • Actions
      • Set PenguinPet = (Triggering unit)
      • Wait 0.10 seconds
      • Unit - Change ownership of PenguinPet to Player 2 (Blue) and Retain color
      • Trigger - Turn on Penguin Defending <gen>
      • Unit - Order PenguinPet to Right-Click Sorceress
      • Unit - Order PenguinPet to Right-Click Wizard
  • Set Penguin Behavior
    • Events
      • Unit - A unit Is attacked
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Attacking unit) Equal to Sorceress) or ((Attacking unit) Equal to Wizard)
        • Then - Actions
          • Trigger - Turn off Penguin Defending <gen>
          • Trigger - Turn on Penguin Attacking <gen>
        • Else - Actions
          • Do nothing
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Attacked unit) Equal to Sorceress) or ((Attacked unit) Equal to Wizard)
        • Then - Actions
          • Trigger - Turn off Penguin Attacking <gen>
          • Trigger - Turn on Penguin Defending <gen>
        • Else - Actions
          • Do nothing
And these start Initially Off:

  • Penguin Defending
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • ((Attacked unit) Equal to Sorceress) or ((Attacked unit) Equal to Wizard)
    • Actions
      • Unit - Order PenguinPet to Attack (Attacking unit)
  • Penguin Attacking
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • ((Attacking unit) Equal to Sorceress) or ((Attacking unit) Equal to Wizard)
    • Actions
      • Unit - Order PenguinPet to Attack (Attacked unit)

So far I've got the Penguin defending me just fine, its switching to my attack target without having the Penguin flip out changing from the target I'm attacking to the one that's attacking me lol.
 
Level 25
Joined
May 11, 2007
Messages
4,651
Why not just code the summoning part too?
Base the spell of Channel with no targets.
Just do:

Events: A unit starts the effect of an ability

Conditions: Ability being cast == Summoning of Dz to this world

Actions:
set tempPoint1 = position of triggering unit
unit - create 1 mechanical penguin for owner of triggering unit at tempPoint1
set PenguinPet = last created unit

remove location(tempPoint1)
unit - change ownership of PenguinPet to player 2 retain colours
order PenguinPet to right click triggering unit

No editor so can't type proper code but you'll get the idea
 
Level 6
Joined
Dec 9, 2014
Messages
176
Why not just code the summoning part too?
Base the spell of Channel with no targets.
Just do:

Events: A unit starts the effect of an ability

Conditions: Ability being cast == Summoning of Dz to this world

Actions:
set tempPoint1 = position of triggering unit
unit - create 1 mechanical penguin for owner of triggering unit at tempPoint1
set PenguinPet = last created unit

remove location(tempPoint1)
unit - change ownership of PenguinPet to player 2 retain colours
order PenguinPet to right click triggering unit

No editor so can't type proper code but you'll get the idea

Actually the summoning of the pet is based off an an altered Ursa Warrior Summon item. When the penguin is summoned the trigger immediately sets the penguin as "PenguinPet" Variable and then changes the control to Blue which is an ally to Red. After that it's told to follow the hero. When the hero is attacked the penguin will attack the unit attacking the hero thereby defending it. If the hero attacks a unit then the penguin should also attack the same target. Now the problem here is that during a battle more units can easily be introduced meaning that the triggers would cause the penguin to continually switch targets instead of focusing on the target being attack be the hero. So what I need to do is make it so that the penguin will focus on the same target as the hero, if the hero has no target then the penguin will attack anything that attacks the hero. Essentially I'm trying to make a "Defensive" behavior for pets from WoW lol
 
Status
Not open for further replies.
Top