ACTOR MP7Primary : Ammo
{
  Inventory.Amount 1
  Inventory.MaxAmount 40
  Ammo.BackpackAmount 1
  Ammo.BackpackMaxAmount 40
  Inventory.Icon "CLIPA0"
  +INVENTORY.IGNORESKILL
}

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

ACTOR "MP7" : Weapon 11456
{
  +WEAPON.NOAUTOAIM
  Weapon.BobStyle Smooth
  Weapon.BobSpeed 2.5
  Weapon.BobRangeX 0.5
  Weapon.BobRangeY 0.3
  Weapon.AmmoUse 0
  Weapon.AmmoGive2 20
  Weapon.AmmoType "MP7Primary"
  Weapon.AmmoType2 "MP7Secondary"
  Obituary "%o was turned into a pincushion by %k's MP7."
  Inventory.Pickupmessage "You picked up the MP7."
  Inventory.PickupSound "ppsh/pickup"
  Tag "Heckler + Koch MP7"
  +WEAPON.NOAUTOFIRE
  Scale 0.75
  States
  {
  Ready:
	PPSS A 0 A_JumpIfInventory("DoBlocking",1,"QuickMelee")
	PPSS A 0 A_JumpIfInventory("QuickGrenading",1,"ToGrenade")
	PPSS A 0 A_JumpIfInventory("IsReloading",1,"ReloadCheck")
    MP7I A 1 A_WeaponReady
    Goto Ready
  ToGrenade:
	TNT1 A 0 A_JumpIfInventory("QuickGrenading",1,2)
	TNT1 A 0 A_Print("Why the fuck are you getting this?")
	GoTo Ready
	TNT1 A 0 A_JumpIfInventory("Type97Primary", 1, 3)
	TNT1 A 0 A_TakeInventory("QuickGrenading",999)
	TNT1 A 0 A_Print("No Grenades Left!")
	GoTo Ready
	M7PS DCBA 1
	TNT1 A 0 A_TakeInventory("QuickGrenading",999)
	TNT1 AAA 3
	97FI ABC 1
	97FI D 1
	97FI D 1 A_WeaponReady(WRF_NOPRIMARY | WRF_NOSECONDARY)
	//97FI D 0 A_JumpIfInventory("QuickGrenading",1,1)
	//97FI D 0 A_ReFire
	97FI E 0 A_PlaySoundEx("type97/pinpull","SoundSlot6")
	97FI EG 1
	97FI I 3
	97FI J 0 A_PlaySoundEx("type97/throw","SoundSlot6")
	97FI JKL 1
	TNT1 A 0 A_TakeInventory("Type97Primary",1)
	FRGN A 0 A_FireCustomMissile("Thrown97",random(-200,200)/100.00,0,0,16,0,random(-150,150)/100.00)
	TNT1 AAA 3
	M7PS ABCD 1
	TNT1 A 0 A_TakeInventory("QuickGrenading",999)
	Goto Ready
  QuickMelee:
	M7PS DCBA 1
	TNT1 AAA 3
	MCFI E 1
	MCFI E 0 A_PlaySoundEx("machete/fire","Weapon")
	MCFI FG 1
    MCFI H 0 A_CustomPunch(2*random(1, 10), TRUE, 0, "ZTMeleePuff")
	MCFI HIJ 1
	MCFI K 2
	TNT1 AAA 3
	M7PS ABCD 1
	TNT1 A 0 A_TakeInventory("DoBlocking",1)
	Goto Ready
  ToReady:
	NULL A 0
	Goto Ready
	NULL AAA 0
	NULL A 0 A_PlaySoundEx("dryfire/smg","SoundSlot6")
	Goto Ready
  Deselect:
	 M7PS 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+4
  Select:
	 TNT1 A 0 A_SetCrosshair(17)
	 TNT1 AA 0 A_Raise
	 TNT1 A 1 A_WeaponReady
	 TNT1 A 0 A_PlaySoundEx("cloth/melee","SoundSlot6")
	 Goto SelectAnim
  SelectAnim:
	 M7PS ABCD 1 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 Goto Ready
  //=================================================================================
  // AMMO CHECKING
  //=================================================================================
  ReloadCheck:
	 TNT1 A 0 A_TakeInventory("IsReloading",1)
	 TNT1 A 0 A_JumpIfInventory("Perk_Commando",1,"RCP")
	 TNT1 A 0 A_JumpIfInventory("MP7Primary",20,"ToReady")
	 TNT1 A 0 A_JumpIfInventory("MP7Secondary",1,"BoltCheck")
	 Goto ToReady
  RCP:
	 TNT1 A 0 A_JumpIfInventory("PerkLevel",10,"RCP10")
	 TNT1 A 0 A_JumpIfInventory("MP7Primary",30,"ToReady")
	 TNT1 A 0 A_JumpIfInventory("MP7Secondary",1,"BoltCheck")
	 Goto ToReady
  RCP10:
	 TNT1 A 0 A_JumpIfInventory("MP7Primary",40,"ToReady")
	 TNT1 A 0 A_JumpIfInventory("MP7Secondary",1,"BoltCheck")
	 Goto ToReady
  //=================================================================================
  
  BoltCheck:
	 TNT1 A 0 A_TakeInventory("PullBolt",1)
	 TNT1 A 0 A_JumpIfInventory("MP7Primary",1,"ReloadAnim")
	 TNT1 A 0 A_GiveInventory("PullBolt",1)
	 Goto ReloadAnim
  
  ReloadAnim:
     9MRL A 0 ACS_ExecuteAlways(820,0,0,0,0)
	 M7RR ABCDEFGHI 1 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 M7RR J 2 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 M7RR K 3 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 M7RR L 2 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 M7RR M 0 A_PlaySoundEx("mp7/magout","SoundSlot6")
	 BPSS A 0 A_FireCustomMissile("PistolMagShooter",5,0,16,-3)
	 M7RR M 1 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 M7RR N 2 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 M7RR O 3 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 M7RR P 2 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 M7RR QR 1 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 M7RR M 0 A_PlaySoundEx("mp7/cloth","SoundSlot6")
	 M7RR STUVWXY 1 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 M7RR Z 2 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 M7RS A 3 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 M7RR M 0 A_PlaySoundEx("mp7/magin","SoundSlot6")
	 M7RS B 3 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 M7RS CDEFGHIJKLMN 1 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 TNT1 A 0 A_JumpIfInventory("PullBolt",1,"BoltPull")
	 M7RS OPQRS 1 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 TNT1 A 0 A_TakeInventory("IsReloading",1)
	 Goto CalculateAmmo
  BoltPull:
	 40RM A 0 A_TakeInventory("PullBolt",1)
	 MPRP ABCDEFG 1 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 MPRP G 3 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 MPRP H 1 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 MPRP H 0 A_PlaySoundEx("mp7/boltback","SoundSlot6")
	 MPRP H 1 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 MPRP IJKL 1 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 MPRP M 2 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 MPRP N 3 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 MPRP O 0 A_PlaySoundEx("mp7/boltfwd","SoundSlot6")
	 MPRP N 1 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 MPRP O 3 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 MPRP P 2 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 MPRP QRST 1 A_WeaponReady(WRF_NOSWITCH | WRF_NOFIRE)
	 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("MP7Secondary",1,2)
	 Goto Ready
	 TNT1 AAA 0
	 TNT1 A 0 A_JumpIfInventory("MP7Primary",20,"ToReady")
	 TNT1 A 0 A_TakeInventory("MP7Secondary",1)
	 TNT1 A 0 A_GiveInventory("MP7Primary",1)
	 Loop
  CalculateAmmoPerk:
     TNT1 A 0 A_JumpIfInventory("PerkLevel",10,"CalculateAmmoPerk10")
     TNT1 A 0 A_JumpIfInventory("MP7Secondary",1,2)
	 Goto Ready
	 TNT1 AAA 0
	 TNT1 A 0 A_JumpIfInventory("MP7Primary",30,"ToReady")
	 TNT1 A 0 A_TakeInventory("MP7Secondary",1)
	 TNT1 A 0 A_GiveInventory("MP7Primary",1)
	 Loop
  CalculateAmmoPerk10:
     TNT1 A 0 A_JumpIfInventory("MP7Secondary",1,2)
	 Goto Ready
	 TNT1 AAA 0
	 TNT1 A 0 A_JumpIfInventory("MP7Primary",40,"ToReady")
	 TNT1 A 0 A_TakeInventory("MP7Secondary",1)
	 TNT1 A 0 A_GiveInventory("MP7Primary",1)
	 Loop
  //=================================================================================
  Fire:
	 PPFI A 0 A_JumpIfInventory("MP7Primary",1,1)
	 Goto ToReady+2
	 PPFI A 0 A_TakeInventory("MP7Primary",1)
	 PPFI A 0 A_FireBullets (ACS_ExecuteWithResult(566,4,0,0), ACS_ExecuteWithResult(566,4,0,0), 1, 5, "BulletPuff2")
	 BPSS A 0 A_FireCustomMissile("LongRifleCaseSpawn",5,0,16,-3)
	 PPFI A 0 A_PlaySound("mp7/fire", CHAN_WEAPON)
	 TNT1 A 0 A_SpawnItemEx("ShooterLight",0,0,0)
	 PPFI A 0 A_SetPitch(pitch-0.5)
	 PPFI A 0 A_Jump(255,"Flash1")
	 Goto Flash1
  Flash1:
	 MP7I B 1 bright A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 Goto FireEnd
  Flash2:
	 MP40 D 1 bright A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 Goto FireEnd
  Flash3:
	 MP40 E 1 bright A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 Goto FireEnd
  FireEnd:
	 PPFI A 0 A_SetPitch(pitch+0.4)
	 MP7I C 1 A_WeaponReady(WRF_NOFIRE | WRF_NOSWITCH)
	 PPFI A 0 A_JumpIfInventory("SemiAutomatic",1,"Ready")
	 PPFI A 0 A_ReFire
	 Goto Ready
  Spawn:
    PPSH F -1
    Stop
  }
}