- Joined
- Jan 3, 2011
- Messages
- 14
Opening/Closing Gates
-By RazorHedgeFan
Description:
In this tutorial, I will show you how to open and close gates in the editor using 3 different methods. Gates are means of entrances and exits which can open or close. In Warcraft III, gates are classified as destructibles, which means that they can be destroyed to be opened.
Method 1: Regions
This method allows gates to open once units enter a region.
First, create a gate wherever you'd like. To do this, open the Doodad Palette, and go to Trees/Destructibles.
Next, switch to the Region Palette, and create a new region. Make the region decently big, so that it covers both sides of the gate by a decent margin. Name the region "Open Gate", as this will be the region in which, upon a unit entering, the gate will open. This is how it should look like:
Once the unit leaves the region, the door will close. But to do this, you must incorporate triggers. Open the Trigger Editor (F4) and create a trigger. The goal of the first trigger is to open the gate upon entering the Open Gate region, so let us do that.
First, create a gate wherever you'd like. To do this, open the Doodad Palette, and go to Trees/Destructibles.
Next, switch to the Region Palette, and create a new region. Make the region decently big, so that it covers both sides of the gate by a decent margin. Name the region "Open Gate", as this will be the region in which, upon a unit entering, the gate will open. This is how it should look like:
Once the unit leaves the region, the door will close. But to do this, you must incorporate triggers. Open the Trigger Editor (F4) and create a trigger. The goal of the first trigger is to open the gate upon entering the Open Gate region, so let us do that.
-
Open The Gate
-
Events
- Unit - A unit enters Open Gate <gen>
- Conditions
- Actions
-
Events
-
Open The Gate
-
Events
- Unit - A unit enters Open Gate <gen>
- Conditions
-
Actions
- Destructible - Open Gate (Horizontal) 0045 <gen>
-
Events
-
Close The Gate
-
Events
- Unit - A unit leaves Open Gate <gen>
- Conditions
-
Actions
- Destructible - Close Gate (Horizontal) 0045 <gen>
-
Events
-
Close The Gate
-
Events
- Unit - A unit leaves Open Gate <gen>
- Conditions
-
Actions
- Set GateUnits = (Units in Open Gate <gen>)
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
- (Number of units in GateUnits) Equal to 0
-
Then - Actions
- Destructible - Close Gate (Horizontal) 0045 <gen>
- Else - Actions
-
If - Conditions
- Custom script: call DestroyGroup(udg_GateUnits)
-
Events
Method II: Chat Messages
This method of opening gates involves chat messages to queue opening and closing of gates. If you type -Open, the gate will open. If you type -Close, the gate will close.
For this, perform the same actions in Method I, except ignore making the regions. Simply make the gate, and then open the trigger editor.
For registering chat messages, we must use the event Player - Chat Message. Add this event for all the players. Then we must simply open the gates. You can either make a trigger for each gate, (eg: -Open1, -Open2), but you can also just use one trigger and open all gates upon the -open chat message.
For this, perform the same actions in Method I, except ignore making the regions. Simply make the gate, and then open the trigger editor.
For registering chat messages, we must use the event Player - Chat Message. Add this event for all the players. Then we must simply open the gates. You can either make a trigger for each gate, (eg: -Open1, -Open2), but you can also just use one trigger and open all gates upon the -open chat message.
-
Open The Gate
-
Events
- Player - Player 1 (Red) types a chat message containing -open as An exact match
- Player - Player 2 (Blue) types a chat message containing -open as An exact match
- Player - Player 3 (Teal) types a chat message containing -open as An exact match
- Player - Player 4 (Purple) types a chat message containing -open as An exact match
- Player - Player 5 (Yellow) types a chat message containing -open as An exact match
- Player - Player 6 (Orange) types a chat message containing -open as An exact match
- Player - Player 7 (Green) types a chat message containing -open as An exact match
- Player - Player 8 (Pink) types a chat message containing -open as An exact match
- Player - Player 9 (Gray) types a chat message containing -open as An exact match
- Player - Player 10 (Light Blue) types a chat message containing -open as An exact match
- Player - Player 11 (Dark Green) types a chat message containing -open as An exact match
- Player - Player 12 (Brown) types a chat message containing -open as An exact match
- Conditions
-
Actions
- Destructible - Open Gate (Horizontal) 0045 <gen>
- -------- You can add other gates to open here as well --------
-
Events
-
Close The Gate
-
Events
- Player - Player 1 (Red) types a chat message containing -close as An exact match
- Player - Player 2 (Blue) types a chat message containing -close as An exact match
- Player - Player 3 (Teal) types a chat message containing -close as An exact match
- Player - Player 4 (Purple) types a chat message containing -close as An exact match
- Player - Player 5 (Yellow) types a chat message containing -close as An exact match
- Player - Player 6 (Orange) types a chat message containing -close as An exact match
- Player - Player 7 (Green) types a chat message containing -close as An exact match
- Player - Player 8 (Pink) types a chat message containing -close as An exact match
- Player - Player 9 (Gray) types a chat message containing -close as An exact match
- Player - Player 10 (Light Blue) types a chat message containing -close as An exact match
- Player - Player 11 (Dark Green) types a chat message containing -close as An exact match
- Player - Player 12 (Brown) types a chat message containing -close as An exact match
- Conditions
-
Actions
- Destructible - Close Gate (Horizontal) 0045 <gen>
- -------- You can add other gates to close here as well --------
-
Events
Method III: Unit Range (Medium)
This method is a bit more advanced. It doesn't require regions, but it effectively does the same thing. It will check if a unit enters the range of the gate, and it will open it if so. It will close the gate if not. In this method, we will also discuss dead gates, as well as multiple gates in the game.
So first, let's take into consideration that you have 3 gates. (or more) If you have a situation like this, you will probably want to use an array to easily sort your gates. So first, create a destructible array called Gate. you will want an initialization trigger to set the gate variables to their corresponding destructibles:
This doesn't make sense at the moment, but it will once we make the opening/closing trigger.
To open/close the gate, we will repeatedly check if there are any units in range of the gate. If there are some, then we will open the gate. If there aren't any, then we will close it. Create a Unit Group variable named GateUnits, create a Point variable named GatePoint, and a real array named GateLife.
This is what the trigger will look like:
The loop will loop through all the gates in the map that you have set in the initialization. If you have 5, set it to "1 to 5", or if you have 123, then set it to "1 to 123". The condition immediately afterward corresponds to the gate destroying trigger. It checks if the variable has no value, and if it does have a value, it won't perform the following functions.
The next part groups the units in range of the gate. If there are 1 or more units in the area, it will open the gate. If there are 0 units in the area, it will close the gate. However, you might have noticed some key things:
The next part is this:
Now you should be done with this method. Make sure you have all 3 of the triggers mentioned throughout this method.
So first, let's take into consideration that you have 3 gates. (or more) If you have a situation like this, you will probably want to use an array to easily sort your gates. So first, create a destructible array called Gate. you will want an initialization trigger to set the gate variables to their corresponding destructibles:
-
Gate Initialization
-
Events
- Map initialization
- Conditions
-
Actions
- Set Gate[1] = Gate (Horizontal) 0100 <gen>
- Set Gate[2] = Gate (Horizontal) 0045 <gen>
- Set Gate[3] = Gate (Horizontal) 0099 <gen>
-
Events
-
Gate Initialization
-
Events
- Map initialization
- Conditions
-
Actions
- Set Gate[1] = Gate (Horizontal) 0100 <gen>
- Set Gate[2] = Gate (Horizontal) 0045 <gen>
- Set Gate[3] = Gate (Horizontal) 0099 <gen>
-
For each (Integer A) from 1 to 3, do (Actions)
-
Loop - Actions
- Trigger - Add to Gate Destroyed <gen> the event (Destructible - Gate[(Integer A)] dies)
-
Loop - Actions
-
Events
-
Gate Destroyed
- Events
- Conditions
-
Actions
-
For each (Integer A) from 1 to 3, do (Actions)
-
Loop - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
- (Dying destructible) Equal to Gate[(Integer A)]
-
Then - Actions
- Set Gate[(Integer A)] = No destructible
- Else - Actions
-
If - Conditions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
Loop - Actions
-
For each (Integer A) from 1 to 3, do (Actions)
This doesn't make sense at the moment, but it will once we make the opening/closing trigger.
To open/close the gate, we will repeatedly check if there are any units in range of the gate. If there are some, then we will open the gate. If there aren't any, then we will close it. Create a Unit Group variable named GateUnits, create a Point variable named GatePoint, and a real array named GateLife.
This is what the trigger will look like:
-
Gate OpenClose
-
Events
- Time - Every 0.40 seconds of game time
- Conditions
-
Actions
-
For each (Integer A) from 1 to 3, do (Actions)
-
Loop - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
- Gate[(Integer A)] Not equal to No destructible
-
Then - Actions
- Set GatePoint = (Position of Gate[(Integer A)])
- Set GateUnits = (Units within 350.00 of GatePoint matching ((((Matching unit) is A structure) Equal to False) and (((Matching unit) is alive) Equal to True)))
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
- (Number of units in GateUnits) Greater than 0
-
Then - Actions
- Set GateLife[(Integer A)] = (Current life of Gate[(Integer A)])
- Trigger - Turn off Gate Destroyed <gen>
- Destructible - Open Gate[(Integer A)]
- Trigger - Turn on Gate Destroyed <gen>
-
Else - Actions
- Destructible - Close Gate[(Integer A)]
- Destructible - Set life of Gate[(Integer A)] to GateLife[(Integer A)]
-
If - Conditions
- Custom script: call RemoveLocation(udg_GatePoint)
- Custom script: call DestroyGroup(udg_GateUnits)
- Else - Actions
-
If - Conditions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
Loop - Actions
-
For each (Integer A) from 1 to 3, do (Actions)
-
Events
The loop will loop through all the gates in the map that you have set in the initialization. If you have 5, set it to "1 to 5", or if you have 123, then set it to "1 to 123". The condition immediately afterward corresponds to the gate destroying trigger. It checks if the variable has no value, and if it does have a value, it won't perform the following functions.
The next part groups the units in range of the gate. If there are 1 or more units in the area, it will open the gate. If there are 0 units in the area, it will close the gate. However, you might have noticed some key things:
- Trigger - Turn off Gate Destroyed <gen>
- Destructible - Open Gate[(Integer A)]
- Trigger - Turn on Gate Destroyed <gen>
The next part is this:
-
Destructible - Close Gate[(Integer A)]
- Destructible - Set life of Gate[(Integer A)] to GateLife[(Integer A)]
Now you should be done with this method. Make sure you have all 3 of the triggers mentioned throughout this method.
Final Notes:
You are done! Now you can open and close gates in as many different ways as you want! Enjoy!
Last edited by a moderator: