UnrealScript Game Programming Cookbook

(Chris Devlin) #1

Weapons


172

Next we use a standard SetTimer() function, which you will find is frequently
used throughout UDK. We're telling the game to call the PoisonDmg() function
every .5 seconds. This is the actual tick that damages our pawn. We could easily
increase the amount of damage done by increasing the frequency at which
PoisonDmg() is called.
/********************************************************
* Called by MyWeapon_PoisonDamge when the pawn is shot
********************************************************/
function PoisonPlayer()
{
// Reset Poison Counter
PoisonCountdown = 0;

// Every .5 seconds PoisonDmg() will be called
SetTimer(0.5, true, 'PoisonDmg');
}

Let's take a look at what PoisonDmg() actually does:
/********************************************************
* Actually does the damage to the pawn
********************************************************/
function PoisonDmg()
{
// Does 5 damage to the pawn of type UTDmgType_Burning
TakeDamage( 5, None, Location, vect(0,0,0) ,
class'UTDmgType_Burning');
PoisonCountdown=PoisonCountdown+1;
// Increment timer
'Log("***Pawn Health:" @Health);
// Log for debugging

// clear the infinitely looping 0.5 second timer after 10
counts of damage
if(PoisonCountdown >= 10)
{
ClearTimer('PoisonDmg');
}
}

We start by calling the TakeDamage() function and informing the pawn how
much damage it is taking ( 5 ), where it is being hit (Location), any momentum
to be applied (None, as our vector reads 0,0,0) and finally the type of damage
(UTDmgType_Burning). Burning is a DoT as well, so rather than create a new
damage type, we just stick with what UDK provides.
Free download pdf