Player online check.....

Discussions about Coding and Scripting
Post Reply
MrLoathsome
Inhuman
Posts: 958
Joined: Wed Mar 31, 2010 9:02 pm
Personal rank: I am quite rank.
Location: MrLoathsome fell out of the world!

Player online check.....

Post by MrLoathsome »

Need/want my mutator to go to "sleep" if there are no players on the server.

Currently I am using this bit of code for that:

Code: Select all

function bool PlayerOn()
{
	local pawn P;

	for ( P=Level.PawnList; P!=None; P=P.nextPawn )
		if (PlayerPawn(P) != None) return true;
	return false;
}

Is there a faster way to accomplish this goal? Function is not called in Tick or anything stupid like that, but it is
called in a Timer function, and would like to make it as optimal as possible. (Performance-wise)

*Edit:
Is there a way to rewrite that function so it traverses the PawnList backwards?
Occurs to me that any player pawns would be at or near the end of the list.
Could bypass all the default pawns in the map/game with this check if the list could
be processed backwards. (I think..... :ironic2: )
blarg
User avatar
Barbie
Godlike
Posts: 2802
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Player online check.....

Post by Barbie »

The best place to check this would be the event "Logout", but it is only available in GameInfo but not in Mutator class.

Using Level.GameInfo.NumPlayers is not an option?

Code: Select all

function bool PlayerOn() {
   return Level.GameInfo.NumPlayers > 0;
}
This one line accessing a variable does not make stress in a Timer() function.
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
MrLoathsome
Inhuman
Posts: 958
Joined: Wed Mar 31, 2010 9:02 pm
Personal rank: I am quite rank.
Location: MrLoathsome fell out of the world!

Re: Player online check.....

Post by MrLoathsome »

DERP! :ironic:

Thanks Barbie.

I knew there was a better way, but my brain was just drawing a blank. :what:

Note: This compiles better:

Code: Select all

function bool PlayerOn()
{
	local pawn P;

	return Level.Game.NumPlayers > 0;
}
blarg
User avatar
sektor2111
Godlike
Posts: 6410
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Player online check.....

Post by sektor2111 »

As I recall in a nearby post you said that we want to work with Bots not against them. This NumPlayers it's addressing PlayerPawn. Bot has another formula called NumBots if memory doesn't cheat me and was implemented in a later stuff also called DeathMatchPlus. So I'm guessing:

Code: Select all

if (DeathMatchPlus(Level.game) != None)
return (DeathMatchPlus(Level.Game).NumPlayers + DeathMatchPlus(Level.Game).NumBots) > 0;
return false;
In hoping to not mess with Botz or other "players".
Higor
Godlike
Posts: 1866
Joined: Sun Mar 04, 2012 6:47 pm

Re: Player online check.....

Post by Higor »

Just scan for bIsPlayer PlayerReplicationInfo actors.
The game's GameReplicationInfo actor will scan them for you every 2 seconds, just loop those 32 slots.
Post Reply