How UT2003 Weapons Work/Firing A Weapon
It starts!
Everything begins on the PlayerController Fire exec function. An exec function is a function that can be bound to a key by a player - so you won't find it directly called in most UnrealScript because the event handling is handled natively by the engine. (thanks Trystan for that )
So the chain goes like this:
- PlayerController.Fire
exec function Fire( optional float F ) { if ( Level.Pauser == PlayerReplicationInfo ) { SetPause(false); return; } Pawn.Fire(F); }
Here is easy: if the level is not in pause mode, call the Pawn's Fire function. If the level is paused and the person who paused it is the one who's firing, it unpauses the level but does not fire the weapon.
- Pawn.Fire
function Fire( optional float F ) { if( Weapon!=None ) Weapon.Fire(F); }
Again, piece of cake: if the pawn has a weapon, call the weapon Fire function.
- Weapon.Fire
simulated function Fire(float F) { }
Huh?? Did someone forgot to write the code? Well, I supposed it was on the subclasses, BUT, whathaheck?? There is no Fire function in the Weapons classes. The WeaponFire class gets in scene. Each weapon has an array of fire modes. This is the linking to the WeaponFire class and we will break our path to this class.
HunterKiller: A good question here would be: Why someone would subclass the Fire function of Weapon?
Trystan: Well consider that not every weapon fires the same way or fires the same projectiles. You want to be able to customize this function to the greatest extent possible. The base classes are abstract; they're meant to be used as a basis for moving forward, and not to actually be used. When you create a new weapon you have to create your own Fire function. Also, if you were to say, create a weapon that couldn't be fired while you were moving you might want to check player velocity before actually firing, etc. (You wouldn't want to do that in PlayerController.Fire() because it would be weapon dependent.)
HunterKiller: You made it very clear in Firing Projectile weapons
WeaponFire is responsible for creating the visual effects and applying damage. There are two main weapon fire types:
Types of weapons
ProjectileFire? - Firing Projectile weapons
InstantFire - Firing InstantFire weapons
We will go on with the instant fire weapons; So, click that link!
Comments
HunterKiller: Well boys this is my first contribution here, so, take it easy
Wormbo: Nice to see someone started this page, because IMHO the weapons are one of the most complex things in the game.
Trystan: Making one is easy. Understanding the mechanics is hard.
Trystan: Understanding the mechanics is impossible. mutter. There's no concrete chain of events that occur in UnrealScript only to follow when firing a weapon. A great deal of the code seems to be handled natively, or via some method I can't find.
DJPaul: Perhaps the big picture/content on Firing Projectile Weapons should live here..
StrikeFerret: Projectile weapons are reasonably easy to understand. Weapon causes object to fly, object contacts something, and something hurts. I had to re-write the entire damage system for a Mod I'm working on, and while there is no concrete chain of events, it's true (Playing with TakeDamage didn't do anything) you can circumvent things and plod along and it'll probably work for you.