/***********************************************************************
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 );
}
Thanks for the script m8, Imma copy-paste it into my own mod.
The increased spread works well however the dryfire part doesn't, I seem to be missing the idle_empty animation. :/
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?
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.
or referr to ubermodder dafama ? :p
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.
I am going to check this script for see if i can fix this issues...