The three virtues of a programmer: Laziness, Impatience, and Hubris. – Larry Wall

Legacy:Respawn Delay Mutator

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search

By UT2004Addict

http://www.arclength.net/ut2004

Also look for me on the official Atari forums.

http://www.ataricommunity.com/forums/member.php?s=&action=getinfo&userid=225286

Anyway, I comment my scripts fairly well, you should get a good idea how this works:

//-----------------------------------------------------------
// Respawn Delay coding by UT2004Addict
// All rights reserved
// 2007
// http://www.ataricommunity.com/forums/member.php?s=&action=getinfo&userid=225286
//-----------------------------------------------------------
class RespawnDelayGameRules extends GameRules;
 
 
var float RespawnDelay;
 
 
 
function bool PreventDeath(Pawn Killed, Controller Killer, class<DamageType> damageType, vector HitLocation)
{
 
    local RespawnDelayActor RDA;
    local Controller C;
 
    if (Killed.Controller != none)
        C = Killed.Controller;
    else if (Killed.Owner.IsA('Controller'))
        C = Controller(Killed.Owner);
    else if (  Killed.Owner.IsA('Pawn')
         &&    Pawn(Killed.Owner).Controller != none  )
        C = Pawn(Killed.Owner).Controller;
 
 
    if (  C != none
    &&    !C.bVehicleTransition  )
    {
        RDA = spawn(class'RespawnDelayActor', C);
 
        if (RDA != none)
        {
            RDA.RespawnDelay = RespawnDelay;
            RDA.CheckController = C;
            RDA.CheckPawn = Killed;
        }
    }
 
 
	if ( (NextGameRules != None) && NextGameRules.PreventDeath(Killed,Killer, damageType,HitLocation) )
	{
 
    	return true;
	}
 
    return false;
}
 
 
 
 
 
defaultproperties
{
 
    RespawnDelay=10.0
 
 
}
//-----------------------------------------------------------
// Respawn Delay coding by UT2004Addict
// All rights reserved
// 2007
// http://www.ataricommunity.com/forums/member.php?s=&action=getinfo&userid=225286
//-----------------------------------------------------------
class RespawnDelayActor extends Actor;
 
 
var int TickChecks;
var bool bActivated;
 
var float RespawnDelay;
var Controller CheckController, TargetController;
var Pawn CheckPawn, TargetPawn;
var float OldControllerFrequency, OldPawnFrequency;
 
 
simulated function PostBeginPlay()
{
 
    super.PostBeginPlay();
 
    Enable('Timer');
    Enable('Tick');
 
}
 
 
simulated function Tick(float DeltaTime)
{
 
 
    // Just in case something else is going on,
    // don't check more than a few times
    if (!bActivated)
        TickChecks--;
 
    if (TickChecks <= 0)
    {
        EndDelay();
        return;
    }
 
 
    super.Tick(DeltaTime);
 
 
 
    if (  !bActivated
    &&    (   CheckPawn == none
          ||  CheckPawn.Health <= 0  )  )
    {
        StartDelay(CheckController);
 
        if (CheckPawn != none)
            SetTargetPawn(CheckPawn);
    }
 
 
}
 
 
 
 
simulated function StartDelay(Controller C)
{
 
    if (C == none)
    {
        Destroy();
        return;
    }
 
    bActivated = true;
 
    TargetController = C;
 
    if (  TargetController.Pawn != none
    &&    TargetController.Pawn.Health > 0  )
        SetTargetPawn(TargetController.Pawn);
 
 
	TargetController.bVehicleTransition = true; // to keep Bots from doing Restart()
	TargetController.Unpossess();
	TargetController.bStasis = true;
 
 
	TargetController.NetUpdateTime = Level.TimeSeconds;
	OldControllerFrequency = TargetController.NetUpdateFrequency;
	TargetController.NetUpdateFrequency = RespawnDelay;
 
 
 
	SetTimer(RespawnDelay, false);
 
 
}
 
 
 
simulated function SetTargetPawn(Pawn P)
{
    if (P == none)
        return;
 
 
    TargetPawn = P;
 
	TargetPawn.NetUpdateTime = Level.TimeSeconds;
	OldPawnFrequency = TargetPawn.NetUpdateFrequency;
	TargetPawn.NetUpdateFrequency = RespawnDelay;
 
 
}
 
 
simulated function Timer()
{
    EndDelay();
}
 
 
 
simulated function EndDelay()
{
 
    // End our delay
    if (TargetController != none)
    {
 
        TargetController.bStasis = false;
 
 
        if (  TargetPawn != none
        &&    TargetPawn.Health > 0  )
        {
            TargetController.Possess(TargetPawn);
 
            if (TargetController.IsA('PlayerController'))
            {
                PlayerController(TargetController).ClientSetViewTarget(TargetPawn);
            }
 
 
            TargetPawn.NetUpdateTime = Level.TimeSeconds;
	        TargetPawn.NetUpdateFrequency = OldPawnFrequency;
 
        }
        else
        {
 
            // Copied from Controller PawnDied
            TargetController.Pawn = None;
	        TargetController.PendingMover = None;
	        if ( TargetController.bIsPlayer )
            {
                if (  !TargetController.IsInState('GameEnded')
                &&    !TargetController.IsInState('RoundEnded') )
			        TargetController.GotoState('Dead'); // can respawn
            }
	        else
		        TargetController.Destroy();
 
 
        }
 
 
        TargetController.bVehicleTransition = false;
 
 
  	    TargetController.NetUpdateTime = Level.TimeSeconds;
	    TargetController.NetUpdateFrequency = OldControllerFrequency;
 
 
    }
 
 
    // Clear out everything
    TargetController = none;
    SetTimer(0.0, false);
    Destroy();
 
}
 
 
 
 
defaultproperties
{
 
    RespawnDelay=10.0
    TickChecks=5
    bActivated = false;
 
    LifeSpan=0.0
    bHidden=true
 
}
//-----------------------------------------------------------
// Respawn Delay coding by UT2004Addict
// All rights reserved
// 2007
// http://www.ataricommunity.com/forums/member.php?s=&action=getinfo&userid=225286
//-----------------------------------------------------------
class MutRespawnDelay extends Mutator;
 
 
var config float RespawnDelay;
 
 
 
 
static function FillPlayInfo(PlayInfo PlayInfo)
{
	Super.FillPlayInfo(PlayInfo);
 
	PlayInfo.AddSetting(default.RulesGroup, "RespawnDelay", "Respawn Delay Duration:", 0, 1, "Text", "10.0;1.0:20.0");
 
	return;
}
 
 
 
function PostBeginPlay()
{
	local GameRules G;
 
	Super.PostBeginPlay();
	G = spawn(class'RespawnDelayGameRules');
 
 
	if (G != none)
    {
        RespawnDelayGameRules(G).RespawnDelay = RespawnDelay;
    }
 
 
	if ( Level.Game.GameRulesModifiers == None )
		Level.Game.GameRulesModifiers = G;
	else
		Level.Game.GameRulesModifiers.AddGameRules(G);
 
 
}
 
 
 
 
 
 
defaultproperties
{
 
    RespawnDelay=10.0
 
    IconMaterialName="MutatorArt.nosym"
    GroupName="RespawnDelay01"
    FriendlyName="Respawn Delay"
    Description="Delay before players can respawn."
}