SetEndCams for Spectators

Discussions about Coding and Scripting
User avatar
Barbie
Godlike
Posts: 2536
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

SetEndCams for Spectators

Post by Barbie »

Does anyone have an idea why setting EndCams for Spectators does not work with this code? Spectators are frozen but keep their view.

Code: Select all

function bool SetEndCams(string Reason) {
local pawn P, BestPawn; // *BestPawn* can also be a Bot; shared parent of (Bot, TournamentPlayer) is *Pawn*
local Actor EndViewTarget;
local bool bGoodEnd, bShutDownMusic;
local Actor A;

	bGoodEnd = True;
	bShutDownMusic = false;

	// find individual winner
	for (P = Level.PawnList; P != None; P = P.nextPawn)
	{
		// remove velocity and freeze player:
		P.Velocity = vect(0,0,0);
		P.Acceleration = vect(0,0,0);
		P.SetPhysics(PHYS_None);
		P.SetLocation(P.Location);

		if (P.bIsPlayer && ((BestPawn == None) || (class'SharedCode'.static.RankComparePawns(P, BestPawn) > 0 )))
			BestPawn = P;
	}

	if (Reason == "No Hunters")
	{
		bGoodEnd = False;
		GameEndedMessage = "Hunting party eliminated!";
	}

	if ((RemainingTime == 0) && (TimeLimit >= 1))
	{
		bGoodEnd = False;
		GameReplicationInfo.GameEndedComments = TimeOutMessage;
	}
	else
		GameReplicationInfo.GameEndedComments = GameEndedMessage;

	EndTime = Level.TimeSeconds + 3.0;

	if (EndCam != None)
	{
		EndViewTarget = EndCam;
		bEndCamDancers = false;
	}
	else
	{
		EndViewTarget = BestPawn;
		// Shut down music if dancers are shown:
		bShutDownMusic = bShutDownMusic || (bEndCamDancers && GameReplicationInfoSB(GameReplicationInfo).MonsterCount <= 0);
	}

	for (P = Level.PawnList; P != None; P = P.nextPawn )
	{
		if (PlayerPawn(P) != None )
		{
			if ( ! bTutorialGame)
				PlayWinMessage(PlayerPawn(P), bGoodEnd);
			if (P == EndViewTarget)
				PlayerPawn(P).ViewTarget = None;
			else
				PlayerPawn(P).ViewTarget = EndViewTarget;
			PlayerPawn(P).bBehindView = bEndCamBehindView;
			PlayerPawn(P).bFixedCamera = bEndCamFixedCamera;
			if (bShutDownMusic)
				PlayerPawn(P).ClientSetMusic(Music'null48.null48', 0, 255, MTRAN_Fade);

			//P.ClientGameEnded(); // Pawn.ClientGameEnded sends itself to state 'GameEnded'
		}
		P.GotoState('GameEnded');
	}
	if (bEndCamDancers && (DancersClass != "") && GameReplicationInfoSB(GameReplicationInfo).MonsterCount <= 0)
		if (spawn(Class<Actor>(DynamicLoadObject(DancersClass, class'Class')), , , BestPawn.Location) == None)
			Warn("function SetEndCams: could not spawn SBDancers-class '" $ DancersClass $ "'");

	// clean up the end game screen, removes leftover monsters
	foreach AllActors(class'Actor', A)
		if (ThingFactory(A) != None && A.IsInState('Spawning'))
			A.GotoState('Finished');
		else if (ScriptedPawn(A) != None)
			A.Destroy();

	CalcEndStats();
	logger(LOG_Debug, "SetEndCams", "leaving function");
	return true;
}
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
Buggie
Godlike
Posts: 1921
Joined: Sat Mar 21, 2020 5:32 am

Re: SetEndCams for Spectators

Post by Buggie »

This code fine. Except one below:

Code: Select all

	// find individual winner
	for (P = Level.PawnList; P != None; P = P.nextPawn)
	{
		// remove velocity and freeze player:
		P.Velocity = vect(0,0,0);
		P.Acceleration = vect(0,0,0);
		P.SetPhysics(PHYS_None);
		P.SetLocation(P.Location);

		if (P.bIsPlayer && ((BestPawn == None) || (class'SharedCode'.static.RankComparePawns(P, BestPawn) > 0 )))
			BestPawn = P;
	}
There can win spectator if all players with 0 score.

Anyway this not related to your problem.

Local test show your code work fine. Then problem come from other side. I suspect Nexgen.

Automatically merged

NexgenPlus100N.u

Code: Select all

/***************************************************************************************************
 *
 *  $DESCRIPTION  Fixes the bug in UT that cases the server to crash when a spectator does a
 *                viewPlayerNum(-1) call when the game is ended.
 *
 **************************************************************************************************/
function fixSpecatorViewPlayerNumBug() {
	local Pawn p;
	
	for (p = level.pawnList; p != none; p = p.nextPawn) {
		if (p.isA('CHSpectator')) {
			CHSpectator(p).viewTarget = none;
		}
	}
}
Buggie
Godlike
Posts: 1921
Joined: Sat Mar 21, 2020 5:32 am

Re: SetEndCams for Spectators

Post by Buggie »

Barbie wrote: Tue Aug 31, 2021 12:08 am Does anyone have an idea why setting EndCams for Spectators does not work with this code? Spectators are frozen but keep their view.
As workaround: SetLocation for spectator, instead of set TargetView. But little bit offset from desired actor for emulate behindview.