• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] Following pets

Status
Not open for further replies.
Level 6
Joined
Oct 23, 2006
Messages
141
In my RPG i need a trigger which keeps a pet (or just unit) close to a hero, in other words so it does not walk to far away or get left behind. Now i know your thinking the owner of the unit could simply keep them together but if an owner so chooses he could mess up other triggers in the game. Thank you for reading!
 
Level 2
Joined
Apr 28, 2009
Messages
22
Maybe just do something like.

Every 0.3 seconds of the game
If (pet) is not in within range(350) of (petOwner)
then move (pet) to a random point within range(300) of (petOwner)
else
do nothing

Maybe instead of a move instantly, do an issue move? That way it doesn't jump around the place and it doesn't look so bad. If that case, I'd make the pet's movement speed the same(maybe a little faster) than the petOwner.
 
Level 12
Joined
Jul 27, 2008
Messages
1,181
You could create an order for the pet to guard the hero and make it unselectable:
  • Trigger
  • Events
    • Player - Player 1 (Red) - Selects a unit
    • Player - Player 2 (Red) - Selects a unit
    • Player - Player 3 (Red) - Selects a unit
    • Player - Player 4 (Red) - Selects a unit
    • Player - Player 5 (Red) - Selects a unit
    • ... etc
  • Conditions
    • Unit-Type of (Triggering Unit) Equal to <PET>
  • Actions
    • Player - Clear Selection for (Triggering Player)
And maybe add commands too, such as attack, stay close etc.
 
Last edited:
Level 4
Joined
Apr 25, 2008
Messages
75
In my map (Creature Island) I have a similar system. There is a minor problem though and that is that if one unit is faster than the other they will get further apart and also if they select the following unit and order it to stop it will stop following (until either issues a new order). With some simple triggers I guess you could fix these problems (teleport back if they get too far away)

  • Auto Follow Creature
    • Events
      • Unit - A unit Is issued an order targeting a point
    • Conditions
      • (Ordered unit) Equal to Active[(Player number of (Owner of (Ordered unit)))]
    • Actions
      • Unit - Order CreatureTamer[(Player number of (Owner of (Ordered unit)))] to Follow (Ordered unit)
  • Auto Follow Tamer
    • Events
      • Unit - A unit Is issued an order targeting a point
    • Conditions
      • (Ordered unit) Equal to CreatureTamer[(Player number of (Owner of (Ordered unit)))]
    • Actions
      • Unit - Order Active[(Player number of (Owner of (Ordered unit)))] to Follow (Ordered unit)
 
Level 10
Joined
Jan 28, 2009
Messages
394
There is really simple and effective way to do this - that is if you dont want the player to have much control over the pet and rather want the pet to just fallow a single unit.

Edit Locus Swarm so its only 1 unit - your pet. Hide it in a spell book, set the duration to 999999 and use a trigger to make the unit cast it.
 
Level 4
Joined
Apr 25, 2008
Messages
75
There is really simple and effective way to do this - that is if you dont want the player to have much control over the pet and rather want the pet to just fallow a single unit.

Edit Locus Swarm so its only 1 unit - your pet. Hide it in a spell book, set the duration to 999999 and use a trigger to make the unit cast it.

I guess that would work too. But difference between my one and your one is that in my map players have max control over the pet as well as the main character.
 
