I don't need to test my programs. I have an error-correcting modem.

Legacy:How UT Weapons Work/Firing A Weapon

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search

This might seem pretty short, but there isn't that much to talk about here.

Basically we go through Engine.Weapon (UT) and Botpack.TournamentWeapon here and have a short look at Botpack.UT_BioRifle's alt fire mode.


When a PlayerPawn wants to fire his weapon he executes his Fire (or AltFire) function which in turn calls the TournamentWeapon's (Alt)Fire function. This function might be overridden in subclasses of actual weapons, but often the default version is used.

The Default Fire Function[edit]

First the weapon checks, if it has ammo, then it tries to use one ammo unit. If successful it goes into 'NormalFire' state and (still in the Fire function) either traces the shot using TraceFire (for hitscan weapons) or spawns a projectile using ProjectileFire.

The Fire function also calls ClientFire which by default only executes when bCanClientFire is True. ClientFire is responsible for all the things only visible to the player actually owning the weapon, like screen flashes, playing the firing animation and calling the FireEffect function of the TournamentPickup registered as the weapon's affector.

If ClientFire is not executed on a listen server or in singleplayer the weapon also goes into 'ClientFiring' state. (see below)

The Default NormalFire State[edit]

After the Fire function has finished code execution continues in the 'NormalFire' state. Well, it doesn't really "continue" because the state code only consists of "Sleep(0.0);" which actually does nothing.

The actual "magic" is in the empty Fire and AltFire functions, which prevent firing another shot while the firing animation isn't finished, and in the AnimEnd function which ends the 'NormalFire' state by calling Finish.

The Finish Function[edit]

(someone please add how bForceFire works)

The first interesting thing here is the check for bChangeWeapon. This variable is set when the player wants to change to another weapon. If this is the case the weapon goes to the 'DownWeapon' state. (see Legacy:How UT Weapons Work/Switching To Another Weapon)

The next part applies only to Bot (UT)s and checks if the weapon still has ammo and whether the bot still wants to shoot.

Now Finish checks whether the weapon still has ammo and the player still presses the (alt)fire button. If so the global (Alt)Fire function is called, if not the weapon goes into 'Idle' state.

The 'Idle' State[edit]

We are back where we started – in the 'Idle' state. The weapon checks if it still has ammo. If not it switches to the best weapon available. If the player presses the (alt)fire button the cycle starts again, if not the weapon disables its AnimEnd function and plays its idle animation.

Firing On A Network Client[edit]

The client can't spawn projectiles or trace shots. Clients have to simulate the behavior of the weapon as good as possible, so the 'Client(Alt)Firing' state waits untill the firing animation is finished and checks whether the player still presses the (alt)fire button. If the player doesn't fire anymore the weapon plays its idle animation and goes into the null state (with GotoState();, the 'Idle' state is only used server-side).

The client code usually is completely different than the code used for the server-side behavior.


Examples For Custom Firing Behavior[edit]

UT Bio Rifle[edit]

The load-and-hold feature in the Bio Rifle's secondary firing mode is created by ignoring the AnimEnd function inside the 'AltFiring' state. Instead there is a check in the Tick function if the player still presses the altfire button. When the button is released the Bio Rifle goes into 'ShootLoad' state to fire its load.

When entering the 'ShootLoad' state a UT_BioGlob is fired and the corresponding animation is played. In this state AnimEnd is not ignored and executes the Finish function to end the firing sequence. (Don't get confused by the Timer function in this state, it isn't used.)


Comments[edit]

Please complain here if something isn't explained clearly enough.

HunterKiller: It's not a complain :) , Its a request. Can someone update this to UT2K3? I don't feel good enough to make the research and change (or make a new) firing a weapon page.

Wormbo: UT2k3 weapons work completely different, so it would be better to start a whole new page for that. Unfortunately I don't have the time to do all the research either. Somebody who made/makes a weapon mod could probably create the How UT2003 Weapons Work page and subpages.

Eldhrin: I'm working with UT2K3 weapons quite a bit at the moment, so I might be able to start that off some time.

HunterKiller: Okay, I'm giving the first step. Please contribute to How UT2003 Weapons Work :D