ACTOR M16Primary : Ammo
{
  Inventory.Amount 0
  Inventory.MaxAmount 60
  Ammo.BackpackAmount 0
  Ammo.BackpackMaxAmount 60
  Inventory.Icon "CLIPA0"
  +INVENTORY.IGNORESKILL
}

ACTOR M16Secondary : Ammo
{
  Inventory.PickupMessage "You picked up a mag of M16A4 ammunition." // "Picked up a clip."
  Inventory.PickupSound "bullpup/magin"
  Inventory.Amount 60
  Inventory.MaxAmount 270
  Ammo.BackpackAmount 60
  Ammo.BackpackMaxAmount 270
  Inventory.Icon "CLIPA0"
  +INVENTORY.IGNORESKILL
  States
  {
  Spawn:
    CLIP A -1
    Stop
  }
}

ACTOR M16Flash : Inventory
{
	Inventory.MaxAmount 2
}

ACTOR M16BurstCounter : Inventory
{
	Inventory.MaxAmount 3
}

ACTOR "M16A4 Rifle" : Weapon 11500
{
  Weapon.AmmoUse 0
  Weapon.AmmoGive2 70
  Weapon.AmmoType "M16Primary"
  Weapon.AmmoType2 "M16Secondary"
  Obituary "\cJ%k \cG> \cKM16A4 \cG> \cJ%o"
  Inventory.Pickupmessage "You picked up the M16A4 Rifle."
  Inventory.PickupSound "ppsh/pickup"
	//$Category ZT2 - Weapons
	//$Title PPSH-41
	//$Sprite PPSHF0
  Tag "M16A4 Rifle"
  Scale 0.75
  +WEAPON.NOAUTOFIRE
  Decal Bullet
  States
  {
  Ready:
	PPSS A 0 A_PlaySoundEx("m16/select","SoundSlot6")
	M6SS ABCDE 1
	PPSS A 0 A_JumpIfInventory("DoBlocking",1,"QuickMelee")
	PPSS A 0 //A_JumpIfInventory("QuickGrenading",1,"ToGrenade")
	PPSS A 0 A_JumpIfInventory("IsReloading",1,"ReloadCheck")
    M6ID A 1 A_WeaponReady
    Goto Ready+6
  ToGrenade:
	PPSS A 0 A_SelectWeapon("Type-97 Grenade")
	Goto Deselect
  QuickMelee:
	PPBL A 1
	PPBL B 0 A_PlaySoundEx("fist/swing","Weapon")
	PPBL BC 1
	PPBL D 0 A_CustomPunch (random(4,5),1,0,"BlockPuff")
	PPBL D 2
	PPBL E 4
	PPBL DCBA 2
	PPBL A 0 A_TakeInventory("DoBlocking",1)
	Goto Ready+6
  ToReady:
	NULL A 0 A_TakeInventory("M16BurstCounter",3)
	NULL A 0
	Goto Ready+6
	NULL A 0 A_TakeInventory("M16BurstCounter",3)
	NULL AAA 0
	NULL A 0 A_PlaySoundEx("dryfire/smg","SoundSlot6")
	Goto Ready+6
  Deselect:
	 M6SS EDCBA 1
	 PPFI A 0 A_TakeInventory("HasFiringModes",1)
	 PPFI A 0 A_TakeInventory("SemiAutomatic",1)
     TNT1 AAAAAAAAAA 0 A_Lower
	 TNT1 A 1 A_Lower
     Goto Deselect+7
  Select:
	 TNT1 A 0 A_SetCrosshair(17)
	 TNT1 A 0 A_GiveInventory("HasFiringModes",1)
     TNT1 A 0 A_Raise
     Wait
  //===========================================================================
  // RELOAD CHECK FOR PERKS
  //===========================================================================
  ReloadCheck:
	 TNT1 A 0 A_TakeInventory("IsReloading",1)
	 TNT1 A 0 A_JumpIfInventory("Perk_Commando",1,"RCP")
	 TNT1 A 0 A_JumpIfInventory("M16Primary",30,"ToReady")
	 TNT1 A 0 A_JumpIfInventory("M16Secondary",1,"BoltCheck")
	 Goto ToReady
  RCP:
	 TNT1 A 0 A_JumpIfInventory("Perk_Level",10,"RCP10")
	 TNT1 A 0 A_JumpIfInventory("M16Primary",45,"ToReady")
	 TNT1 A 0 A_JumpIfInventory("M16Secondary",1,"BoltCheck")
	 Goto ToReady
  RCP10:
	 TNT1 A 0 A_JumpIfInventory("M16Primary",60,"ToReady")
	 TNT1 A 0 A_JumpIfInventory("M16Secondary",1,"BoltCheck")
	 Goto ToReady
  //===========================================================================
  BoltCheck:
	 TNT1 A 0 A_JumpIfInventory("M16Primary",1,"ReloadAnim")
	 TNT1 A 0 A_GiveInventory("PullBolt",1)
	 Goto ReloadAnim
  ReloadAnim:
	 9MRL A 0 A_JumpIfInventory("M16Primary",1,"NoPull")
	 Goto BoltPull
  BoltPull:
	 9MRL A 0 A_GiveInventory("PullBolt",1)
  NoPull:
     9MRL A 0 ACS_ExecuteAlways(820,0,0,0,0)
	 M6RL ABCDE 1 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 M6RL F 5 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 
	 M6RL E 0 A_PlaySoundEx("m16/magout","SoundSlot6")
	 
	 M6RL GHIJKLMNO 1 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 M6RL P 8 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 M6RL QRSTUVWXY 1 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 
	 // Grab sound here
	 M6RL E 0 A_PlaySoundEx("m16/grab","SoundSlot6")
	 
	 M6RL Z 3 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 M6RM A 2 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 M6RM BCDEFG 1 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 M6RM H 4 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 M6RM I 1 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 
	 M6RL E 0 A_PlaySoundEx("m16/magin","SoundSlot6")
	 
	 M6RM J 1 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 
	 Goto CalculateAmmo
  CalculateAmmo:
     TNT1 A 0 A_JumpIfInventory("M16Secondary",1,2)
	 Goto ReloadEnd
	 TNT1 AAA 0
	 TNT1 A 0 A_JumpIfInventory("M16Primary",30,"ReloadEnd")
	 TNT1 A 0 A_TakeInventory("M16Secondary",1)
	 TNT1 A 0 A_GiveInventory("M16Primary",1)
	 Loop
	 
  ReloadEnd:
	 
	 M6RM K 2 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 M6RM L 3 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 M6RM M 2 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 M6RM NOPQ 1 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 TNT1 A 0 A_TakeInventory("IsReloading",1)
	 M6RM A 0 A_JumpIfInventory("PullBolt",1,"DoBoltPull")
	 Goto ToReady
	 
  DoBoltPull:
	TNT1 A 0 A_TakeInventory("PullBolt",1)
	M6RM RSTUVWX 1 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	M6BP H 0 A_PlaySoundEx("m16/boltback","SoundSlot6")
	M6RM YZ 1 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	M6RN A 1 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	M6RN B 3 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	M6RN C 3 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	M6BP H 0 A_PlaySoundEx("m16/boltfwd","SoundSlot6")
	M6RN C 2 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	M6RN E 3 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	M6RN F 2 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	M6RN GH 1 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 TNT1 A 0 A_TakeInventory("PullBolt",1)
	 TNT1 A 0 A_TakeInventory("IsReloading",1)
	 Goto ToReady
  Fire:
	 PPFI A 0 A_JumpIfInventory("M16Primary",1,1)
	 Goto ToReady+2
	 PPFI A 0 A_TakeInventory("M16Primary",1)
	 PPFI A 0 A_GiveInventory("M16BurstCounter",1)
	 PPFI A 0 A_FireBullets (ACS_ExecuteWithResult(566,2,0,0), ACS_ExecuteWithResult(566,2,0,0), 1, 5, "BulletPuff2")
	 BPSS A 0 A_FireCustomMissile("LongRifleCaseSpawn",5,0,16,-3)
	 PPFI A 0 A_PlaySound("m16/fire", CHAN_WEAPON)
	 TNT1 A 0 A_SpawnItemEx("ShooterLight",0,0,0)
	 PPFI A 0 A_SetPitch(pitch-1.5)
	 PPFI A 0 A_JumpIfInventory("M16Flash",2,"Flash3")
	 PPFI A 0 A_JumpIfInventory("M16Flash",1,"Flash2")
  Flash1:
	 M6FI A 0 A_GiveInventory("M16Flash",1)
	 M6FI A 1 bright A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 Goto FinishShoot
  Flash2:
	 M6FI A 0 A_GiveInventory("M16Flash",1)
	 M6FI C 1 bright A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 Goto FinishShoot
  Flash3:
	 M6FI A 0 A_TakeInventory("M16Flash",2)
	 M6FI D 1 bright A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 Goto FinishShoot
  FinishShoot:
	 PPFI A 0 A_SetPitch(pitch+1.0)
	 M6FI B 2 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 PPFI A 0 A_JumpIfInventory("M16BurstCounter",3,"ToReady")
	 PPFI A 0 A_JumpIfInventory("SemiAutomatic",1,"ToReady")
	 PPFI A 0 A_ReFire
	 Goto Ready+6
  AltFire:
	 PPFI A 0 A_JumpIfInventory("SemiAutomatic",1,"ToFull")
	 Goto ToSemi
  ToFull:
	 PPFI A 0 A_TakeInventory("SemiAutomatic",1)
	 TNT1 A 0 A_SetCrosshair(17)
	 PPFI A 0 A_Print("Switched to Fully Automatic mode.")
	 Goto Ready+6
  ToSemi:
	TNT1 A 0 A_SetCrosshair(18)
	 PPFI A 0 A_GiveInventory("SemiAutomatic",1)
	 PPFI A 0 A_Print("Switched to Semi Automatic mode.")
	 Goto Ready+6
  Spawn:
    M16W A -1
    Stop
  }
}