Victory Rules
The framework ends a match in one case: when a player is defeated and everyone left is on one team. Every other way to win or lose is a rule you write. A rule is a passive ability. It runs every tick, looks at the simulation, and calls Defeat Player or End Match when its condition is met.
Goal. Add three rules:
- A player is defeated when they lose their Headquarters.
- A player wins by holding 5,000 Minerals.
- The match is a draw after ten minutes.
The first two go on the Player State, because each is about one player. The third goes on the Game State, because it is about the match. Match Flow explains the two classes.
Before you start. Complete Add Victory, Defeat and an AI or have equivalents: a Player State Blueprint PS_Demo and a Game Mode that uses it, a headquarters entity SU_Headquarters, a Sein Player Start for each slot with Spawn Entity set to SU_Headquarters, and a Minerals resource. Naming the headquarters SU_Headquarters gives it the tag SeinARTS.Unit.Headquarters.
1. Defeat when the Headquarters is lost
Section titled “1. Defeat when the Headquarters is lost”Create an ability SA_HeadquartersRule, SeinARTS > SeinARTS Ability, Generic Ability:
| Setting | Value |
|---|---|
| Ability Name | Headquarters Rule |
| Is Passive | On |
| Target Type | None |
Passive is the setting that matters. A passive ability starts when it is granted and ticks for the rest of the match, and it needs no command. An ability that is not passive sits idle until something orders it.
Add variables, both Fixed Point:
| Variable | Default | Notes |
|---|---|---|
CheckEvery |
1 |
Seconds between checks. Instance Editable. |
TimeUntilCheck |
0 |
Counts down |
Add a Boolean Found. In On Tick:
- Subtract Delta Time from
TimeUntilCheck. If the result is above zero, stop. Checking every tick would walk every entity 30 times a second for nothing. - Add
CheckEverytoTimeUntilCheck. SetFoundto false. - Get Entity Owner of Owner Entity. On a Player State ability, the owner entity is the player’s own entity, so this is the player.
- Get Player Entities for that player with Skip Abstract Entities on. For Each Loop: if Has Tag
SeinARTS.Unit.Headquarterson the entity, setFoundto true. - On Completed, Branch on
Found. On false, call Defeat Player with that player and ReasonSeinARTS.Defeat.HeadquartersLost(add the tag when prompted), then End Ability.
Reason is your own tag. It travels with the result so the defeat screen can say why.
The Neutral player has a player entity built from the same Player State, so the rule runs for it too. It finds no Headquarters and calls Defeat Player, which ignores Neutral and logs a warning.
Open PS_Demo, select its Sein Abilities component and add SA_HeadquartersRule to Granted Abilities. If it has no Sein Abilities component, add one.
A defeated player’s entities are destroyed, and the match ends once the players still playing share one team. Both come from Match Flow; the rule does not repeat them.
2. Win by stockpile
Section titled “2. Win by stockpile”Add the victory to the same ability. Add a Fixed Point variable GoalAmount, default 5000, Instance Editable. On the true branch of the same Branch:
- Get Resource for the player, Resource Tag
SeinARTS.Resource.Minerals. - If it is at or above
GoalAmount, call End Match. Build Winners with Make Array holding just the player. ReasonSeinARTS.Victory.Stockpile. Then End Ability.
End Match makes the listed players victorious and defeats everyone else still playing. Leave Winners empty and every player still playing draws.
The two outcomes of this ability are independent. A player who loses the Headquarters is defeated, and a player who reaches the goal wins.
3. A time limit on the Game State
Section titled “3. A time limit on the Game State”Create a Blueprint GS_Demo with parent Sein Game State. In its Components panel, add a Sein Abilities component. In the Game Mode, set Game State Class to GS_Demo.
Create an ability SA_TimeLimit: Ability Name Time Limit, Is Passive on, Target Type None. Add two Fixed Point variables, LimitSeconds (default 600, Instance Editable) and Elapsed (0).
On Tick: add Delta Time to Elapsed. When Elapsed is at or above LimitSeconds, call End Match with no Winners and Reason SeinARTS.Victory.TimeLimit, then End Ability.
Add SA_TimeLimit to the Game State’s Sein Abilities, Granted Abilities.
A time limit is simulation time, counted from the ticks the ability sees, so every machine reaches it on the same tick. Do not use a timer or Delay. If you want the limit to come from the lobby’s rules, the Time Limit field of Sein Basic Match Settings holds minutes, and your ability can read it with Get Match Extensions. The framework does not read that field itself.
4. Show the result
Section titled “4. Show the result”The result reaches presentation on the Player Controller. On Defeated (Reason) fires for a defeated player while the match goes on. On Match Ended (Result, Reason) fires for everyone when it ends, with Victory, Defeat or Draw. Add Victory, Defeat and an AI shows both on a banner. The Game Mode’s On Match Ended then waits Post Match Seconds and returns to the lobby.
5. Test
Section titled “5. Test”Make the rules fast to trigger, one at a time, by changing class defaults on the ability. Keep CheckEvery at 1.
- Time limit. Set
LimitSecondsto20, leaving the other values. Play and wait. After 20 seconds the match ends, each player’s result is Draw, and the banner shows it. - Stockpile. Put
LimitSecondsback to600and setGoalAmountto600. Play, and mine until Minerals reach 600. The match ends with Victory for you and Defeat for the AI, and the reason isSeinARTS.Victory.Stockpile. - Headquarters. Put
GoalAmountback to5000. Destroy the AI’s Headquarters. Within a second the AI is defeated and its units are destroyed. With two players, the match ends, and you win with the reasonSeinARTS.Match.End.OneTeamRemains. - A third player. Add a third start. Defeat one player and the match continues; the team rule needs one team left.
Put the original values back when you are done.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Likely cause |
|---|---|
| A player is defeated on the first check | They have no Headquarters. Check the start’s Spawn Entity, and that the tag on the headquarters is the one the rule tests. |
| The rule never fires | The ability is not granted on the Player State or Game State actually selected in the Game Mode, or Is Passive is off |
| A Game State rule does nothing | The Game State Class is still the default. Select your Blueprint. |
| The match does not end after a defeat | Three or more free-for-all players remain, a teammate remains, or End When One Team Remains is off in the match rules |
| Both players are defeated and nobody wins | Both lost their Headquarters in the same tick. Nobody is left playing. If two End Match calls land in one tick, the first decides. |
| The defeated player’s units stay | Destroy Entities On Defeat is off in the match rules |
| The defeat screen does not show | Show it from the Player Controller’s On Defeated. The Game Mode has no such event. |
| The reason tag is not found | Add the tag in the picker when prompted |
Related
Section titled “Related”- Match Flow: defeat, victory, teams and the end-of-match events.
- Abilities: passives and their lifecycle.
- Gameplay Tags
- Add Victory, Defeat and an AI
- SeinARTS Match Library, Sein Game State and Sein Player State