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:
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.
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.
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:
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:
Thx to linamus for constructive Critisism (See Below).
Hopefully This helped you. All Critisism Welcome.
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)
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>)
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>)
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>)
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>)
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
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
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
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
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.