Post tutorial RSS Predator-style chaingun script

Not much of a tutorial I guess, its simply the tweaked Chaingun script, it has working Dryfire empty barrelspin a la movie Predator

Posted by on - Intermediate Client Side Coding

Heres the weapon_chaingun.script in its
entirety, it has a working empty barrelspin a la Predator, to get the "full Predator effect" you need the sounds from it, if people want it i will upload my Predatorstyle chaingun as a standalone mod.
Note - this scriptis basically all by Dafama

/***********************************************************************

weapon_chaingun.script

***********************************************************************/

#define CHAINGUN_FIRE_SKIPFRAMES 3 //4 is 10.4 rounds/sec - 3 is 14 rounds/sec
#define CHAINGUN_LOWAMMO 20 // was 30
#define CHAINGUN_NUMPROJECTILES 1 // def. 1
#define CHAINGUN_BARREL_SPEED ( 60 * ( GAME_FPS / CHAINGUN_FIRE_SKIPFRAMES ) )
#define CHAINGUN_BARREL_ACCEL_TIME 0.05 // was 0.4
#define CHAINGUN_BARREL_DECCEL_TIME 2.6 // was 1.0
#define CHAINGUN_BARREL_ACCEL ( CHAINGUN_BARREL_SPEED / CHAINGUN_BARREL_ACCEL_TIME )
#define CHAINGUN_BARREL_DECCEL ( CHAINGUN_BARREL_SPEED / CHAINGUN_BARREL_DECCEL_TIME )

// blend times
#define CHAINGUN_IDLE_TO_LOWER 4
#define CHAINGUN_IDLE_TO_FIRE 0
#define CHAINGUN_IDLE_TO_RELOAD 4
#define CHAINGUN_IDLE_TO_NOAMMO 4 //FOR DRYFIRE
#define CHAINGUN_NOAMMO_TO_RELOAD 4 //FOR DRYFIRE
#define CHAINGUN_NOAMMO_TO_IDLE 4 //FOR DRYFIRE
#define CHAINGUN_RAISE_TO_IDLE 4 // was 0
#define CHAINGUN_WINDDOWN_TO_IDLE 4 // was 0
#define CHAINGUN_RELOAD_TO_IDLE 0

object weapon_chaingun : weapon_base {
entity world_model;
float world_barrel_joint;
float barrel_joint;
float barrel_angle;
float current_rate;
float start_rate;
float end_rate;
float spin_start;
float spin_end;
float spread;

void init();

void UpdateBarrel();
void SpinUp();
void SpinDown();

void Lower();
void Raise();
void Idle();
void NoAmmo(); //FOR DRYFIRE
void Fire();
void Reload();
void ExitCinematic();
};

void weapon_chaingun::init() {
world_model = getWorldModel();
world_barrel_joint = world_model.getJointHandle( "toob" );
barrel_joint = getJointHandle( "spinner" );
barrel_angle = 0;
current_rate = 0;
start_rate = 0;
end_rate = 0;
spin_start = 0;
spin_end = 0;
spread = getFloatKey( "spread" );

weaponState( "Raise", 0 );
}

void weapon_chaingun::destroy() {
stopSound( SND_CHANNEL_BODY3, false );
}

void weapon_chaingun::UpdateBarrel() {
float currentTime;
float t;
vector ang;

currentTime = sys.getTime();
if ( currentTime < spin_end ) {
t = ( currentTime - spin_start ) / ( spin_end - spin_start );
current_rate = start_rate + t * ( end_rate - start_rate );
} else {
current_rate = end_rate;
}

if ( current_rate ) {
barrel_angle = barrel_angle + current_rate * GAME_FRAMETIME;

ang_x = 0;
ang_y = 0;
ang_z = barrel_angle;
setJointAngle( barrel_joint, JOINTMOD_LOCAL, ang );

ang_y = barrel_angle;
ang_z = 0;
world_model.setJointAngle( world_barrel_joint, JOINTMOD_LOCAL, ang );
}
}

void weapon_chaingun::SpinUp() {
start_rate = current_rate;
end_rate = CHAINGUN_BARREL_SPEED;
spin_start = sys.getTime();
spin_end = spin_start + ( end_rate - current_rate ) / CHAINGUN_BARREL_ACCEL;
startSound( "snd_windup", SND_CHANNEL_BODY3, false );
}

void weapon_chaingun::SpinDown() {
start_rate = current_rate;
end_rate = 0;
spin_start = sys.getTime();
spin_end = spin_start + ( current_rate - end_rate ) / CHAINGUN_BARREL_DECCEL;
startSound( "snd_winddown", SND_CHANNEL_BODY3, false );
}

void weapon_chaingun::Raise() {
weaponRising();
playAnim( ANIMCHANNEL_ALL, "raise" );
waitUntil( animDone( ANIMCHANNEL_ALL, CHAINGUN_RAISE_TO_IDLE ) );
playCycle( ANIMCHANNEL_ALL, "idle" );
weaponState( "Idle", CHAINGUN_RAISE_TO_IDLE );
}

void weapon_chaingun::Lower() {
weaponLowering();
playAnim( ANIMCHANNEL_ALL, "putaway" );

while( !animDone( ANIMCHANNEL_ALL, 0 ) ) {
UpdateBarrel();
waitFrame();
}

weaponHolstered();
waitUntil( WEAPON_RAISEWEAPON );
weaponState( "Raise", 0 );
}

