ACTOR MP5Primary : Ammo
{
  Inventory.Amount 1
  Inventory.MaxAmount 64
  Inventory.Icon "CLIPA0"
  +INVENTORY.IGNORESKILL
}

ACTOR MP5Secondary : Ammo
{
  Inventory.PickupMessage "You picked up a magazine of MP5 ammunition." // "Picked up a clip."
  Inventory.PickupSound "bullpup/magin"
  Inventory.Amount 32
  Inventory.MaxAmount 400
  Ammo.BackpackAmount 96
  Ammo.BackpackMaxAmount 400
  Inventory.Icon "CLIPA0"
  +INVENTORY.IGNORESKILL
  States
  {
  Spawn:
    CLIP A -1
    Stop
  }
}

ACTOR "MP5 Submachine Gun" : Weapon 11506
{
  Weapon.AmmoUse 0
  Weapon.AmmoGive2 70
  Weapon.AmmoType "MP5Primary"
  Weapon.AmmoType2 "MP5Secondary"
  Obituary "\cJ%k \cG> \cKMP5 \cG> \cJ%o"
  Inventory.Pickupmessage "You picked up the MP5 SMG."
  Inventory.PickupSound "mp5/pickup"
	//$Category ZT2 - Weapons
	//$Title MP5 Submachine Gun
	//$Sprite PPSHF0
  Tag "MP5 Submachine Gun"
  +WEAPON.NOAUTOFIRE
  States
  {
  Ready:
	PPSS A 0 A_PlaySoundEx("mp5/select","SoundSlot6")
	MPSS ABCD 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")
    MPID A 1 A_WeaponReady
    Goto Ready+5
  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+5
  ToReady:
	NULL A 0
	Goto Ready+5
	NULL AAA 0
	NULL A 0 A_PlaySoundEx("dryfire/smg","SoundSlot6")
	Goto Ready+5
  Deselect:
	 MPSS DCBA 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+6
  Select:
     TNT1 A 0 A_SetCrosshair(17)
	 TNT1 A 0 A_GiveInventory("HasFiringModes",1)
     TNT1 A 0 A_Raise
     Wait
  //===========================================================================
  // RELOAD CHECKING
  //===========================================================================
  ReloadCheck:
	 TNT1 A 0 A_TakeInventory("IsReloading",1)
	 TNT1 A 0 A_JumpIfInventory("Perk_Commando",1,"RCP")
	 TNT1 A 0 A_JumpIfInventory("MP5Primary",32,"ToReady")
	 TNT1 A 0 A_JumpIfInventory("MP5Secondary",1,"ReloadAnim")
	 Goto ToReady
  RCP:
	 TNT1 A 0 A_JumpIfInventory("PerkLevel",10,"RCP10")
	 TNT1 A 0 A_JumpIfInventory("MP5Primary",48,"ToReady")
	 TNT1 A 0 A_JumpIfInventory("MP5Secondary",1,"ReloadAnim")
	 Goto ToReady
  RCP10:
	 TNT1 A 0 A_JumpIfInventory("MP5Primary",64,"ToReady")
	 TNT1 A 0 A_JumpIfInventory("MP5Secondary",1,"ReloadAnim")
	 Goto ToReady
  //===========================================================================
  ReloadAnim:
     9MRL A 0 ACS_ExecuteAlways(820,0,0,0,0)
	 MPRL ABCDEFGH 1 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 MPRL I 8 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 MPRL K 0 A_PlaySoundEx("mp5/magout","SoundSlot6")
	 MPRL J 2 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 MPRL KL 1 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 MPRL MNO 2 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 MPRL PQR 1 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 MPRL S 8 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 MPRL TU 1 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 MPRL K 0 A_PlaySoundEx("mp5/magin","SoundSlot6")
	 MPRL V 2 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 MPRL W 4 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 MPRL X 3 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 MPRL YZ 2 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 MPRL IHGFEDCBA 1 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 TNT1 A 0 A_TakeInventory("IsReloading",1)
	 Goto CalculateAmmo
  //===========================================================================
  // AMMO CALCULATION
  //===========================================================================
  CalculateAmmo:
	 TNT1 A 0 A_JumpIfInventory("Perk_Commando",1,"CalculateAmmoPerk")
     TNT1 A 0 A_JumpIfInventory("MP5Secondary",1,2)
	 Goto Ready+5
	 TNT1 AAA 0
	 TNT1 A 0 A_JumpIfInventory("MP5Primary",32,"ToReady")
	 TNT1 A 0 A_TakeInventory("MP5Secondary",1)
	 TNT1 A 0 A_GiveInventory("MP5Primary",1)
	 Loop
  CalculateAmmoPerk:
	 TNT1 A 0 A_JumpIfInventory("PerkLevel",10,"CalculateAmmoPerk10")
     TNT1 A 0 A_JumpIfInventory("MP5Secondary",1,2)
	 Goto Ready+5
	 TNT1 AAA 0
	 TNT1 A 0 A_JumpIfInventory("MP5Primary",48,"ToReady")
	 TNT1 A 0 A_TakeInventory("MP5Secondary",1)
	 TNT1 A 0 A_GiveInventory("MP5Primary",1)
	 Loop
  CalculateAmmoPerk10:
     TNT1 A 0 A_JumpIfInventory("MP5Secondary",1,2)
	 Goto Ready+5
	 TNT1 AAA 0
	 TNT1 A 0 A_JumpIfInventory("MP5Primary",64,"ToReady")
	 TNT1 A 0 A_TakeInventory("MP5Secondary",1)
	 TNT1 A 0 A_GiveInventory("MP5Primary",1)
	 Loop
  //===========================================================================
  Fire:
	 PPFI A 0 A_JumpIfInventory("MP5Primary",1,1)
	 Goto ToReady+2
	 PPFI A 0 A_TakeInventory("MP5Primary",1)
	 PPFI A 0 A_FireBullets (ACS_ExecuteWithResult(566,3,0,0), ACS_ExecuteWithResult(566,3,0,0), 1, 5, "BulletPuff2")
	 BPSS A 0 A_FireCustomMissile("LongRifleCaseSpawn",5,0,16,-3)
	 PPFI A 0 A_PlaySound("mp5/fire", CHAN_WEAPON)
	 TNT1 A 0 A_SpawnItemEx("ShooterLight",0,0,0)
	 PPFI A 0 A_SetPitch(pitch+0.5)
	 MPFI A 1 bright A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 PPFI A 0 A_SetPitch(pitch-0.4)
	 MPFI B 2 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 PPFI A 0 A_JumpIfInventory("SemiAutomatic",1,"ToReady")
	 PPFI A 0 A_ReFire
	 Goto Ready+5
  AltFire:
	 PPFI A 0 A_JumpIfInventory("SemiAutomatic",1,"ToFull")
	 Goto ToSemi
  ToFull:
     TNT1 A 0 ACS_ExecuteAlways(82,0,17,0,0)
	 PPFI A 0 A_TakeInventory("SemiAutomatic",1)
	 PPFI A 0 A_Print("Switched to Fully Automatic mode.")
	 Goto Ready+5
  ToSemi:
     TNT1 A 0 ACS_ExecuteAlways(82,0,18,0,0)
	 PPFI A 0 A_GiveInventory("SemiAutomatic",1)
	 PPFI A 0 A_Print("Switched to Semi Automatic mode.")
	 Goto Ready+5
  Spawn:
    MP5W I -1
    Stop
  }
}