Win/Loss Conditions

DonMushroom

Member
Reaction score
4
Hi :)

I'm trying to set up victory conditions and cant seem to get them to work :(

I'm looking for the game to end for the player when they run our of units and the last unit standing wins the game.

Any help would be greatly appreciated :)
 

Siretu

Starcraft 2 Editor Moderator
Reaction score
293
First of all, welcome to Thehelper!

Since I don't know entirely how your map works, I'll give you a general trigger that you might want to modify to fit your needs. I also don't know how good you are with triggers, so I'll try to explain quite thoroughly but if something is unclear, feel free to ask and I'll clarify.

Okay, first of all you'll need a variable of the "Player Group" type (let's call it "In-game players"). We're going to use it to save all players that are still in the game. (If you don't know what a variable is, check out these links: 1 and 2)

This means that when the map starts, you want to make sure "In-game players" is filled with all the players that are currently playing the game. One way to do this is to just set it to "Active Players". This is a function that returns all the active players. However, if I remember correctly, that function also returns computer players. If you have computer players in your game, you'll have to remove them manually or do it another way. Another simpler way would be to add them all manually. Have a trigger with the "Map initialization" event and actions like: "Add player X to In-game".

Here's the trigger:
Trigger:
  • Victory Condition
    • Events
      • Unit - Any Unit dies
    • Local Variables
    • Conditions
      • (Number of Living units in (Any units in (Entire map) owned by player (Triggering player) matching Excluded: Missile, Dead, Hidden, with at most Any Amount)) == 0
    • Actions
      • Player Group - Remove player (Triggering player) from In-game players
      • Game - End game in Defeat for player (Triggering player) (Show dialogs, Show score screen)
      • General - If (Conditions) then do (Actions) else do (Actions)
        • If
          • (Number of players in In-game players) == 1
        • Then
          • Game - End game in Victory for player (Player 1 from In-game players) (Show dialogs, Show score screen)
        • Else


Depending on your previous experience with the trigger editor, this might look scary. Don't worry though, it's all quite simple when you understand the basics.

The trigger runs when a unit dies. When a unit dies, it checks how many units that player has left and it only runs the trigger if the player only has 0 units left(that's what the condition is for).

So, if the player has 0 units left, it runs all the actions. This means it'll remove the player from the "In-game players" variable, since the player is no longer playing. Using the "End game for player" action, we end the game in defeat for this player since he lots all his units.

Finally, we have an "If then else". This checks if there's only one player left playing. If that is the case, he's won so we end the game in victory for him.

Now, if you only want to count units in a certain area, you could change "(Entire map)" in the condition to the actual region you're using.
 

Jokker

Member
Reaction score
16
This works with more than one players.
The if condition in the end only checks the last man standing. So you don't need to change a thing.
 

DonMushroom

Member
Reaction score
4
Hi again :)

I was wondering how i could modify this to work with lobby teams. The map has custom teams so it could range from 1v1 to 7v1 to 8v8 and it only seem to work for free for all at the mo.
Any info would be great. :D

I need it like a normal melee game really
 

DonMushroom

Member
Reaction score
4
So does anyone know how i would go about editing this trigger? :)

At the moment it works for Free for all. I need it to work for ffa, 2v2, 3v3, 4v4 and custom teams.

So how would i change the win conditions to be if no units are left alive on the other teams the team remaining wins. :)
 

DonMushroom

Member
Reaction score
4
Ok this is what i have ended up with...

Events
Unit - Any Unit dies
Local Variables
Conditions
(Number of Living units in (Any units in (Entire map) owned by player (Owner of (Triggering unit)) matching Excluded: Structure, Missile, Dead, Hidden, with at most Any Amount)) == 0
(Number of Living units in (Any units in (Entire map) owned by player (Number of players in (Allies of player (Triggering player))) matching Excluded: Structure, Missile, Dead, Hidden, with at most Any Amount)) == 0
Actions
Game - End game in Defeat for player (Triggering player) (Show dialogs, Show score screen)
Game - End game in Defeat for player (Number of players in (Allies of player (Triggering player))) (Show dialogs, Show score screen)

