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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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