// --------------------------------------------------------------------------
//
// Deagle (Demo weapon)
//
// --------------------------------------------------------------------------

Actor M4A1_sil_AltFire : Inventory
{
Inventory.MaxAmount 1
}

ACTOR "m4a1 silenced" : CSDMOWeapon //5010
{
	Weapon.SisterWeapon "m4a1 silenced_rat"

+AMMO_OPTIONAL

	Weapon.SelectionOrder 200
  weapon.ammotype "M4A1_SIL_Clip"
  weapon.ammouse 1
  weapon.ammogive 0
  weapon.ammotype2 "556mmAmmo"
  weapon.ammouse2 0
  weapon.ammogive2 0 //7
	obituary "%k killed %o with m4a1 silenced."
	+WEAPON.WIMPY_WEAPON
	Inventory.Pickupmessage "Picked up a silenced m4a1."
	Tag "M4A1 Silenced"
	Weapon.UpSound "m4a1_sil/Ready"
	//AttackSound "Deagle/Fire" 
	Scale 0.2
	//+NOAUTOFIRE

	States
	{
	Ready:
		45WC N 1 A_WeaponReady
	TNT1 A 0 A_JumpIfInventory("IsBot",1,"BotReady")
	TNT1 A 0 A_JumpIfInventory("IsAltFire", 1, "Sil")
		Loop


	ReadySilencer:
		W45C N 1 A_WeaponReady
	TNT1 A 0 A_JumpIfInventory("IsBot",1,"BotReady")
	TNT1 A 0 A_JumpIfInventory("IsAltFire", 1, "Unsil")
		Loop
		

	



		

	Deselect:
	TNT1 A 0 ACS_NamedExecuteAlways("HSPreviousWeapon", 0, 2, 0, 0)
    TNT1 A 1 
	Goto DeselectLoop

	Select:
	TNT1 A 1 A_Raise
	TNT1 AA 0 A_Raise
	TNT1 A 0 ACS_ExecuteAlways(798, 0, 225, 0, 0)//Weapon Weight
	TNT1 A 5 A_TakeInventory("CrosshairType",2)

	TNT1 A 0 ACS_NamedExecuteAlways("HSPreviousWeapon", 0, 1, 0, 0)
		TNT1 A 0 A_WEAPONREADY(WRF_NOFIRE)


	TNT1 A 0 A_JumpIfInventory("M4A1_sil_AltFire", 1, "SelectSilencer")

    TNT1 A 0 A_JumpIfInventory("RAT_Trigger",1,"RAT_TriggerSelect")
		45WA FGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE|WRF_NOBOB)
		45WB ABCDEFG 1 A_WEAPONREADY(WRF_NOFIRE|WRF_NOBOB)
		45WB HIJKLMN 1 A_WEAPONREADY(WRF_NOFIRE)
		Goto Ready

	SelectSilencer:

    TNT1 A 0 A_JumpIfInventory("RAT_Trigger",1,"RAT_TriggerSelectSilencer")
		W45A FGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE|WRF_NOBOB)
		W45B ABCDEF 1 A_WEAPONREADY(WRF_NOFIRE|WRF_NOBOB)
		W45B GHIJKLMN 1 A_WEAPONREADY(WRF_NOFIRE)
		Goto ReadySilencer



	Rat_TriggerSelect:
    TNT1 A 0 A_TakeInventory("Rat_Trigger",1)

		45WA FGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE|WRF_NOBOB)
		45WB ABCDEFG 1 A_WEAPONREADY(WRF_NOBOB)
		45WB HIJKLMN 1 A_WEAPONREADY//(WRF_NOFIRE)
		Goto Ready

	Rat_TriggerSelectSilencer:
    TNT1 A 0 A_TakeInventory("Rat_Trigger",1)

		W45A FGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE|WRF_NOBOB)
		W45B ABCDEF 1 A_WEAPONREADY(WRF_NOBOB)
		W45B GHIJKLMN 1 A_WEAPONREADY//(WRF_NOFIRE)
		Goto ReadySilencer


	Fire:

	W45F H 0 A_JumpIfNoAmmo("AltFire")
	TNT1 A 0 A_JumpIfInventory("M4A1_sil_AltFire", 1, "FireSilencer")
	TNT1 A 0 A_JumpIfInventory("IsBot",1,"BotFire")
	
		45WC A 1 A_GunFlash
		45WC B 1 A_WEAPONREADY(WRF_NOFIRE)
		45WC CD 1 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 0 A_Refire
		45WC EFGHIJKLMN 1 A_WeaponReady
		Goto Ready



	FireSilencer:

	W45F H 0 A_JumpIfNoAmmo("AltFire")
	TNT1 A 0 A_JumpIfInventory("IsBot",1,"BotFire")
	
		W45C A 1 A_GunFlash
		W45C B 1 A_WEAPONREADY(WRF_NOFIRE)
		W45C CD 1 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 0 A_Refire
		W45C EFGHIJKLMN 1 A_WeaponReady
		Goto ReadySilencer






	Unsil:
		W45I ABCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W45J AB 1 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 0 A_PlaySound("m4a1_sil/Unsil", 6)
		W45J CDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W45K ABCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W45L ABCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W45M ABCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W45N ABCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W45O ABCDEFGHIJKL 1 A_WEAPONREADY(WRF_NOFIRE)
		
		    TNT1 A 0 A_TakeInventory("M4A1_sil_AltFire",1)
		
		Goto Ready
	
	
	Sil: //Same as unsil, but reversed because i couldn't rip it properly before hand changes
		W45O LKJIHGFEDCBA 1 A_WEAPONREADY(WRF_NOFIRE)
		W45N ZYXWVUTSRQPONMLKJIHGFEDCBA 1 A_WEAPONREADY(WRF_NOFIRE)
		W45M ZYXWVUTSRQPONM 1 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 0 A_PlaySound("m4a1_sil/unSil", 6)
		W45M LKJIHGFEDCBA 1 A_WEAPONREADY(WRF_NOFIRE)
		W45L ZYXWVUTSRQPONMLKJIHGFEDCBA 1 A_WEAPONREADY(WRF_NOFIRE)
		W45K ZYXWVUTSRQPONMLKJIHGFEDCBA 1 A_WEAPONREADY(WRF_NOFIRE)
		W45J ZYXWVUTSRQPONMLKJIHGFEDCBA 1 A_WEAPONREADY(WRF_NOFIRE)
		W45I ZYXWVUTSRQPONMLKJIHGFEDCBA 1 A_WEAPONREADY(WRF_NOFIRE)

		    TNT1 A 0 A_GiveInventory("M4A1_sil_AltFire",1)


		Goto ReadySilencer