Level 11
Joined
Feb 22, 2006
Messages
752
If you want your pet to basically always be within X range of your hero, just do what The_Nyne said. To prevent players from spamming stop on the pet, just make a trigger that detects when it receives any order. Check to see if the pet is farther than X from its hero, and if it is, just reissue the move order. (Of course you can see that this way the pet will literally do nothing except try to get back to its hero if it's too far away...which may be a problem.)
 
Level 10
Joined
Jan 28, 2009
Messages
394
I guess that would work too. But difference between my one and your one is that in my map players have max control over the pet as well as the main character.

Uhh is this thread to help you or Hargoth? It looks like he doesnt want the player to have much control over the pet.. but i have been wrong b4.
 
Level 6
Joined
Jul 25, 2005
Messages
221
Here's a simple Pet AI map I just made for you
(Haven't added leak removes because I don't find it necessary if its only for show)
This is how you should design your pet's commands
Note that this also comes with a command where you can turn on/off the AI, so you let the player decide whether or not the pet should be automated or controlled
Adding to these triggers, you can use a trigger that teleports the pet back to the caster if the pet is too far away (and if AI is on)
I feel dirty allover, I don't like triggering in GUI :cute:

Let's see, what can be improved?
1) If you have more than one pet, you can create an array of points (each one representing a point around the master) and then position each pet for each point.
2) You can add a better follow system, where if the degree to the targeted offset point is bigger than the masters degree to the targeted point then assign a new point that doesn't interfere with the masters point (not creating an X pattern where they cross paths with eachother), or something...

And here are the triggers for those who are lazy:


Pet Initiation
  • PetInit
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Summon Flame Seeker
    • Actions
      • Set intPlayerNumber = (Player number of (Triggering player))
      • Set pointSpawnLocation = ((Position of (Triggering unit)) offset by 150.00 towards ((Facing of (Triggering unit)) + 90.00) degrees)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • isFlameSeekerActive[intPlayerNumber] Equal to True
        • Then - Actions
          • Unit - Kill uFlameSeeker[intPlayerNumber]
        • Else - Actions
      • Unit - Create 1 Flame Seeker for (Owner of (Triggering unit)) at pointSpawnLocation facing (Facing of (Triggering unit)) degrees
      • Set uFlameSeeker[intPlayerNumber] = (Last created unit)
      • Set uFlameMaster[intPlayerNumber] = (Triggering unit)
      • Set isFlameSeekerActive[intPlayerNumber] = True
      • Unit - Order uFlameSeeker[intPlayerNumber] to Night Elf Demon Hunter - Activate Immolation
