On this guide we are going to do two very basic conditions to define when player loses or wins. First one is very simple and second is a bit more complicated while it uses If-Then-Else action. By doing these triggers you understand trigger system better and you can modify later these triggers for your own needs.
- - -
We are going to do a trigger that defines how player loses. On my example I have already made a Marine hero unit called Max Järvinen. So we are going to do a trigger that makes player to lose if Max dies. If you have no hero unit on your map you can simply add some more rare unit to your map. It helps to find it easier on long lists later if you have only one Battlecruiser for example on your map.
Open Triggers window by pressing F6 or clicking triggers. On left side of window right click and select New element (Ctrl+W). Name that trigger as "Defeat". On right side of the screen click "Events" which marked with small yellow flag. Then click bigger yellow flag (New Event) or CTRL+E.
From left side choose "Unit" and from right side choose "Unit dies". Click green "Any unit" word on bottom of the window. To source Select "Value" and from this list select your unit which must survive. Events part is done.
Lets do new action by right clicking on top of right side of the window. You have to be on correct area of window to get some actions done. Select New - New action. From left side select "Game" and from right side select "End game for player".
Player number depends on it how you have set your player properties. Choose "defeat" for green "victory" text. Now we have working action for Player 1 defeat so we can copy it and use it for Player 2 victory. Click that action and copy-paste it with CTRL+C, CTRL+V. Or do it my right clicking. We only need to change "defeat" to "victory" and player number from "1" to "2". Picture at end.
Now your trigger works if your "Player properties" are set right. To modify those click Map - Player properties. Picture at end.
Now we are going to define how player (=Player 1) wins the game. On this tutorial player must destroy 2 of enemy Orbital Commands and one Planetary Fortress to achieve victory.
Let's begin by doing new variable by right clicking and selecting New Variable. Name it as "Things to destroy". Double click "Initial value" and set it to 3. Make sure its type is "Integer". (that should be default value)
Now lets do a trigger much like we did in Trigger 1 practise. Right click on left side of window, New Element. Name it as "Destroyed". New event (yellow flags) - Unit - Unit dies. Choose some of these 3 buildings "to die". To Action we choose "Variable" from left side and from right side "Modify variable (Integer) Click green Variable text and choose "Things to destroy" to it. Change "+" to "-" (plus to minus).
Now we have working "Destroyed" trigger and we need 2 more of these - one for each destroyable building. Copy and paste "Destroyed" 2 times. Now you have "Destroyed 2" and "Destroyed 3" triggers. You only need to change "Unit dies" event to be a building other than in "Destroyed" trigger.
Now to final (fifth) thing that combines our earlier work. Lets do right click - New Element. Name it as "Victory", New event, choose Timer - Periodic event, every 5 seconds of game time. To actions from "General" tab choose "If Then Else". Right click "If" and choose "New conditon". Choose "Within Bounds" next. To "Value" click and select "Things to destroy". On left and right sides set 0. (0<=Things to destroy<=0)
Select "Then" and make New Action. Game - End game for player. Make player 1 to win and player 2 to lose just like in Practise 1.
Okay we have done lot of things so lets think what we actually did with all these triggers. We have determined that "Things to destroy" is 3. Each "Destroyed" trigger reduces "Things to destroy" by 1. So when we destroy one Planetary Fortress or Orbital Command "Things to destroy" reduces by 1. "Victory" trigger checks every 5 seconds is "Things to destroy" 0 or more. If it is 0 then it does its Actions (=Player1 wins)
That's a huge wall of text... I hope this tutorial helps you to understand logic of triggers.
Really helpful tutorial!
I have a question, I just want one of the players to be defeated when one of their special unit is dead.
That depends on your Player properties. Lets say Player 1 is you. And players 2 and 3 are enemies.
Then you need to do a trigger like: [important unit] dies - End game in defeat for Player 2.
This causes player 2 to lose but players 1 and 3 still continue the game. On my both examples one thing causes one player to lose and one player to win. That's not necessary to add both.
Hope this helps.
You must login to post a comment. Don't have an account? Register to get one!