Legacy:SustainedDamageTrigger - Unreal Wiki

# Legacy:SustainedDamageTrigger

### From Unreal Wiki, The Unreal Engine Documentation Site

Mod ideas for UT 2003 – Sustained damage trigger (keeps track of total damage)

## Description

In the original UT a trigger could be set to fire based on a minimum damage threshold. This trigger keeps track of the amonut of damage it receives and fires when the total damage it has sustained reaches the value specified.

#### Interested Scripters

If you are interested in developing this mod for UT2003 then add your name to the list. Once you start development you should indicate that below (and hopefully include a link to a journal page). Before you start development you should also check this section to see if anyone else has started.

- EntropicLqd – I'll need one of these for a map idea I've got. It's a little poly intensive for UT, but UT2003 would have no problems.

Tarquin: Try this:

    //=============================================================================
    // SustainedDamageTrigger.
    // by Tarquin. Untested.
    //=============================================================================
    class SustainedDamageTrigger extends Trigger;

    var float  DamageTaken ;

    function bool IsRelevant( actor Other )
    {
            if( !bInitiallyActive )
                    return false;
            switch( TriggerType )
            {
                    case TT_PlayerProximity:
                            return Pawn(Other)!=None && Pawn(Other).bIsPlayer;
                    case TT_PawnProximity:
                            return Pawn(Other)!=None && ( Pawn(Other).Intelligence > BRAINS_None );
                    case TT_ClassProximity:
                            return ClassIsChildOf(Other.Class, ClassProximityType);
                    case TT_AnyProximity:
                            return true;
                    case TT_Shoot:
                            if(Projectile(Other) != None)
                                    DamageTaken += Projectile(Other).Damage ;
                            return ( DamageTaken >= DamageThreshold );
            }
    }

even smaller:

    //=============================================================================
    // SustainedDamageTrigger.
    // by Tarquin. Untested.
    //=============================================================================
    class SustainedDamageTrigger extends Trigger;

    var float  DamageTaken ;

    function bool IsRelevant( actor Other )
    {
            if( !bInitiallyActive )
                    return false;
            if( TriggerType == TT_Shoot )
            {
                    if(Projectile(Other) != None)
                            DamageTaken += Projectile(Other).Damage ;
                    return ( DamageTaken >= DamageThreshold );
            }
            super.IsRelevant( Other );
            // case TT_Shoot in super will never be called
    }

## Discussion

EntropicLqd: Neato :) But what about hit scan weapons? I must confess to not having done a whole lot of research (ie. none) on this one but I was sort of expecting to use a TakeDamage() equivalent for the Trigger.

Tarquin: being cheap, I just used the code from Trigger which checks for damage. I have no idea!!

Mychaeel: You'd need to overwrite TakeDamage to deal with hitscan weapons, I suppose. For that matter, I'd think dealing with projectile weapons there instead of in IsRelevant would be neater too.

Dr.AwkwArD: I've added this sort of functionality to a new mover that I'm working on, imaginatively titled "AdvancedMover." Since movers already use TakeDamage() to deal with damage-triggering, it was the obvious function to override to accumulate damage. It takes damage from both projectiles and hitscan weapons. Here's a look at the code:

    //---------------------------------------------------------------------
    // new variables
    var() bool bDamageAccumulated;
    var   int  AccumulatedDamage;

    //---------------------------------------------------------------------
    // TakeDamage()
    //
    // Override the TakeDamage() function from mover to include an "accumulation" mode
    function TakeDamage(
       int Damage,
       Pawn instigatedBy,
       Vector hitlocation,
       Vector momentum,
       class<DamageType> damageType)
    {
       if(bDamageAccumulated)                                 // if we're supposed to accumulate damage, then...
       {
          AccumulatedDamage += Damage;                        // add the current damage inflicted to the AccumulatedDamage amount.
          Damage=AccumulatedDamage;                           // set Damage to the value of AccumulatedDamage so that we can trigger the mover if Damage is equal-to or greater-than the DamageThreshold
       }
       if( bDamageTriggered && (Damage >= DamageThreshold) )  // if the mover is supposed to be triggered by damage AND the amount of damage is equal-to or greater-than the DamageThreshold that was set...
       {
          if( (AIController(instigatedBy.Controller) != None) && (instigatedBy.Controller.Focus == self) )
          {
             instigatedBy.Controller.StopFiring();
          }
          self.Trigger(self, instigatedBy);                   // go ahead and trigger the mover
       }
    }

    //---------------------------------------------------------------------
    // Default Properties
    Default Properties
    {
       AccumulatedDamage=0  //the amount of damage accumulated at the start of the game
    }

(As this is my first posting, I'm not really familiar with WIKI etiquette so please feel free to move this code someplace else–or even remove it–if it doesn't belong here.)

If you're interested in learning more about AdvancedMover, a design journal and, of course, the resource itself is available on my website; just follow this link, here: AdvancedMover

Tarquin: Hi :) Looks interesting. Feel free to make a dedicated page for it on the wiki if you like. :)

Category: Legacy Journal

##### Views

- Legacy
- Discussion
- Current revision

##### Search