void weapon_chaingun::Idle() {
float ammoClip;
float avail;
float clip_size;

clip_size = clipSize();

//if ( !ammoInClip() ) {
// weaponOutOfAmmo();
//} else {
weaponReady();
//}

while( 1 ) {
if ( WEAPON_LOWERWEAPON ) {
weaponState( "Lower", CHAINGUN_IDLE_TO_LOWER );
}
ammoClip = ammoInClip();
if ( WEAPON_ATTACK || WEAPON_NETFIRING ) {
if ( ammoClip > 0 || !autoReload() ) { // dfm
weaponState( "Fire", CHAINGUN_IDLE_TO_FIRE );
} else if ( ammoAvailable() > 0 ) {
if ( autoReload() ) {
netReload();
weaponState( "Reload", CHAINGUN_IDLE_TO_RELOAD );
//DRYFIRE CODE START
} else {
weaponState( "NoAmmo", CHAINGUN_IDLE_TO_NOAMMO );
}
} else {
weaponState( "NoAmmo", CHAINGUN_IDLE_TO_NOAMMO );
}
//DRYFIRE CODE END
}
if ( WEAPON_RELOAD && ( ammoAvailable() > ammoClip ) && ( ammoClip < clip_size ) ) {
netReload();
weaponState( "Reload", CHAINGUN_IDLE_TO_RELOAD );
}
if ( WEAPON_NETRELOAD ) {
WEAPON_NETRELOAD = false;
weaponState( "Reload", CHAINGUN_IDLE_TO_RELOAD );
}
UpdateBarrel();
waitFrame();
}
}

//DRYFIRE CODE START
void weapon_chaingun::NoAmmo() {

if ( WEAPON_NETRELOAD ) {
WEAPON_NETRELOAD = false;
weaponState( "Reload", CHAINGUN_IDLE_TO_RELOAD );
}

playAnim( ANIMCHANNEL_ALL, "noammo" );
waitUntil( animDone( ANIMCHANNEL_ALL, CHAINGUN_NOAMMO_TO_IDLE ) );
weaponState( "Idle", CHAINGUN_NOAMMO_TO_IDLE );
}
//DRYFIRE CODE END

void weapon_chaingun::Fire() {
float ammoClip;
float currentTime;
float skip;

SpinUp();
ammoClip = ammoInClip();
while( ( current_rate < end_rate ) && !WEAPON_RELOAD && ( WEAPON_NETFIRING || ( WEAPON_ATTACK && ( ammoClip > 0 ) ) ) ) {
UpdateBarrel();
waitFrame();
ammoClip = ammoInClip();
}

startSound( "snd_spin", SND_CHANNEL_BODY3, false );
ammoClip = ammoInClip();
//while ( !WEAPON_RELOAD && ( WEAPON_NETFIRING || ( WEAPON_ATTACK && ( ammoClip > 0 ) ) ) ) {
while ( !WEAPON_RELOAD && ( WEAPON_NETFIRING || WEAPON_ATTACK ) ) {
if ( ammoClip > 0 ) {
launchProjectiles( CHAINGUN_NUMPROJECTILES, 2, 1, 1.0, 1.0 );

startSound( "snd_fire", SND_CHANNEL_WEAPON, false );
ammoClip = ammoInClip();
if ( ammoClip == CHAINGUN_LOWAMMO || ammoClip <= 20 ) {
startSound( "snd_lowammo", SND_CHANNEL_ITEM, false );
}
} // dfm

// skip frames
for( skip = 0; skip < CHAINGUN_FIRE_SKIPFRAMES; skip++ ) {
UpdateBarrel();
waitFrame();
}
}

//EMPTY BARREL SPIN CODE START
while( WEAPON_ATTACK && !WEAPON_RELOAD && ( ammoClip <= 0 ) ) {
UpdateBarrel();
waitFrame();
}
//EMPTY BARREL SPIN CODE END

SpinDown();

// Auto reload when empty
// if ( !ammoInClip() && autoReload() && (ammoAvailable() > 0) )
// {
// netReload();
// weaponState( "Reload", CHAINGUN_IDLE_TO_RELOAD );
// } else {
weaponState( "Idle", CHAINGUN_WINDDOWN_TO_IDLE );
// }
}

void weapon_chaingun::Reload() {
weaponReloading();
playAnim( ANIMCHANNEL_ALL, "reload" );
while( !animDone( ANIMCHANNEL_ALL, CHAINGUN_RELOAD_TO_IDLE ) ) {
UpdateBarrel();
waitFrame();
}
addToClip( clipSize() );
playCycle( ANIMCHANNEL_ALL, "idle" );
weaponState( "Idle", CHAINGUN_RELOAD_TO_IDLE );
}

void weapon_chaingun::ExitCinematic() {
current_rate = 0;
start_rate = 0;
end_rate = 0;
spin_start = 0;
spin_end = 0;

weaponState( "Idle", 0 );
}

Comments
GunmanProductions™
GunmanProductions™

It would be more than awesome if you could release a Predator style Chaingun as a standalone mod, yes!

Reply Good karma Bad karma+3 votes
ice_trey Author
ice_trey

hehe true that mate (Y) Now that im BACK at it , once again, i might expand and retweak stuff :P

Reply Good karma+1 vote
Fady117
Fady117

Thank you, this can be helpful in some way, I've been trying to learn how to add custom scripts to an existing script to further customize weapons. Sure can use all the help I can find!

Reply Good karma Bad karma+1 vote
Valorin
Valorin

Thanks! I recently started to reassemble my mod stuff again, and I know at some point I had dryfire and that spinning barrel when empty. Couldn't find my old script files (which I got from some mod) from 10 years ago, and was really glad to still find these scripts online!
I got my dryfire back. I can sleep again. Thanks again!

Reply Good karma Bad karma+1 vote
Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.