//Bot compatibility


	BotReady:
		
		W45F H 1 A_WeaponReady
		TNT1 A 0 A_REFIRE
		Loop

	BotFire:
	
		W45C A 1 A_GunFlash
		W45C B 1 A_WEAPONREADY(WRF_NOFIRE)
		W45C CD 1 A_WEAPONREADY(WRF_NOFIRE)


		W45C EFGHIJKLMN 1 A_Refire


		Goto Ready




  Altfire:
  TNT1 A 0 A_JumpIfInventory("M4A1_sil_AltFire",1,"AltfireSilencer")

    TNT1 A 0 A_JumpIfInventory("M4A1_SIL_Clip",25,"Ready")//20
    TNT1 A 0 A_JumpIfInventory("556mmAmmo",1,"ReloadStart")
    goto Ready

  AltfireSilencer:
    TNT1 A 0 A_JumpIfInventory("M4A1_SIL_Clip",25,"ReadySilencer")//20
    TNT1 A 0 A_JumpIfInventory("556mmAmmo",1,"ReloadStart")
    goto ReadySilencer

	ReloadStart:
	TNT1 A 0 A_JumpIfInventory("M4A1_sil_AltFire", 1, "ReloadStartSilencer")


		45WD ABCDEFGHIJKLMN 1 A_WEAPONREADY(WRF_NOFIRE|WRF_NOBOB)
		45WD O 1 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 0 A_PlaySound("m4a1_sil/Reload", 6)
		45WD PQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		45WE ABCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		45WF ABCDEFGHIJKLMNOPQRS 1 A_WEAPONREADY(WRF_NOFIRE)
		Goto ReloadAmmo
	
	
  ReloadAmmo:
    TNT1 A 0 A_GiveInventory("M4A1_SIL_Clip",1)
    TNT1 A 0 A_TakeInventory("556mmAmmo",1)
    TNT1 A 0 A_JumpIfInventory("M4A1_SIL_Clip",0,"ReloadEnd")
    TNT1 A 0 A_JumpIfInventory("556mmAmmo",1,"ReloadAmmo")
    goto ReloadEnd		

	ReloadEnd:
		45WF TUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		45WG ABCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE) //1
		45WH ABCDEFG 0 A_WEAPONREADY(WRF_NOFIRE) //1
		Goto Ready





	ReloadStartSilencer:


		W45D ABCDEFGHIJKLM 1 A_WEAPONREADY(WRF_NOFIRE|WRF_NOBOB)
		W45D NO 1 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 0 A_PlaySound("m4a1_sil/Reload", 6)
		W45D PQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W45E ABCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W45F ABCDEFGHIJKLMNOPQRS 1 A_WEAPONREADY(WRF_NOFIRE)
		Goto ReloadAmmoSilencer
	
	
  ReloadAmmoSilencer:
    TNT1 A 0 A_GiveInventory("M4A1_SIL_Clip",1)
    TNT1 A 0 A_TakeInventory("556mmAmmo",1)
    TNT1 A 0 A_JumpIfInventory("M4A1_SIL_Clip",0,"ReloadEndSilencer")
    TNT1 A 0 A_JumpIfInventory("556mmAmmo",1,"ReloadAmmoSilencer")
    goto ReloadEndSilencer		

	ReloadEndSilencer:
		W45F TUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W45G ABCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE) //1
		W45H ABCDE 0 A_WEAPONREADY(WRF_NOFIRE) //1
		Goto ReadySilencer




	Flash:
	TNT1 A 0 ACS_ExecuteAlways(799, 0, 0, 0, 0)
	TNT1 A 0 A_GiveInventory("CrosshairGrow", 6)
		TNT1 A 0 A_JumpIfInventory("M4A1_sil_AltFire",1,"FlashSilencer")
	TNT1 A 0 A_FireCustomMissile("WeaponSmokePuff",0,0,11,1)
		TNT1 A 0 Bright A_Light1
		TNT1 A 0 A_AlertMonsters
		TNT1 A 0 A_PlaySound ("m4a1_sil/FIRE")
		TNT1 A 0 A_PlaySound("m4a1_sil/Distant", 7)
		TNT1 A 0 A_FireCustomMissile("RifleCaseSpawn",5,0,12,-6)
	TNT1 A 0 A_JumpIfInventory("IsBot",1,"FlashFast")
        TNT1 A 0 BRIGHT A_FireCustomMissile("Tracer", frandom(-2.5,2.5), 0, 11, 0, 0, frandom(-2.5,2.5))
		TNT1 A 3 A_FireBullets(0.25, 0.25, 1, 125.0, "m4a1_sil_Bullet")//9.35
