SpectatorOnly=1 stopping spawn! :(

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

Traktion

New Member
Nov 2, 2004
17
0
0
Hi,

I'm having a problem setting a player in spectator mode and then loading a new level. I have tried various ways of putting a player into spectator mode, but when the map changes, the countdown until the match starts gets stuck at 3 (just keeps pulsing), none of the bots join the server and the score board is empty. I've tried all sorts of work arounds, but I'm new to UnrealScript and this is driving me crazy! :( From what I can see, every time I set the player to spectator mode, SpectatorOnly=1 is added to the user.ini file. This seems to stop them being able to connect to the server.

I've tried this:

Code:
	PController = Level.GetLocalPlayerController();
	PController.PlayerReplicationInfo.bOnlySpectator = false;
	if (sess==0) {
		if (!PController.PlayerReplicationInfo.bIsSpectator) {
//			PController.BecomeSpectator();
			PController.GotoState('Spectating');
			PController.PlayerReplicationInfo.bIsSpectator = true;
		}
	}else if (sess==1) {	//only set session if successful, so retries if failed last time
		if (PController.PlayerReplicationInfo.bIsSpectator) {
//			PController.BecomeActivePlayer();
			PController.GotoState('PlayerWaiting');
			PController.PlayerReplicationInfo.bIsSpectator = false;
		}
	}

You can see, the various remarked lines I've also tried. I've also tried resetting the PlayerController and still no joy.

I'm sure it's something simple and stupid, but has anyone a solution to a) put a player in spectator mode and stop this SpectatorMode=1 being added to the user.ini file (config var) or b) know a way to disable SpectatorMode on connection?

Many thanks in advance!
 
Last edited:

Traktion

New Member
Nov 2, 2004
17
0
0
Fixed it... 1-2 days of head scratching, I post and then find it! Typical! :D

The above code was like this:

Code:
	PController = Level.GetLocalPlayerController();
	if (sess==0) {
		if (!PController.PlayerReplicationInfo.bIsSpectator) {
			PController.BecomeSpectator();
			PController.PlayerReplicationInfo.bIsSpectator = true;
		}
	}else if (sess==1) {	//only set session if successful, so retries if failed last time
		if (PController.PlayerReplicationInfo.bIsSpectator) {
			PController.BecomeActivePlayer();
			PController.PlayerReplicationInfo.bIsSpectator = false;
		}
	}

But I also ran the following every time the level changed (via an interaction event):

Code:
			PController = Level.GetLocalPlayerController();
			PController.PlayerReplicationInfo.reset();
			log ("ICFXMut->Tick() -> PController.reset()");
			PController.reset();
			PController.PlayerReplicationInfo.bOnlySpectator = false;

That seems to do the trick! Time to make some actual progress now! :)
 

Traktion

New Member
Nov 2, 2004
17
0
0
I added this SpectatorMode=1 in my user.ini and then connected to a public server and the same thing happened. It looks like if you set this value in the DefaultPlayer section, you simply can't join a match and you just get 'stuck' at the 'match commensing in 3' message.

So... it looks I *need* to change this value to 0. I can do this when I launch the game, but it changes the URL when the map reloads. I've tried modifying the login to set it to 0, but it has no affect. I've tried changing the default value ( Level.Game.PlayerControllerClass.Default.PlayerReplicationInfoClass.Default.bOnlySpectator = false;), but this has no affect either.

Could it be a problem with not having 'ready' players connected (hence, no countdown - even when I have bots)? I keep trying things, but if anyone has any clue, it'd be much appreciated.
 

Traktion

New Member
Nov 2, 2004
17
0
0
I'm starting to think it's something to do with client/server communications. My understanding of ROLE and simulated functions seems to grow by the day at the moment.
 

Traktion

New Member
Nov 2, 2004
17
0
0
I've done some more research, more playing and some recoding. I still haven't fixed the problem of not being able to connect to the server when bOnlySpectator=1 is set, but I've realised many of my problems were caused by:

a) PlayerReplicationInfo.bOnlySpectator being replicated from the server to the client (so any changes to the client version in a simulated function were essentially useless)

b) PlayerReplicationInfo.bIsSpectator is only used when the player is dead, rather than in spectating mode. Therefore, checking this variable doesn't return the expected value

I also had problems with the ROLE settings and replication and some invalid assumptions I was making. I thought I'd write this all here in case any other UnrealScript n00b has a similar problem! :)

From what I can gather (ie. from testing), replication only works for data you are transfering to your peer to be called from a *remote call*. Let me explain further with two scenarios:

Code:
replication
{
    // Things the client should send to the server.
    reliable if( Role < ROLE_Authority ) 
		sClientStatus;
}

simulated function Tick(float DeltaTime)
	if (role == ROLE_Authority) {   //only run on server
		ServerSetStatus();   //status changes need to be done at the server, then replicated	
	}
	if (role < ROLE_Authority) {	//only run on clients
		ServerSetStatus();
                sClientStatus = getSysStatus()
        }

}

//NOT simulated!
function ServerSetStatus() {
        log("ServerSetStatus()");
	if (sClientStatus == "ok") {
		//do nothing!
	}else {
		//take actions!
	}
}

//function getSysStaus() {
     //changes sClientStatus
}

In this scenario, when ServerSetStatus is ran when ROLE = ROLE_Authority, sClientStatus *never* changes, despite the code being flagged replication. BUT, if you run the code when ROLE < ROLE_Authority, then the data is replicated for the *remote* call to ServerSetStatus().

At least, this is what I *think* is happening! lol! I don't entirely know why I decided to code my click routine in a way that this was happening, but as a UnrealScript beginner, I've been learning different bits at different times and this is how it fell together. After many hours of head scratching, I realised what was going on. What I found *really* confusing was that the remote call doesn't seem to send my 'log' results anywhere. It doesn't appear on the client or the server, but just happens. Like I said, I need to do more testing, but there is definitely something weird going on in there!
 

Traktion

New Member
Nov 2, 2004
17
0
0
Probably the final reply to myself... LOL!

I think I need to use ModifyLogin to change the SpectatorOnly=1 to SpectatorOnly=0. Is it ok to replace the Options string even though it is declared as an 'out' type?
 

Traktion

New Member
Nov 2, 2004
17
0
0
Sorted it... called each tick. If the match has not started and there are players in SpectatorOnly and they are spectating, then start the match. I still need to alter the defaul camera to behind a bot, but at least the match is starting now! The question is, why isn't this implemented by default?! Anyway, here's the code:

Code:
function ResetServer() {
    local PlayerController PController;
	local array<PlayerController> PControllerArray;

	if (!Level.Game.GameReplicationInfo.bMatchHasBegun) {
		Level.Game.GetPlayerControllerList(PControllerArray);
		ForEach AllActors(class'PlayerController', PController) {
			if (PController.PlayerReplicationInfo.bOnlySpectator && PController.PlayerReplicationInfo.bIsSpectator) {
				Level.Game.StartMatch();
                                PController.BecomeSpectator(); //goto 3rd person view
			}
		}
	}
}
 
Last edited: