UnrealScript Game Programming Cookbook

(Chris Devlin) #1

Miscellaneous Recipes


222


  1. We really only need to add two new functions here, and alter another pre-existing
    one. Let's add our first new function now, FlashDmgTimer():
    /*****

    • NES style flashing damage timer to indicate how hurt a

    • pawn is
      *****/
      function FlashDmgTimer()
      {
      if (Health < HealthMax * .5)
      {
      'log("HP is less than 50%");
      SetTimer(2.2, true, 'FlashDmg');
      }




else if (Health < HealthMax * .25)
{
'log("HP is less than 25%");
SetTimer(1.5, true, 'FlashDmg');
}

else if (Health < HealthMax * 0.1)
{
'log("HP is less than 10%");
SetTimer(0.7, true, 'FlashDmg');
}
}

If our pawn's health is less than 50 percent, we call SetTimer(), which tells
FlashDmg() to be called once every 2.2 seconds. This is a simple visual indication
that our pawn (or any enemy who uses this function) is hurt. We then add two more
if statements that work in the same manner, and simply adjust how frequently
FlashDmg() is called. The more frequent it is called, the quicker the flashing occurs.


  1. The FlashDmg() function is very simple. It sets our body material color by calling the
    SetBodyMatColor() function and passing in our color and time parameters that
    we defined just before this.
    /*****

    • Sets the flashing overlay on the pawn to indicate damage taken
      *****/
      simulated function FlashDmg()
      {
      SetBodyMatColor(DamageBodyMatColor, DamageOverlayTime);
      }



  2. PlayHit() is called each time a pawn is hit. We want to override the current version
    of it and add our own behavior.
    /*****

    • Called when a pawn is hit



Free download pdf