TNT1 A 0 A_SetPitch(pitch-0.5)
TNT1 A 0 A_SetANgle(angle-0.2)
TNT1 A 0 A_SetANgle(angle+0.1)
		Goto LightDone

	FlashSilencer:
	TNT1 A 0 A_FireCustomMissile("WeaponSMGSILENCEDSmokePuff",0,0,11,1)
		TNT1 A 0 A_PlaySound ("m4a1_sil/FIRE_sil")
		TNT1 A 0 A_PlaySound("m4a1_sil/Distant_sil", 7)
		TNT1 A 0 A_FireCustomMissile("RifleCaseSpawn",5,0,12,-6)
	TNT1 A 0 A_JumpIfInventory("IsBot",1,"FlashFast")
        TNT1 A 0 BRIGHT A_FireCustomMissile("Tracer", frandom(-2.5,2.5), 0, 11, 0, 0, frandom(-2.5,2.5))
		TNT1 A 3 A_FireBullets(0.25, 0.25, 1, 125.0, "m4a1_sil_Bullet")//9.35
TNT1 A 0 A_SetPitch(pitch-0.5)
TNT1 A 0 A_SetANgle(angle-0.2)
TNT1 A 0 A_SetANgle(angle+0.1)
		Goto LightDone

		
	FlashFast:
		TNT1 A 3 A_FireBullets(0.25, 0.25, 1, 125.0, "m4a1_sil_Bullet")//9.35
TNT1 A 0 A_SetPitch(pitch-0.5)
TNT1 A 0 A_SetANgle(angle-0.2)
TNT1 A 0 A_SetANgle(angle+0.1)
		Goto LightDone		
		
		
 	Spawn:
		W45Z A -1
		Stop
	}
}