Tutorial Keeping Wandering Units In An Area

death_knight

Dark is the heart of a corrupted man.
Reaction score
24
This tutorial is aimed at helping you keep wandering units inside a specific area. This tutorial will be using 3x Pigs with Wander Ability and 2x regions (1. Main Area; 2. Minor area). Anything else that is needed will be specific to the requirements and will be listed at the appropriate time.

Part 1: Keeping inside the Main Area
In this part, we will be looking at keeping our Pig moving inside our area.

Whether you create the pig by triggers or place it in the editor, it doesn't matter; as long as if you create it through triggers, you set the pig to a unit variable for later use. You may call this variable whatever you want but for this tutorial, the variable will be called "Pig001" for the first pig, and "Pig002" for the second pig. For this part, we will only be using "Pig001"

Here is how to create the pig through triggers and set it to the variable:
Creating the Pig
Events
Time - Elapsed game time is 0.01 seconds
Conditions
Actions
Unit - Create 1 Pig for Neutral Passive at (Center of Main Area <gen>) facing Default building facing degrees
Set Pig001 = (Last created unit)
Unit - Create 1 Pig for Neutral Passive at (Center of Main Area <gen>) facing Default building facing degrees
Set Pig002 = (Last created unit)

You can shoose any owner of the pig for now but my suggestion is Neutral Passive because that removes player interference.

There are two triggers below. One is for the pre-loaded pig and the other is for the trigger-created pig.
Pig Tries to Leave
Events
Unit - A unit leaves Main Area <gen>
Conditions
(Leaving unit) Equal to Pig 0000 <gen>
Actions
Unit - Order Pig 0000 <gen> to Move To (Random point in Main Area <gen>)
Pig Tries to Leave Variable
Events
Unit - A unit leaves Main Area <gen>
Conditions
(Triggering unit) Equal to Pig001
Actions
Unit - Order Pig 001 to Move To (Random point in Main Area <gen>)

DO NOT use "Unit - Move Unit (Instantly)" because it doesn't flow in terms of unit movement.

Part 2: Area Transition
To start, make sure that Minor Region <gen> overlaps Main Region <gen>. The purpose of the overlap was so that the pig can enter a different part of the area without setting off the trigger we just created.

We will again only be using "Pig001" in this Part

Here are the two triggers, one with the pre-loaded pig and one with the trigger-created pig.
Pig enters Minor Area
Events
Unit - A unit enters Minor Area <gen>
Conditions
(Entering unit) Equal to Pig 0000 <gen>
Actions
Unit - Order Pig 0000 <gen> to Move To (Random point in Minor Area <gen>)
Pig enters Minor Area Variable
Events
Unit - A unit enters Minor Area <gen>
Conditions
(Entering unit) Equal to Pig001
Actions
Unit - Order Pig 001 <gen> to Move To (Random point in Minor Area <gen>)

Part 3: More Than One Unit Exiting
In this part we will be using both "Pig001" and "Pig002".

For this part, we will remove the condition and replace the action with 2 "If, Then, Else" actions (1 for each pig). The triggering is as follows, the first being the one with the pre-loaded unit and the other with the trigger-created unit:
Both Pigs
Events
Unit - A unit leaves Main Area <gen>
Conditions
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Leveling Hero) Equal to Pig 0000 <gen>
Then - Actions
Unit - Order Pig 0000 <gen> to Move To (Random point in Main Area <gen>)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Leveling Hero) Equal to Pig 0002 <gen>
Then - Actions
Unit - Order Pig 0002 <gen> to Move To (Random point in Main Area <gen>)
Else - Actions
Both Pigs Variable
Events
Unit - A unit leaves Main Area <gen>
Conditions
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Leveling Hero) Equal to Pig001
Then - Actions
Unit - Order Pig001 to Move To (Random point in Main Area <gen>)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Leveling Hero) Equal to Pig002
Then - Actions
Unit - Order Pig002 to Move To (Random point in Main Area <gen>)
Else - Actions

Part 4: Multiple Units Entering the Minor Area
For this part, we will remove the condition and replace the action with 2 "If, Then, Else" actions (1 for each pig). The triggering is as follows, the first being the one with the pre-loaded unit and the other with the trigger-created unit:

Both Pigs Enters Minor
Events
Unit - A unit enters Minor Area <gen>
Conditions
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Leveling Hero) Equal to Pig 0000 <gen>
Then - Actions
Unit - Order Pig 0000 <gen> to Move To (Random point in Minor Area <gen>)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Leveling Hero) Equal to Pig 0002 <gen>
Then - Actions
Unit - Order Pig 0002 <gen> to Move To (Random point in Minor Area <gen>)
Else - Actions
Both Pigs Enters Minor Variable
Events
Unit - A unit enters Minor Area <gen>
Conditions
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Leveling Hero) Equal to Pig001
Then - Actions
Unit - Order Pig001 to Move To (Random point in Minor Area <gen>)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Leveling Hero) Equal to Pig002
Then - Actions
Unit - Order Pig002 to Move To (Random point in Minor Area <gen>)
Else - Actions

