UnrealScript Game Programming Cookbook

(Chris Devlin) #1
Chapter 6

171

How to do it...


We're only going to add one function to this class.



  1. Just as we did with our healing weapon, we need to override the UTWeapon
    class's ProcessInstantHit() function. We're not going to do any sort
    of healing again though.
    simulated function ProcessInstantHit(byte FiringMode, ImpactInfo
    Impact, optional int NumHits)
    {
    local TutorialPawn TP;


if (Impact.HitActor != None &&
(Impact.HitActor).IsA('Pawn'))
{
// Defining the pawn
TP = TutorialPawn(Impact.HitActor);

/** Calls the poison function in the TutorialPawn
class */
TP.PoisonPlayer();

// Log for debugging
'Log("***Pawn Health:" @TP.Health);

}
}

First we perform a check to see whether our projectile has hit an actor. Immediately
after that, we check to see if that actor is a pawn. We don't want to apply our
poison damage to something non-living like a vehicle or a barrel. Afterwards, we
check to see if the pawn is of our TutorialPawn class. From there, we call the
PoisonPlayer() function from our TutorialPawn class. This is what actually
poisons the pawn. Finally, we add our standard log which tracks our tutorial pawn's
health, to verify that our function is actually having some kind of an effect.


  1. Now it's time to head to our TutorialPawn class. Let's start by adding a variable
    to hold the amount of time ticking by, as our pawn is poisoned:
    var int PoisonCountdown;

  2. Our PoisonPlayer() function is what is actually being called by our weapon.
    This simple function resets our poison counter to 0 , and prevents our damage
    from stacking.

Free download pdf