Cogito, ergo sum

Legacy:VitalOverdose/DamageCounter

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search
UT2004 :: Actor >> Trigger >>DamageCounter(Package: custom)

by VitalOverdose

Overview[edit]

//-----------------------------------------------------------
//      FxDamageCounter a Counter thats Triggered by Damage
//      can Trigger SoundFx,EmitterFx and an event on rEaching The Damage threshold
//-----------------------------------------------------------
 
class DamageCounter Extends Triggers
Placeable;
 
var (TheCount) float                           ResetDelay;
Var (TheCount) Bool                            bCarryDamage;
Var (TheCount) int                             TargetNum;
Var (TheCount) float                           DamThresh;
Var (TheCount) float                           CounterResetDelay;
 
var (AmbiantFx) Array< Class< Emitter > >      AmbiantFxPool;
var (AmbiantFx) bool                           bTransferMomentumToFxWhenShot;
 
Var (CountInc) sound                           CountIncSound;
Var (CountInc) bool                            bResetCounter;
var (CountInc) Array< Class< Emitter > >       CountIncFxpool;
 
var (Payload)  Array< Class< Emitter > >       PayloadFxpool;        // PayloadFx . if more than one they
Var (Payload)  float                           DeliverPayloadDelay;  // get picked at random for spawning
Var (Payload)  name                            PayloadEvent;
Var (Payload)  sound                           PayloadSoundFx;
Var (Payload)  float                           ShakeRadius;		// radius within which to shake Player views
 
var emitter                                    SpawnedAmbiant;
Var float                                      DamageTotal;
Var int                                        TheCounter;
var bool                                       bAffectingParticles;
var bool                                       bDeliveringPayload;
var bool                                       bResetting;
Var float                                      RotTime;			// how much Time to rot The instigator's view
Var float                                      OffsetTime;	    // how much Time to offset view
var vector                                     RotMag;			// how far to rot view
var vector                                     RotRate;			// how fast to rot view
var vector                                     OffsetMag;		// Max view offset vertically
var vector                                     OffsetRate;		// how fast to offset view vertically
 
 
function PostBegineplay()
{
 if (AmbiantFxPool.length > 0)
     SpawnFx(AmbiantFxPool);
 
 if (ShakeRadius < 64 )
     return;
                                                       // Taken away the option to
 OffsetMag  = vect(10.000000,10.000000,10.000000);             // let the mapper mess with the
 OffsetRate = vect(1000.000000,1000.000000,1000.000000);      // viewshake prorties just to
 OffsetTime=3.000000;                                         //make thing simpler
}
 
function takeDamage(Int Damage,Pawn EventInstigator,Vector HitLocation ,Vector Momentum,Class<damagEType> damagEType)
{
 
if ( bDeliveringPayload == true )
    return;
 
 DamageTotal = DamageTotal + Damage;
 if (bTransferMomentumToFxWhenShot == true)
    {
    bAffectingParticles = true;
    setTimer(0.5,false);
    }
 
 if (( DamageTotal > DamThresh ) && ( IncCounter() ) )
    {
     bDeliveringPayload = true;
     settimer( DeliverPayloadDelay , false );
    }
}
 
simulated function SpawnFX(array< class< emitter > > FXPool)
{
 local class<emitter>   PickedFxClass< SEMI >
 local Emitter          SpawnedFx;
 local int              PickedNumb;
 
 PickedNumb    = Rand(FXPool.length-1)+1;
 PickedFxClass = FXPool[ PickedNumb ];
 SpawnedFx     = Spawn ( PickedFxClass , self ,, Location , Rotation ); // delivering payload
 
if ( SpawnedAmbiant == none )
     SpawnedAmbiant = SpawnedFx;
}
 
Function bool IncCounter()     // adds 1 to Counter and checks to see If it
{                              // has rEached The Target amount. if so Returns True
 TheCounter++;
 
 if ( CountIncFxpool.length != 0 )
     spawnFX(CountIncFxpool);
 
 if ( CountIncSound  != none )
     PlaySound( CountIncSound );
 
 if ( TheCounter == TargetNum )
      return True;
 
Return false;
}
 
