UnrealScript Game Programming Cookbook

(Chris Devlin) #1
Chapter 4

93

How to do it...



  1. In the defaultproperties block at the bottom of your class, add the
    following code:
    // How many rounds will be added to our weapon type
    AmmoAmount=10
    // The type of weapon that this pickup will supply ammo
    for
    TargetWeapon=class'UTWeap_ShockRifle'


This simply declares the amount of ammo that will be added to the pawn's
inventory, as well as for which weapon class when it is picked up.


  1. Moving on, add the following code for the sound the pickup will make when
    it is acquired, respawn time, and the desirability for a bot to pick it up:
    // The sound effect triggered when the pickup is acquired
    PickupSound=SoundCue'A_Pickups.Ammo.Cue.
    A_Pickup_Ammo_Rocket_Cue'


/** The value at which an AI bot desires the pickup. Higher
value = will lean towards this pickup */
MaxDesireability=0.3

// Time (seconds) before the pickup respawns
RespawnTime=10.0

Desirability is a bot's attraction to a particular object in UDK. It can be
anything from ammo or health, to a specific weapon. Bots can also be
programmed to have a preferred weapon, and seek ammunition for that
above all else. The higher the desirability, the more likely a pawn is to
ignore other objects (and often pawns) to go after it.
This is especially effective when changing an AI's routine during a
particular gameplay type. In capture, if the flag matches, you can often
tell your AI companions to either defend your flag, attack the enemy flag,
or roam about and seek enemies.

We really could use any sound here, so for the sake of variety let's use the rocket
launcher's pickup sound.
Free download pdf