Legacy:MinigunFire
UT2003, Build 2225
Once again another reference of code, but this time for the Primary Fire of the minigun. Oh, and please correct me if I'm wrong. I won't get too pissed off ;)
<uscript> class MinigunFire extends InstantFire; //This is the class and the parent that it inherits some functionality from.
// These are declarations of variables used in the code. var() float MaxRollSpeed; var() float RollSpeed; var() float BarrelRotationsPerSec; //Amount of rotations of the barrel per sec var() int RoundsPerRotation; //Rounds fired per rotation var() float FireTime; var() Sound WindingSound; //The sound you hear when the minigun is getting ready to shoot. var() Sound FiringSound; //The sound you hear when the minigun is actually shooting. var MiniGun Gun; var() float WindUpTime; //Amount of time it takes to wind up
var() String FiringForce; //Amount of recoil var() String WindingForce;
//What happens when you beserk (adrenaline combo) with this firing mode function StartBerserk() {
DamageMin = default.DamageMin * 1.33; DamageMax = default.DamageMax * 1.33;
}
//What happens when you stop beserking function StopBerserk() {
DamageMin = default.DamageMin; DamageMax = default.DamageMax;
}
//Initiate this code after game begins function PostBeginPlay() {
Super.PostBeginPlay();
//Set the firing rate FireRate = 1.f / (RoundsPerRotation * BarrelRotationsPerSec);
//Set the maximum barrel rotation speed MaxRollSpeed = 65536.f*BarrelRotationsPerSec; Gun = Minigun(Owner);
}
//DoTrace is a function common to all weapons that handles the movement of projectiles and the determination //of the point of impact for instant-hit weapons. function DoTrace(Vector Start, Rotator Dir) { if ( FRand() < DeathMatch(Level.Game).MinigunLockDownFactor ) Momentum = FMax(1.0,DeathMatch(Level.Game).MinigunLockDownFactor) * Default.Momentum; else Momentum = 0; Super.DoTrace(Start,Dir); }
//Set muzzle flash to proper location on the gun function FlashMuzzleFlash() {
local rotator r; r.Roll = Rand(65536); Weapon.SetBoneRotation('Bone_Flash', r, 0, 1.f); Super.FlashMuzzleFlash();
}
//Set effects of the gun function InitEffects() {
Super.InitEffects(); if ( FlashEmitter != None )
Weapon.AttachToBone(FlashEmitter, 'flash'); }
//Set ambient sounds function PlayAmbientSound(Sound aSound) {
if ( (Minigun(Weapon) == None) || (Instigator == None) || (aSound == None && ThisModeNum != Gun.CurrentMode) ) return;
Instigator.AmbientSound = aSound; Gun.CurrentMode = ThisModeNum;
}
//Stop the barrel roll //When this function is called, it does an error check to make sure it's a valid call, then it simply sets //the rollspeed to 0.0 -- stopping the roll. function StopRolling() {
if (Gun == None || ThisModeNum != Gun.CurrentMode) return;
RollSpeed = 0.f; Gun.RollSpeed = 0.f;
}
function PlayPreFire() {} function PlayStartHold() {} function PlayFiring() {} function PlayFireEnd() {} function StartFiring(); function StopFiring(); function bool IsIdle() { return false; }
auto state Idle { function bool IsIdle() { return true; }
function BeginState() { PlayAmbientSound(None); StopRolling(); }
function EndState() { PlayAmbientSound(WindingSound); }
function StartFiring() //Says once you start to fire it winds up first { RollSpeed = 0;
FireTime = (RollSpeed/MaxRollSpeed) * WindUpTime;
GotoState('WindUp'); }
}
state WindUp {
function BeginState() //Starts the wind-up Procedure { ClientPlayForceFeedback(WindingForce); // jdf }
function EndState() //Says when wind-up ends the firing begins { if (ThisModeNum == 0) { if ( (Weapon == None) || !Weapon.FireMode[1].bIsFiring ) StopForceFeedback(WindingForce); } else { if ( (Weapon == None) || !Weapon.FireMode[0].bIsFiring ) StopForceFeedback(WindingForce); } }
function ModeTick(float dt) { FireTime += dt; RollSpeed = (FireTime/WindUpTime) * MaxRollSpeed;
if ( !bIsFiring ) {
GotoState('WindDown'); return; }
if (RollSpeed >= MaxRollSpeed) { RollSpeed = MaxRollSpeed; FireTime = WindUpTime; Gun.UpdateRoll(dt, RollSpeed, ThisModeNum);
GotoState('FireLoop');
return; }
Gun.UpdateRoll(dt, RollSpeed, ThisModeNum); }
function StopFiring() //Says if you stop firing it winds down { GotoState('WindDown'); }
}
state FireLoop //A loop that continues only if the boolean variable bIsFiring is true {
function BeginState() { NextFireTime = Level.TimeSeconds - 0.1; //fire now! PlayAmbientSound(FiringSound); ClientPlayForceFeedback(FiringForce); // jdf Gun.LoopAnim(FireLoopAnim, FireLoopAnimRate, TweenTime); Gun.SpawnShells(RoundsPerRotation*BarrelRotationsPerSec); }
function StopFiring() { GotoState('WindDown'); }
function EndState() //What happens after you stop firing { PlayAmbientSound(WindingSound); StopForceFeedback(FiringForce); // jdf Gun.LoopAnim(Gun.IdleAnim, Gun.IdleAnimRate, TweenTime); Gun.SpawnShells(0.f); }
function ModeTick(float dt) { Super.ModeTick(dt); Gun.UpdateRoll(dt, RollSpeed, ThisModeNum); if ( !bIsFiring ) {
GotoState('WindDown'); return; }
}
}
state WindDown {
function BeginState() //Begins the wind-down procedure { ClientPlayForceFeedback(WindingForce); // jdf }
function EndState() { if (ThisModeNum == 0) { if ( (Weapon == None) || !Weapon.FireMode[1].bIsFiring ) StopForceFeedback(WindingForce); } else { if ( (Weapon == None) || !Weapon.FireMode[0].bIsFiring ) StopForceFeedback(WindingForce); }//This checks to see what mode is firing, and stops the force feedback if any is occuring. }
function ModeTick(float dt) { FireTime -= dt; RollSpeed = (FireTime/WindUpTime) * MaxRollSpeed; if (RollSpeed <= 0.f) { RollSpeed = 0.f; FireTime = 0.f; Gun.UpdateRoll(dt, RollSpeed, ThisModeNum); GotoState('Idle'); return; }
Gun.UpdateRoll(dt, RollSpeed, ThisModeNum); }
function StartFiring() //Says in order to fire the gun must wind-up { GotoState('WindUp'); }
}
defaultproperties //Default variable settings. Some were declared at the top of the file, others were declared in the parent class. {
BarrelRotationsPerSec=3.000000 // How many times the barrel rotates every second. RoundsPerRotation=5 // How many rounds (shots) it fires every rotation. WindingSound=Sound'WeaponSounds.Minigun.miniempty' // The sound it plays when the gun is winding up. FiringSound=Sound'WeaponSounds.Minigun.minifireb' // The sound it plays when the gun is firing. WindUpTime=0.270000 // The default windup time. FiringForce="minifireb" WindingForce="miniempty" DamageType=Class'XWeapons.DamTypeMinigunBullet' DamageMin=6 // The minimum amount of damage each bullet does. DamageMax=7 // The maximum amount of damage each bullet does. Momentum=1200.000000 FireLoopAnimRate=9.000000 PreFireTime=0.270000 AmmoClass=Class'XWeapons.MinigunAmmo' // Which class of ammunition this weapon uses. AmmoPerFire=1 // How much of that ammuntion is used per shot. This might // seem pointless, but recall how the alt-fire on the Flak // Cannon uses more than one piece of ammo. ShakeRotMag=(X=50.000000,Y=50.000000,Z=50.000000) ShakeRotRate=(X=10000.000000,Y=10000.000000,Z=10000.000000) ShakeRotTime=2.000000 ShakeOffsetMag=(X=1.000000,Y=1.000000,Z=1.000000) ShakeOffsetRate=(X=1000.000000,Y=1000.000000,Z=1000.000000) ShakeOffsetTime=2.000000 BotRefireRate=0.990000 bPawnRapidFireAnim=True FlashEmitterClass=Class'XEffects.MinigunMuzFlash1st' // Which class the weapon will use for its muzzle flash emitter. SmokeEmitterClass=Class'XEffects.MinigunMuzzleSmoke' // Which class the weapon will use for its muzzle smoke emitter. aimerror=900.000000
Spread=0.080000 // How much variation there is between shots. This keeps the bullets going in slightly different directions. SpreadStyle=SS_Random // This makes sure that the Spread is truly random, so that the bullets going in slightly different directions looks pretty realistic.
} </uscript>
Once again I would like anyone to correct or add to any of this.
Related Topics
Category:Legacy Class (UT2003)