function Timer()
{
Local int Counter;
local int ModifySlot;
 
if (bAffectingParticles == true )
   {
   For( Counter=0 ; Counter <SpawnedAmbiant.Emitters.Length; Counter++ )
      {
      if ( ( SpawnedAmbiant.Emitters[Counter].UseVelocityScale == true ) && (SpawnedAmbiant.Emitters[Counter].VelocityScale[0].RelativeTime == 0 ) )
          ModifySlot = 1;
 
      SpawnedAmbiant.Emitters[Counter].VelocityScale[ModifySlot].RelativeVelocity.X = 
      SpawnedAmbiant.Emitters[Counter].default.VelocityScale[ModifySlot].RelativeVelocity.X;
      SpawnedAmbiant.Emitters[Counter].VelocityScale[ModifySlot].RelativeVelocity.y = 
      SpawnedAmbiant.Emitters[Counter].default.VelocityScale[ModifySlot].RelativeVelocity.y;
      SpawnedAmbiant.Emitters[Counter].VelocityScale[ModifySlot].RelativeVelocity.z = 
      SpawnedAmbiant.Emitters[Counter].default.VelocityScale[ModifySlot].RelativeVelocity.z;
      }
    bAffectingParticles = false;
   }
else
if ( bDeliveringPayload == true)
   {
    DeliverPay_load();
    return;
   }
else
Reset();
}
 
function Reset()
{
 SpawnedAmbiant.destroyed();
 bAffectingParticles = false;
 Thecounter          = Default.Thecounter;
 DamageTotal         = Default.DamageTotal;
 Super.Reset();                             // for level reset
}
 
Simulated function PartMorph( Vector TranferedMomentum )
{
 Local int Counter;
 local int ModifySlot;
 
 For( Counter=0 ; Counter < SpawnedAmbiant.Emitters.Length; Counter++ )
    {
     if ( ( SpawnedAmbiant.Emitters[Counter].UseVelocityScale == true ) && 
        (SpawnedAmbiant.Emitters[Counter].VelocityScale[0].RelativeTime == 0 ) )
         ModifySlot=1;
 
     SpawnedAmbiant.Emitters[Counter].VelocityScale[ModifySlot].RelativeVelocity.X = TranferedMomentum.x;
     SpawnedAmbiant.Emitters[Counter].VelocityScale[ModifySlot].RelativeVelocity.y = TranferedMomentum.y;
     SpawnedAmbiant.Emitters[Counter].VelocityScale[ModifySlot].RelativeVelocity.z = TranferedMomentum.z;
    }
}
 
function DeliverPay_load()
{
 local PlayerController	LocalPlayer;
 local Controller		C;
 
 if ( PayloadFxpool.length > 0 )
      SpawnFx(PayloadFxpool);
 
 if ( PayloadEvent  != '' )
 
     Triggerevent( PayloadEvent , self , instigator );            // delivering payload
 
 if ( PayloadSoundFx != none )
     PlaySound( PayloadSoundFx );                               // delivering payload
 
 
 if ( ShakeRadius > 64 )
    {
     LocalPlayer = Level.GetLocalPlayerController();
 
     if ( (LocalPlayer != none ) && ( VSize( Location - LocalPlayer.ViewTarget.Location ) < ShakeRadius ) )
         LocalPlayer.ShakeView( RotMag , RotRate , RotTime , OffsetMag , OffsetRate , OffsetTime );
 
     for ( C = Level.ControllerList ; C != None ; C = C.NextController )
 	      if ( (PlayerController( C ) != None) && (C != LocalPlayer) && (VSize(Location - PlayerController(C).ViewTarget.Location) < ShakeRadius) )
              C.ShakeView( RotMag, RotRate , RotTime , OffsetMag , OffsetRate , OffsetTime );
 
      }
 
 if ( bResetCounter == true )
    {
     bDeliveringPayload = false;
     SetTimer( ReSetDelay,false );
    }
}

Related[edit]

Discussion[edit]