Thx to linamus for constructive Critisism (See Below).

Hopefully This helped you. All Critisism Welcome.
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
What if the there are more units than just one, which are not all allowed to wander outside the region?

But it's still nice, though, somewhat short.


P.S

Pictures wouldn't hurt.
 

linamus

I r bak!
Reaction score
57
Kinda blind wander system.
Lemme post better one:


Code:
Pigs
    Events
        Time - Every (Random real number between 1.00 and 15.00) seconds of game time
    Conditions
    Actions
        Unit - Order (Random unit from (Units in Wander Pigs <gen> owned by Neutral Passive)) to Move To (Random point in Wander Pigs <gen>)
Make a region for each creep camp. This way ^ pigs.
Event picks a random pig and orders to move to random region place.
Simple? Usefull?






___________________________

Best Ideas Comes When You're Not Thinking
-> The Land Of Wonders
-> Simple Equipment System TuT
 

ZiggyMcjoney

Data editor?! AAAHHHHH!
Reaction score
95
That number in the event will only be random once, and then it'll be the same number for the rest of the game, by the way.
 

death_knight

Dark is the heart of a corrupted man.
Reaction score
24
Kinda blind wander system.
Lemme post better one:

Code:
Pigs
Events
Time - Every (Random real number between 1.00 and 15.00) seconds of game time
Conditions
Actions
Unit - Order (Random unit from (Units in Wander Pigs <gen> owned by Neutral Passive)) to Move To (Random point in Wander Pigs <gen>)

Make a region for each creep camp. This way ^ pigs.

Event picks a random pig and orders to move to random region place.
Simple? Usefull?

  1. With my trigger, the pig already has wander ability so it is already randomly wandering.
  2. If there was more than one pig, would would have the same event, and instead of the one condition, have one "If, Then, Else" action for each pig.

I must say though, your random point in the region is very good. I will edit my tutorial in place of my action with credit to you and +rep because, now that i think about it, it is a better action than the one I put. Thanks for that good constructive criticism.

What if the there are more units than just one, which are not all allowed to wander outside the region?

But it's still nice, though, somewhat short.


P.S

Pictures wouldn't hurt.

  1. I explained how you could have more than one unit just above and i will also edit it back into the tutorial.
  2. I know it is short but it doesn't have to be long to be useful to someone.
  3. Pictures wouldn't adequetely help me explain what I'm getting at with my triggers and I don't know how to take a video in game.
 

esb

Because none of us are as cruel as all of us.
Reaction score
329
Wouldn't it be better to use Arrays? First you set the arrays to units.
Pig[1] = Pig 001
Pig[2] = Pig 002
...
Pig[12]= Pig 12

For each Integer A 1 - 12 do actions
Order Pig[IntegerA] to move to a random point in <gen> Pig

Something similar.

As for the event beign random, set the event to every 1 second, then add a random wait.
 

vypur85

Hibernate
Reaction score
803
I think you can make it MUI by just checking the ability instead of Unit-type (which is a hassle).

Code:
Pig Tries to Leave
Events
 Unit - A unit leaves Main Area <gen>
Conditions
 Level of Wander for (Triggering unit) Equal to 1
Actions
 Unit - Order (Triggering unit) to Move To (Random point in Main Area <gen>)

But I'm really unsure about one thing. When you order the creep to move to another area, will the wander ability still work? (I mean, will the creep stand there idle after moving to the designated point).

Anyway, your trigger leaks. Maybe you should fix those.

Edit:
Code:
Leveling Hero
There are a lot of these, maybe you should update the trigger. They are supposed to be 'Leaving unit' or 'Triggering unit'.
 

H34DhUnT3r

Ultra Cool Member
Reaction score
36
plz put it in code so: (Spoiler)(Code)(/Code)(/Spoiler)

that is way more clear

for the rest, yea uhm.. is there also a way to create a wander system without regions?

Greetings,
H34DhUnT3r[NL]
 

Drunken_God

Hopes to get back into Mapmaking with SC2 :)
Reaction score
106
uhmm
does this work?
im just wondering
If - Conditions
(Leveling Hero) Equal to Pig 0002 <gen>
Then - Actions
Unit - Order Pig 0002 <gen> to Move To (Random point in Minor Area <gen>)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top