rott/kf_sources/ScrnStoryGame/Classes/ACTION_IfPlayerCount.uc
2026-07-14 20:27:09 +07:00

69 lines
1.7 KiB
Ucode

/*
--------------------------------------------------------------
ACTION_IfPlayerCount
--------------------------------------------------------------
Checks if player count is between MinPlayers and MaxPlayers (inclusive).
If not - goes to section end.
Setting MaxPlayers=0 (default) disables MaxPlayers restriction and only checks MinPlayers.
Set bCountOnlyAlive=True to exclude dead players
Author : PooSH
--------------------------------------------------------------
*/
class ACTION_IfPlayerCount extends ScriptedAction;
var(Action) int MinPlayers, MaxPlayers;
var(Action) bool bCountOnlyAlive; // all players should be counted or only alive?
//returns adjusted NumToSpawn to difficulty and number of players
function int GetPlayerCount(LevelInfo Level)
{
local int LivingCount;
local Controller C;
if ( !bCountOnlyAlive )
return Level.Game.NumPlayers;
for ( C=Level.ControllerList; C!=None; C=C.NextController ) {
if (C.PlayerReplicationInfo != None && C.bIsPlayer
&& !C.PlayerReplicationInfo.bOutOfLives && !C.PlayerReplicationInfo.bOnlySpectator )
LivingCount++;
}
return LivingCount;
}
function ProceedToNextAction(ScriptedController C)
{
local int PlayerCount;
C.ActionNum += 1;
PlayerCount = GetPlayerCount(C.Level);
if ( PlayerCount < MinPlayers || (MaxPlayers != 0 && PlayerCount > MaxPlayers) )
ProceedToSectionEnd(C);
}
function bool StartsSection()
{
return true;
}
function string GetActionString()
{
if ( MaxPlayers == 0 )
return ActionString $ " > " $ MinPlayers;
return ActionString $ " ["$MinPlayers$".."$MaxPlayers$"]";
}
defaultproperties
{
ActionString="If player count"
}