ACTOR PDTranquilizer : Weapon
{
  Weapon.Kickback 100
  Scale 0.050
  
  Tag "Tranquilizer"
        Weapon.Ammotype1 "TranquilizerClip"
  Weapon.Ammotype2 "PDSedatives"
    Weapon.AmmoUse1 1
  Weapon.AmmoGive1 0
  Weapon.AmmoGive2 8
  +WEAPON.AMMO_OPTIONAL
  Inventory.PickupMessage "Picked up a Tranquilizer."
  Obituary  "%k cut short %o's cry with a Tranquilizer."
  	Inventory.PickupSound "PerfectDark/Items/PickupWeapon"
  States
  {
  Spawn:
    TKB4 A -1
    Loop
  Ready:
  TNT1 A 0 A_PlaySound ("PerfectDark/Weapons/TranquilizerUp","Weapon")
    TL21 ABCDEFGHIJK 1
    TL21 L -1 A_WeaponReady(WRF_ALLOWRELOAD)
	goto ReloadCheck
	TL21 L 1 A_WeaponReady(WRF_ALLOWRELOAD)
    Goto Ready+8
	
	  ReloadCheck:
	 KLBG A 0 A_JumpIfInventory("TranquilizerClip",8,2)
	 KLBG A 0 A_JumpIfInventory("PDSedatives",1,"ReloadStart")
	 KLBG A 0
	 Goto Ready+8

  ReloadStart:
	 KLBR A 0 A_PlayWeaponSound("PerfectDark/Weapons/TranquilizerReload")
     TL21 YZ 1
	 TL22 ABCDEFGHIJKLMNOPQRSTUVXYZ 1
	 TL23 ABCDEFGH 1
	 goto ReloadAmmo

  ReloadAmmo:
	 TNT1 A 0 A_TakeInventory("PDSedatives",1)
	 TNT1 A 0 A_GiveInventory("TranquilizerClip",1)
	 TNT1 A 0 A_JumpIfInventory("TranquilizerClip",8,"ReloadDone")
	 TNT1 A 0 A_JumpIfInventory("PDSedatives",1,"ReloadAmmo")
	 goto ReloadDone
	 
	 ReloadDone:
	 TL23 IJKLMNOPQRSTU 1
	 Goto Ready+8
	
  Deselect:
    TL21 UVX 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/Tranquilizer","Weapon")
    TL21 M 1 BRIGHT A_FireBullets(2, 2, -1, 10, "BulletPuff",FBF_USEAMMO)
    TL21 NOPQR 1
	TL21 S 1
	TL21 T 2 A_REFIRE
    Goto Ready+8
	Altfire:
	 NULL A 0 A_JumpIfInventory("TranquilizerClip",4,1)
	goto Ready+10
	TL23 UVXYZ 1
	TL24 ABC 1
	TNT1 A 0 A_PlaySound ("PerfectDark/Weapons/TranquilizerAlt","Weapon")
	TNT1 A 0 A_TakeInventory("TranquilizerClip",4,TIF_NOTAKEINFINITE)
	MK45 T 0 A_CustomPunch(100, false, 0, "PDHitPuff")
	TL24 DEFGHIJKLMNOPQRSTUVXYZ 1
	Goto Ready+10
		Reload:
		TK04 A 0
		goto ReloadCheck
  }
}

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

ACTOR PDTranquilizerPickup : Custominventory
{
   Scale 0.050
  Inventory.PickupMessage "Picked up a Tranquilizer."
  	Inventory.PickupSound "PerfectDark/Items/PickupWeapon"
   States
   {
   Spawn:
	  TKB4 A -1
	  loop
   Pickup:
	  TNT1 A 0 A_GiveInventory("PDTranquilizer")
	  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
   }
}
