Auto start matches without human players

Discussions about Servers
User avatar
UT Sniper (SJA94)
Masterful
Posts: 716
Joined: Thu Jun 24, 2010 10:35 pm
Personal rank: noob programmer
Location: England

Auto start matches without human players

Post by UT Sniper (SJA94) » Wed Feb 23, 2022 9:59 pm

Is there a way to have a server always start matches even if there are no human players on the server?

I was looking through uscript code to try and find how to start a match, but couldn't find what I was looking for(being stupid) or not applying it correctly in a mutator.

The_Cowboy
Experienced
Posts: 99
Joined: Mon Jan 24, 2011 3:22 am
Personal rank: Codezilla

Re: Auto start matches without human players

Post by The_Cowboy » Wed Feb 23, 2022 11:49 pm

You may hafta write a new gamemode class for that purpose. Since I have UT2k4 code in front of me, I see (file DeathMatch.uc)

Code: Select all

auto State PendingMatch
{
	
    ... Some functions
    
    function Timer()
    {
        local Controller P;
        local bool bReady;

        Global.Timer();

        // first check if there are enough net players, and enough time has elapsed to give people
        // a chance to join
        if ( NumPlayers == 0 )
			bWaitForNetPlayers = true;
	
	// Now this part is hardcoded and nothing can be done here.
    }

  ... Some more related functions

}   
In your new gamemode class get rid of this line. And you are good to go!

User avatar
UT Sniper (SJA94)
Masterful
Posts: 716
Joined: Thu Jun 24, 2010 10:35 pm
Personal rank: noob programmer
Location: England

Re: Auto start matches without human players

Post by UT Sniper (SJA94) » Thu Feb 24, 2022 1:57 am

Pretty crude but does what I required, just wanted matches to happen on my server without me having to have a player joined to it to collect match logs for node utstats.

Code: Select all

//=============================================================================
// Potatoes.
//=============================================================================
class Potatoes expands DeathMatchPlus;

function Timer()
{

	Super.Timer();
	
	bRequireReady = false;
	
	StartMatch();
	
	if(needPlayers()){
		AddBot();
	}
	
	if ( bGameEnded )
		{
			if ( Level.TimeSeconds > EndTime + RestartWait )
				RestartGame();
		}
	else if ( !bOverTime && (TimeLimit > 0) )
	{
		GameReplicationInfo.bStopCountDown = false;
		RemainingTime--;
		GameReplicationInfo.RemainingTime = RemainingTime;
		if ( RemainingTime % 60 == 0 )
			GameReplicationInfo.RemainingMinute = RemainingTime;
		if ( RemainingTime <= 0 )
			EndGame("timelimit");
	}
	else
	{
		ElapsedTime++;
		GameReplicationInfo.ElapsedTime = ElapsedTime;
	}
}


defaultproperties
{
	GameName="Potatoes"
	NetWait=0
    	RestartWait=0
	bNetReady=True
	bStartMatch=True
	bRequireReady=False
	MutatorClass=Class'Botpack.DMMutator'
	DefaultWeapon=Class'BotPack.ImpactHammer'
}



Buggie
Godlike
Posts: 1483
Joined: Sat Mar 21, 2020 5:32 am

Re: Auto start matches without human players

Post by Buggie » Thu Feb 24, 2022 3:24 am

Look like this can be done outside from gameInfo code. For example via mutator with Timer.

The_Cowboy
Experienced
Posts: 99
Joined: Mon Jan 24, 2011 3:22 am
Personal rank: Codezilla

Re: Auto start matches without human players

Post by The_Cowboy » Thu Feb 24, 2022 4:01 am

O yeah Buggie, my friend, enlighten us, why would you want to do that instead of graceful leverage of new game type's complete control!

User avatar
sektor2111
Godlike
Posts: 5871
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Auto start matches without human players

Post by sektor2111 » Thu Feb 24, 2022 7:41 pm

I've done something a few time ago for starting matches and quickly ending them in purpose to deliver server-travel at MapVote for loading mutators normally in multi-servers. Section for starting goes like this:

Code: Select all

		if ( bStartGames )
		{
			if ( DeathMatchPlus(Level.Game) != None )
			{
				DeathMatchPlus(Level.Game).NetWait=0;
				DeathMatchPlus(Level.Game).RestartWait=0;
				DeathMatchPlus(Level.Game).bRequireReady=False;
				DeathMatchPlus(Level.Game).bNetReady=False;
				DeathMatchPlus(Level.Game).StartMatch();
			}
		}

User avatar
UT Sniper (SJA94)
Masterful
Posts: 716
Joined: Thu Jun 24, 2010 10:35 pm
Personal rank: noob programmer
Location: England

Re: Auto start matches without human players

Post by UT Sniper (SJA94) » Thu Feb 24, 2022 8:04 pm

I put what sektor said, and created a Server Actor and called it in PreBeginPlay(). I did something similar before I did the custom gametype, but missed a few of the values and couldn't get it to work.

Thanks, much less faffing about compared to making custom gametypes.

Code: Select all

//=============================================================================
// AutoStartActor.
//=============================================================================
class AutoStartActor expands Actor;

function PreBeginPlay(){

	if ( DeathMatchPlus(Level.Game) != None ){
	
		DeathMatchPlus(Level.Game).NetWait=0;
		DeathMatchPlus(Level.Game).RestartWait=0;
		DeathMatchPlus(Level.Game).bRequireReady=False;
		DeathMatchPlus(Level.Game).bNetReady=False;
		DeathMatchPlus(Level.Game).StartMatch();
	}
}