Post tutorial RSS a machinegun script complete with dryfire and fullauto spread

This isnt much of a tutorial as such, its a machinegun script completed with both Dryfire as well as Spread settings that make the weapon shoot with more spread if on fullauto; i post this because i havent seen a script which combines both Dryfire and Spread anywhere else

Posted by on - Intermediate Client Side Coding

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

weapon_machinegun.script

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

#define MACHINEGUN_FIRERATE 0.1 // ~10 per second
#define MACHINEGUN_BURSTTIME 0.1
#define MACHINEGUN_CHECKBURSTTIME 0.15
#define MACHINEGUN_MAXSPREAD 6
#define MACHINEGUN_LOWAMMO 5
#define MACHINEGUN_NUMPROJECTILES 1

// blend times
#define MACHINEGUN_IDLE_TO_LOWER 4
#define MACHINEGUN_IDLE_TO_FIRE 0
#define MACHINEGUN_IDLE_TO_RELOAD 4
#define MACHINEGUN_IDLE_TO_NOAMMO 3 //dryfire
#define MACHINEGUN_NOAMMO_TO_RELOAD 4 //dryfire
#define MACHINEGUN_NOAMMO_TO_IDLE 3 //dryfire
#define MACHINEGUN_RAISE_TO_IDLE 4
#define MACHINEGUN_FIRE_TO_IDLE 0
#define MACHINEGUN_RELOAD_TO_IDLE 4
#define MACHINEGUN_FIRE_TO_FIRE 2 //spread

object weapon_machinegun : weapon_base {
float next_attack;
float spread;
float firetype; //added 4 spread

void init();

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

void weapon_machinegun::init() {
next_attack = 0;
spread = getFloatKey( "spread" );
weaponState( "Raise", 0 );
}

void weapon_machinegun::Raise() {
weaponRising();
playAnim( ANIMCHANNEL_ALL, "raise" );
waitUntil( animDone( ANIMCHANNEL_ALL, MACHINEGUN_RAISE_TO_IDLE ) );
weaponState( "Idle", MACHINEGUN_RAISE_TO_IDLE );
}

void weapon_machinegun::Lower() {
weaponLowering();
playAnim( ANIMCHANNEL_ALL, "putaway" );
waitUntil( animDone( ANIMCHANNEL_ALL, 0 ) );
weaponHolstered();
waitUntil( WEAPON_RAISEWEAPON );
weaponState( "Raise", 0 );
}

void weapon_machinegun::Idle() {
float currentTime;
float ammoClip;
float avail;
float clip_size;

clip_size = clipSize();

//dryfire tweak bel0w

weaponReady();
if ( !ammoInClip() ) {
playCycle( ANIMCHANNEL_ALL, "idle_empty" );
} else {
playCycle( ANIMCHANNEL_ALL, "idle" );
}
while( 1 ) {
if ( WEAPON_LOWERWEAPON ) {
weaponState( "Lower", MACHINEGUN_IDLE_TO_LOWER );
}
currentTime = sys.getTime();
ammoClip = ammoInClip();
if ( ( currentTime >= next_attack ) && WEAPON_ATTACK ) {
if ( ammoClip > 0 ) {
weaponState( "Fire", MACHINEGUN_IDLE_TO_FIRE );
} else if ( ammoAvailable() > 0 ) {
if ( autoReload() ) {
netReload();
weaponState( "Reload", MACHINEGUN_IDLE_TO_RELOAD );
} else {
weaponState( "NoAmmo", MACHINEGUN_IDLE_TO_NOAMMO );
}
} else {
weaponState( "NoAmmo", MACHINEGUN_IDLE_TO_NOAMMO );
}
}
if ( WEAPON_RELOAD && ( ammoAvailable() > ammoClip ) && ( ammoClip < clip_size ) ) {
netReload();
weaponState( "Reload", MACHINEGUN_IDLE_TO_RELOAD );
}
if ( WEAPON_NETRELOAD ) {
WEAPON_NETRELOAD = false;
weaponState( "Reload", MACHINEGUN_IDLE_TO_RELOAD );
}
waitFrame();
}
}

void weapon_machinegun::NoAmmo() {

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

playAnim( ANIMCHANNEL_ALL, "noammo" );
waitUntil( animDone( ANIMCHANNEL_ALL, MACHINEGUN_NOAMMO_TO_IDLE ) );
weaponState( "Idle", MACHINEGUN_NOAMMO_TO_IDLE );
}

//dryfire tweak end"

void weapon_machinegun::Fire() {
float ammoClip;

next_attack = sys.getTime() + MACHINEGUN_FIRERATE;

ammoClip = ammoInClip();
if ( ammoClip == MACHINEGUN_LOWAMMO ) {
startSound( "snd_lowammo", SND_CHANNEL_ITEM, true );
}

launchProjectiles( MACHINEGUN_NUMPROJECTILES, spread, 0, 1.0, 1.0 );
playAnim( ANIMCHANNEL_ALL, "fire" );
if(firetype == 2){
wait(MACHINEGUN_BURSTTIME);
if(WEAPON_ATTACK && ammoClip > 0){
if(spread < MACHINEGUN_MAXSPREAD)
spread = spread + 1;
weaponState( "Fire", MACHINEGUN_FIRE_TO_FIRE );
}
}
else{
wait(MACHINEGUN_CHECKBURSTTIME);
if(WEAPON_ATTACK && ammoClip > 0){
firetype = 2;
weaponState( "Fire", MACHINEGUN_FIRE_TO_FIRE );
}
}
spread = getFloatKey( "spread" );
firetype = 1;
waitUntil( animDone( ANIMCHANNEL_ALL, MACHINEGUN_FIRE_TO_IDLE ) );
weaponState( "Idle", MACHINEGUN_FIRE_TO_IDLE );
}

void weapon_machinegun::Reload() {
weaponReloading();
playAnim( ANIMCHANNEL_ALL, "reload" );
waitUntil( animDone( ANIMCHANNEL_ALL, MACHINEGUN_RELOAD_TO_IDLE ) );
addToClip( clipSize() );
weaponState( "Idle", MACHINEGUN_RELOAD_TO_IDLE );
}

void weapon_machinegun::ExitCinematic() {
next_attack = 0;
weaponState( "Idle", 0 );
}

Comments
GunmanProductions™
GunmanProductions™ - - 251 comments

Thanks for the script m8, Imma copy-paste it into my own mod.

Reply Good karma Bad karma+1 vote
GunmanProductions™
GunmanProductions™ - - 251 comments

The increased spread works well however the dryfire part doesn't, I seem to be missing the idle_empty animation. :/

Reply Good karma Bad karma+1 vote
ice_trey Author
ice_trey - - 1,106 comments

hmmmm weird, it works perfectly with default and with the ak74u im using now for mg sub, maybe you should try messing with the blend times?

Reply Good karma+1 vote
fascinate4
fascinate4 - - 7 comments

ice_trey, can you make tutorials how to make models(first person and third) for doom3, with exporting and importing tutors? Cause always I have trouble with textures, when I am importing models for D3. But I didn't find good tutors for this problem.

Reply Good karma Bad karma+1 vote
ice_trey Author
ice_trey - - 1,106 comments

or referr to ubermodder dafama ? :p

Reply Good karma+2 votes
tehstrelok
tehstrelok - - 125 comments

would be great if you got this fully working, fixing the noammo to reload problem, and how the dryfire sound cause the shoot sounds to cut off.

Reply Good karma Bad karma+2 votes
Dafama2k7
Dafama2k7 - - 156 comments

I am going to check this script for see if i can fix this issues...

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.