Pet AI
  • PetAI
    • Events
      • Unit - A unit Is issued an order targeting an object
      • Unit - A unit Is issued an order targeting a point
      • Unit - A unit Is issued an order with no target
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Master
    • Actions
      • Set intPlayerNumber = (Player number of (Triggering player))
      • Game - Display to (All players) the text: (String((Issued order)))
      • -------- If there is no flame seeker, or if the AI is turned off, this trigger will end here --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • isFlameSeekerActive[intPlayerNumber] Equal to False
              • isAIOn[intPlayerNumber] Equal to False
        • Then - Actions
          • Skip remaining actions
        • Else - Actions
      • -------- if the event was an order --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • (Issued order) Equal to (Order(smart))
              • (Issued order) Equal to (Order(stop))
              • (Issued order) Equal to (Order(holdposition))
              • (Issued order) Equal to (Order(attack))
              • (Issued order) Equal to (Order(move))
        • Then - Actions
          • -------- Smart Move --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Issued order) Equal to (Order(smart))
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Or - Any (Conditions) are true
                    • Conditions
                      • ((Target unit of issued order) is A structure) Equal to True
                      • ((Target unit of issued order) is A Hero) Equal to True
                      • ((Target unit of issued order) is A ground unit) Equal to True
                      • ((Target unit of issued order) is A flying unit) Equal to True
                • Then - Actions
                  • Unit - Order uFlameSeeker[intPlayerNumber] to Attack (Target unit of issued order)
                • Else - Actions
                  • Set pointMove = ((Target point of issued order) offset by 150.00 towards ((Angle from (Position of uFlameMaster[intPlayerNumber]) to (Target point of issued order)) + 90.00) degrees)
                  • Unit - Order uFlameSeeker[intPlayerNumber] to Move To pointMove
            • Else - Actions
          • -------- Stop --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Issued order) Equal to (Order(stop))
            • Then - Actions
              • Unit - Order uFlameSeeker[intPlayerNumber] to Stop
            • Else - Actions
          • -------- Hold Position --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Issued order) Equal to (Order(holdposition))
            • Then - Actions
              • Unit - Order uFlameSeeker[intPlayerNumber] to Hold Position
            • Else - Actions
          • -------- Attack --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Issued order) Equal to (Order(attack))
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Or - Any (Conditions) are true
                    • Conditions
                      • ((Target unit of issued order) is A structure) Equal to True
                      • ((Target unit of issued order) is A Hero) Equal to True
                      • ((Target unit of issued order) is A ground unit) Equal to True
                      • ((Target unit of issued order) is A flying unit) Equal to True
                • Then - Actions
                  • Unit - Order uFlameSeeker[intPlayerNumber] to Attack (Target unit of issued order)
                • Else - Actions
                  • Set pointMove = ((Target point of issued order) offset by 150.00 towards ((Angle from (Position of uFlameMaster[intPlayerNumber]) to (Target point of issued order)) + 90.00) degrees)
                  • Unit - Order uFlameSeeker[intPlayerNumber] to Attack-Move To pointMove
            • Else - Actions
          • -------- Move --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Issued order) Equal to (Order(move))
            • Then - Actions
              • Set pointMove = ((Target point of issued order) offset by 150.00 towards ((Angle from (Position of uFlameMaster[intPlayerNumber]) to (Target point of issued order)) + 90.00) degrees)
              • Unit - Order uFlameSeeker[intPlayerNumber] to Move To pointMove
            • Else - Actions
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • ((Target unit of issued order) is A structure) Equal to True
                  • ((Target unit of issued order) is A Hero) Equal to True
                  • ((Target unit of issued order) is A ground unit) Equal to True
                  • ((Target unit of issued order) is A flying unit) Equal to True
            • Then - Actions
              • Unit - Order uFlameSeeker[intPlayerNumber] to Attack (Target unit of issued order)
            • Else - Actions
Pet State (AI on or off)
  • PetManagement
    • Events
      • Unit - A unit Is issued an order with no target
    • Conditions
      • And - All (Conditions) are true
        • Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • (Issued order) Equal to (Order(immolation))
              • (Issued order) Equal to (Order(unimmolation))
          • (Unit-type of (Triggering unit)) Equal to Flame Seeker
    • Actions
      • Set intPlayerNumber = (Player number of (Triggering player))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Issued order) Equal to (Order(immolation))
        • Then - Actions
          • Set isAIOn[intPlayerNumber] = True
        • Else - Actions
          • Set isAIOn[intPlayerNumber] = False
Pet Dies
  • PetDeath
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Flame Seeker
    • Actions
      • Set intPlayerNumber = (Player number of (Triggering player))
      • Set isFlameSeekerActive[intPlayerNumber] = False
      • Set isAIOn[intPlayerNumber] = False
Pet is out of range
  • PetRange
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Flame Seeker
    • Actions
      • Set intPlayerNumber = (Player number of (Owner of (Attacking unit)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • And - All (Conditions) are true
            • Conditions
              • (Distance between (Position of uFlameMaster[intPlayerNumber]) and (Position of uFlameSeeker[intPlayerNumber])) Greater than 1000.00
              • isAIOn[intPlayerNumber] Equal to True
        • Then - Actions
          • Set pointMove = ((Position of uFlameMaster[intPlayerNumber]) offset by 150.00 towards ((Angle from (Position of uFlameMaster[intPlayerNumber]) to (Target point of issued order)) + 90.00) degrees)
          • Unit - Move uFlameSeeker[intPlayerNumber] instantly to pointMove, facing (Facing of uFlameMaster[intPlayerNumber]) degrees
        • Else - Actions
 

Attachments

  • Simple Pet AI.w3x
    23.4 KB · Views: 70
Last edited:
Status
Not open for further replies.
Top