I was going for if you and your allies have no units its game over. Where am i going wrong? :(
 

Kyuft

Member
Reaction score
11
Ok this is what i have ended up with...

(Number of Living units in (Any units in (Entire map) owned by player (Number of players in (Allies of player (Triggering player))) matching Excluded: Structure, Missile, Dead, Hidden, with at most Any Amount)) == 0

I think I might know the problem. the field that is underlined is looking for a number or Triggering player/ killing player. So, instead of taking the players that are allies of the triggering player, it is inputting the number of allies he has. For example, if he has 4 allies, it will say "player 4".

-Kyuft:shades:
 

Siretu

Starcraft 2 Editor Moderator
Reaction score
293
Look through your second condition. "Owned by player (Number of players in (Allies of player (Triggering player)))".

Number of players in Player Group is a function that returns an integer, the number of players in that player group. The player group in this case is all the allies of (Triggering Player). So let's assume player 5 and 6 are allies of the triggering player. You would then have a player group with player 5 and 6. How many players are in that group? Two!(5 and 6).

This means that the Numer of players in Player Group will return 2. So in that example, what you actually got is (Number of Living units in (Any units in (Entire map) owned by player 2 matching Excluded: Structure, Missile, Dead, Hidden, with at most Any Amount)) == 0

In other words, you're checking if player 2 has 0 units left, when in fact you were only interested in the triggering player, player 5 and player 6.

So how do you do it? Well, using the "Pick every player in Player group" action, you can loop through all the allies of a player. Here's an example trigger that uses this:
Trigger:
  • Loss
    • Events
      • Unit - Any Unit dies
    • Local Variables
      • units = 0 <Integer>
    • Conditions
      • (Number of Living units in (Any units in (Entire map) owned by player (Triggering player) matching Excluded: Missile, Dead, Hidden, with at most Any Amount)) == 0
    • Actions
      • Player Group - Pick each player in (Allies of player (Triggering player)) and do (Actions)
        • Actions
          • Variable - Set units = (units + (Number of Living units in (Any units in (Entire map) owned by player (Picked player) matching Excluded: Missile, Dead, Hidden, with at most Any Amount)))
      • General - If (Conditions) then do (Actions) else do (Actions)
        • If
          • units == 0
        • Then
          • Player Group - Pick each player in (Allies of player (Triggering player)) and do (Actions)
            • Actions
              • Game - End game in Defeat for player (Picked player) (Show dialogs, Show score screen)
          • Game - End game in Defeat for player (Triggering player) (Show dialogs, Show score screen)
        • Else


Now what does this trigger do? If a unit dies, and it's the last unit the player has, go through all his allies and add the number of units everyone has to the units variable. If the units variable is 0, no one on his team has any units, so we go through them all and end the game for them.

There is however an easier way to do this that I thought of while doing the trigger for you. Here it is:
Trigger:
  • Loss
    • Events
      • Unit - Any Unit dies
    • Local Variables
      • units = 0 <Integer>
    • Conditions
      • (Number of Living units in (Units in (Entire map) having alliance Ally with player (Triggering player) matching Excluded: Missile, Dead, Hidden, with at most Any Amount)) == 0
    • Actions
      • Player Group - Pick each player in (Allies of player (Triggering player)) and do (Actions)
        • Actions
          • Game - End game in Defeat for player (Picked player) (Show dialogs, Show score screen)
      • Game - End game in Defeat for player (Triggering player) (Show dialogs, Show score screen)


It is very similar. It ends the game in the same way and it has the same event. The condition, however, is different. It uses a function called "Units in Region with Alliance To Player". This includes the player himself so you don't have to have two different conditions.
 

Kyuft

Member
Reaction score
11
That is exactly what I meant to say, but I guess I wasn't clear enough.

-Kyuft:shades:
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top