ACTOR PDPP9i : Weapon
{
  Weapon.Kickback 100
  Scale 0.050
  
  Tag "PP9i"
        Weapon.Ammotype1 "PP9iClip"
  Weapon.Ammotype2 "PDPistolAmmo"
    Weapon.AmmoUse1 1
  Weapon.AmmoGive1 0
  Weapon.AmmoGive2 7
  +WEAPON.AMMO_OPTIONAL
  Inventory.PickupMessage "Picked up a PP9i."
  Obituary  "%k's PP9i went off in %o's face."
  	Inventory.PickupSound "PerfectDark/Items/PickupWeapon"
  States
  {
  Spawn:
    TKB4 H -1
    Loop
  Ready:
  TNT1 A 0 A_PlaySound ("PerfectDark/Weapons/WeaponDraw","Weapon")
    TL34 A 2 
    TL34 B 2
    TL34 C 2
    TL34 D 2
    TL34 E 2
    TL34 F -1 A_WeaponReady(WRF_ALLOWRELOAD)
	goto ReloadCheck
	TL34 F 1 A_WeaponReady(WRF_ALLOWRELOAD)
    Goto Ready+7
	
	  ReloadCheck:
	 KLBG A 0 A_JumpIfInventory("PP9iClip",7,2)
	 KLBG A 0 A_JumpIfInventory("PDPistolAmmo",1,"ReloadStart")
	 KLBG A 0
	 Goto Ready+7

  ReloadStart:
	 KLBR A 0 A_PlayWeaponSound("PerfectDark/Weapons/GoldenEyeReload")
     TL34 UVX 2
	 TNT1 A 10
	 goto ReloadAmmo

  ReloadAmmo:
	 TNT1 A 0 A_TakeInventory("PDPistolAmmo",1)
	 TNT1 A 0 A_GiveInventory("PP9iClip",1)
	 TNT1 A 0 A_JumpIfInventory("PP9iClip",7,"ReloadDone")
	 TNT1 A 0 A_JumpIfInventory("PDPistolAmmo",1,"ReloadAmmo")
	 goto ReloadDone
	 
	 ReloadDone:
	 TL34 YZ 2
	 TL35 ABCD 1
	 Goto Ready+7
	
  Deselect:
    TL34 RST 2
    TK08 A 0 A_Lower
    wait
  Select: 
    TK08 A 0 A_Raise 
    Loop  
  Fire: 
  KLBG A 0 A_JumpIfNoAmmo("ReloadCheck")
 	TNT1 A 0 A_PlaySound ("PerfectDark/Weapons/PP9i","Weapon")
    TL34 G 1 BRIGHT A_FireBullets(1, 1, 1, 8, "BulletPuff",FBF_USEAMMO)
	PP7G B 0 BRIGHT A_SpawnItemEx ("PDBulletCasing", 30,cos(pitch)*12,sin(-pitch)*10+30, frandom(0.5,1.2),frandom(0.5,1.2),frandom(1.5,2.5))
    TL34 HIJK 2
	TL34 L 1
	TL34 M 1
	TL34 NOPQ 2 A_REFIRE
    Goto Ready+7
		Reload:
		TK04 A 0
		goto ReloadCheck
  }
}

ACTOR PP9iClip : Ammo
{
Inventory.MaxAmount 7 // size of the clip
Ammo.BackpackAmount 0
Ammo.BackpackMaxAmount 7 //MUST be the same as Inventory.MaxAmmount
+INVENTORY.IGNORESKILL
}

ACTOR PDPP9iPickup : Custominventory
{
   Scale 0.050
  Inventory.PickupMessage "Picked up a PP9i."
  	Inventory.PickupSound "PerfectDark/Items/PickupWeapon"
   States
   {
   Spawn:
	  TKB4 H -1
	  loop
   Pickup:
	  TNT1 A 0 A_GiveInventory("PDPP9i")
	  TNT1 A 0 A_JumpIfInventory("PlayingasPerfectKirby",1,"PickupPerfectKirby")
	  TNT1 A 0 A_JumpIfInventory("PlayingasRED",1,"PickupRED")
	  stop
	  PickupPerfectKirby:
	 	TNT1 A 0 A_PlaySound ("PerfectDark/Player/PerfectKirby/PerfectKirbyWeaponPickup")
		Stop
	  PickupRED:
	 	TNT1 A 0 A_PlaySound ("PerfectDark/Player/RED/REDWeaponPickup")
		Stop
   }
}
