• Please make sure you are familiar with the forum rules. You can find them here: https://forums.tripwireinteractive.com/index.php?threads/forum-rules.2334636/

Code [Help] SetViewTraget

TracingActors is basically same as Trace (performance wise).
Trace creates a list of trace hit actors and returns the first hit, tracing actor iterates through the hit list.

Just tested and the code still doesn't work

Code:
	function PossessZed()
	{
		local Pawn M;
		local vector HL,HN;
		local bool bWasSpec;

		if( NextPossessTimer>Level.TimeSeconds )
			return;
		NextPossessTimer = Level.TimeSeconds+0.4f;

		foreach TraceActors(Class'Pawn',M,HL,HN,Location+vector(Rotation)*1000.f,Location)
		{
			if( M!=None && M.Health>0 )
			{
				if( Monster(M)!=None )
					VSGame(Level.Game).PlayerPossess(Self,Monster(M));
				else if( KFPawn(M)!=None )
				{
					bWasSpec = !bBehindView && ViewTarget != Pawn && ViewTarget != self;
					
					SetViewTarget(M);
					ClientSetViewTarget(M);
					if ( ViewTarget == self || bWasSpec )
						bBehindView = false;
					else
						bBehindView = true;
					ClientSetBehindView(bBehindView);
				}
				return;
			}
		}
		ClientMessage("Can't possess: You must aim at the specimen to possess.");
	}

	exec function Fire( optional float F )
	{
		if( NextPossessTimer<Level.TimeSeconds )
		{
			PossessZed();
			NextPossessTimer = Level.TimeSeconds+0.5f;
		}
	}
 
Last edited:
Upvote 0
Code doesn't work because you are executing the code on client side, but it is supposed to be executed on the server.

My version is executing PossessZed() on client side and then passes actor player want to spectate to server.
Marco suggests replicating ServerPossessZed() call to the server, i.e. there should be this code included:
Code:
replication {
reliable if (Role < ROLE_Authority)
  ServerPossessZed;
}
 
Upvote 0
Code doesn't work because you are executing the code on client side, but it is supposed to be executed on the server.

My version is executing PossessZed() on client side and then passes actor player want to spectate to server.
Marco suggests replicating ServerPossessZed() call to the server, i.e. there should be this code included:
Code:
replication {
reliable if (Role < ROLE_Authority)
  ServerPossessZed;
}

PossessZed is already replicated to the server

Code:
replication
{
    reliable if( Role < ROLE_Authority )
        PossessZed;
    reliable if( Role==ROLE_Authority )
        ClientDeathMessage;
}
 
Last edited:
Upvote 0
This is what I have so far and it still doesn't work, all the logs are called fine as refrenced from this

Code:
P (Pawn) was KF-WestLondon.KFHumanPawn
I tried to set my ViewTarget

Code:
replication
{
    reliable if( Role < ROLE_Authority )
        PossessZed;
    reliable if( Role==ROLE_Authority )
        ClientDeathMessage;
}

state Spectating
{
    function BeginState()
    {
        Super.BeginState();
        if( VSGame(Level.Game)!=None && VSGame(Level.Game).ShouldGoHunt() && !PlayerReplicationInfo.bOnlySpectator )
            GoToState('PreySpec');
    }
}

state PreySpec extends BaseSpectating
{
ignores SwitchWeapon, RestartLevel, ClientRestart, Suicide, ThrowWeapon, NotifyPhysicsVolumeChange, NotifyHeadVolumeChange;
    
    function PossessZed()
    {
        local Pawn P;
        local vector HL,HN;
        local bool bWasSpec;

        if( NextPossessTimer>Level.TimeSeconds )
            return;
        NextPossessTimer = Level.TimeSeconds+0.4f;

        foreach TraceActors(Class'Pawn',P,HL,HN,Location+vector(Rotation)*1000.f,Location)
        {
            log("P (Pawn) was"@P);
            if( P!=None && P.Health>0 )
            {
                if( Monster(P)!=None )
                    VSGame(Level.Game).PlayerPossess(Self,Monster(P));
                else if( KFHumanPawn(P)!=None )
                {
                    log("I tried to set my ViewTarget");
                    bWasSpec = !bBehindView && ViewTarget != Pawn && ViewTarget != self;
                    SetViewTarget(KFHumanPawn(P));
                    ViewTargetChanged();
                    ClientSetViewTarget(KFHumanPawn(P));
                    if ( ViewTarget == self || bWasSpec )
                        bBehindView = false;
                    else
                        bBehindView = true; //bChaseCam;
                    ClientSetBehindView(bBehindView);  
                }
            }
            return;
        }
        ClientMessage("Can't possess: You must aim at the specimen to possess.");
    }

    exec function Fire( optional float F )
    {
        if( NextPossessTimer<Level.TimeSeconds )
        {
            PossessZed();
            NextPossessTimer = Level.TimeSeconds+0.5f;
        }
    }
    
    exec function AltFire( optional float F )
    {
        if( ViewTarget != self )
            ServerViewSelf();
    }

    function Timer()
    {
        bFrozen = false;
    }

    function BeginState()
    {
        if ( Pawn != None )
        {
            SetLocation(Pawn.Location);
            UnPossess();
        }
        bCollideWorld = true;
        CameraDist = Default.CameraDist;
    }

    function EndState()
    {
        PlayerReplicationInfo.bIsSpectator = false;
        bCollideWorld = false;
    }
    
    function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
    {
        bBehindView = false;
        if( ViewTarget!=Self )
            SetViewTarget(Self);
        Acceleration = NewAccel;
        MoveSmooth(SpectateSpeed * Normal(Acceleration) * DeltaTime);
    }
}
 
Last edited:
Upvote 0