ACTOR TWINEGoldengun : Weapon
{
  Weapon.Kickback 100
      Weapon.Ammotype1 "GoldenGunClip"
  Weapon.Ammotype2 "TWINEGoldenAmmo"
    Weapon.AmmoUse1 1
  Weapon.AmmoGive1 0
  Weapon.AmmoGive2 5
  +WEAPON.AMMO_OPTIONAL
  Tag "Golden Gun"
  Inventory.PickupMessage "Golden Gun"
  Obituary  "%k sent a golden bullet into %o's face."
  	Inventory.PickupSound "TWINE/Items/Pickup"
  States
  {
  Spawn:
    TKA1 Y -1
    Loop
  Ready:
  TNT1 A 0 A_PlaySound ("TWINE/Weapons/WeaponupPSX","Weapon")
    TI02 A 2 
    TI02 B 2
    TI02 C 2
    TI02 D 2
    TI02 EF 2
    TI02 G -1 A_WeaponReady(WRF_ALLOWRELOAD)
	goto ReloadCheck
	TI02 G 1 A_WeaponReady(WRF_ALLOWRELOAD)
    Goto Ready+6
	
		  ReloadCheck:
	 KF7S A 0 A_JumpIfInventory("GoldenGunClip",5,2)
	 KF7S A 0 A_JumpIfInventory("TWINEGoldenAmmo",1,"ReloadAboutToBegin")
	 KF7S A 0
	 goto Ready+6
	 
	ReloadAboutToBegin:
  TNT1 A 0 A_JumpIfInventory("PlayingasEllis",1,"ReloadSoundEllis")
  TNT1 A 0 A_JumpIfInventory("PlayingasCoach",1,"ReloadSoundCoach")
  TNT1 A 0 A_JumpIfInventory("PlayingasFrancis",1,"ReloadSoundFrancis")
    TNT1 A 0 A_JumpIfInventory("PlayingasBill",1,"ReloadSoundBill")
  TNT1 A 0 A_JumpIfInventory("PlayingasLouis",1,"ReloadSoundLouis")
  TNT1 A 0 A_JumpIfInventory("PlayingasZoey",1,"ReloadSoundZoey")
    TNT1 A 0 A_JumpIfInventory("PlayingasNick",1,"ReloadSoundNick")
  TNT1 A 0 A_JumpIfInventory("PlayingasRochelle",1,"ReloadSoundRochelle")
	 goto ReloadStart
	 
    	ReloadSoundEllis:
	 	TNT1 A 0 A_PlaySound ("L4D/Ellis/Reload","Weapon")
	 goto ReloadStart
	 
	  ReloadSoundCoach:
	 	TNT1 A 0 A_PlaySound ("L4D/Coach/Reload","Weapon")
	 goto ReloadStart
	 
	 ReloadSoundFrancis:
	 	TNT1 A 0 A_PlaySound ("L4D/Francis/Reload","Weapon")
	 goto ReloadStart
	 
	 	 ReloadSoundBill:
	 	TNT1 A 0 A_PlaySound ("L4D/Bill/Reload","Weapon")
	 goto ReloadStart
	 
	 	 ReloadSoundLouis:
	 	TNT1 A 0 A_PlaySound ("L4D/Louis/Reload","Weapon")
	 goto ReloadStart
	 
	 	 ReloadSoundZoey:
	 	TNT1 A 0 A_PlaySound ("L4D/Zoey/Reload","Weapon")
	 goto ReloadStart
	 
	 	 ReloadSoundNick:
	 	TNT1 A 0 A_PlaySound ("L4D/Nick/Reload","Weapon")
	 goto ReloadStart
	 
	 	 ReloadSoundRochelle:
	 	TNT1 A 0 A_PlaySound ("L4D/Rochelle/Reload","Weapon")
	 goto ReloadStart

  ReloadStart:
	 TK04 A 0 A_PlayWeaponSound("TWINE/Weapons/P2KReload")
	 TI02 STUVX 1
	 TNT1 AAAAAAAAAAA 1
	 TK04 A 0 A_PlayWeaponSound("TWINE/Weapons/P2KReload2")
	 TNT1 AAAAAAAAAAAAA 1
	 TNT1 A 0
	 goto ReloadAmmo

  ReloadAmmo:
	 TNT1 A 0 A_TakeInventory("TWINEGoldenAmmo",1)
	 TNT1 A 0 A_GiveInventory("GoldenGunClip",1)
	 TNT1 A 0 A_JumpIfInventory("GoldenGunClip",5,"ReloadDone")
	 TNT1 A 0 A_JumpIfInventory("TWINEGoldenAmmo",1,"ReloadAmmo")
	 goto ReloadDone

  ReloadDone:
	 TNT1 A 0
	 TI02 X 1
	 TI02 ABCDEFG 1
	 goto Ready+6
	
  Deselect:
  TNT1 A 0 A_PlaySound ("TWINE/Weapons/Switch","Weapon")
    TI02 S 2
    TI02 TUVX 2
    TI02 A 0 A_Lower
    wait
  Select: 
    TK08 A 0 A_Raise 
    Loop  
  Fire: 
  TK04 A 0 A_JumpIfNoAmmo("ReloadCheck")
 	TNT1 A 0 A_PlaySound ("TWINE/Weapons/P2K","Weapon")
	TNT1 A 0 A_SpawnItemEx("TWINEBulletCasing", 30,cos(pitch)*12,sin(-pitch)*10+30, frandom(0.5,1.2),frandom(0.5,1.2),frandom(1.5,2.5))
    TI02 H 1 BRIGHT A_FireBullets(1.0, 1, 1, 300, "BulletPuff")
	TI02 HI 1
	TI02 JKLMNOPQR 1
	TI02 G 50
    Goto Ready+7
		Reload:
		TK04 A 0
		goto ReloadCheck
  }
}

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

ACTOR TWINEGoldengunPickup : Custominventory
{
  Inventory.PickupMessage "Golden Gun"
  	Inventory.PickupSound "TWINE/Items/Pickup"
   States
   {
   Spawn:
    TKA1 Y -1
	  loop
   Pickup:
	  TNT1 A 0 A_GiveInventory("TWINEGoldengun")
	   TNT1 A 0 A_JumpIfInventory("PlayingasEllis",1,"PickupEllis")
	   TNT1 A 0 A_JumpIfInventory("PlayingasCoach",1,"PickupCoach")
	   TNT1 A 0 A_JumpIfInventory("PlayingasFrancis",1,"PickupFrancis")
	   TNT1 A 0 A_JumpIfInventory("PlayingasBill",1,"PickupBill")
	   TNT1 A 0 A_JumpIfInventory("PlayingasLouis",1,"PickupLouis")
	   TNT1 A 0 A_JumpIfInventory("PlayingasZoey",1,"PickupZoey")
       TNT1 A 0 A_JumpIfInventory("PlayingasNick",1,"PickupNick")
       TNT1 A 0 A_JumpIfInventory("PlayingasRochelle",1,"PickupRochelle")
	  stop
	  PickupEllis:
	 	TNT1 A 0 A_PlaySound ("L4D/Ellis/takepistol")
		Stop
		PickupCoach:
	 	TNT1 A 0 A_PlaySound ("L4D/Coach/takepistol")
		Stop
		PickupFrancis:
	 	TNT1 A 0 A_PlaySound ("L4D/Francis/takepistol")
		Stop
			    PickupBill:
	 	TNT1 A 0 A_PlaySound ("L4D/Bill/takepistol")
		Stop
		PickupLouis:
	 	TNT1 A 0 A_PlaySound ("L4D/Louis/takepistol")
		Stop
		PickupZoey:
	 	TNT1 A 0 A_PlaySound ("L4D/Zoey/takepistol")
		Stop
	    PickupNick:
	 	TNT1 A 0 A_PlaySound ("L4D/Nick/takepistol")
		Stop
		PickupRochelle:
	 	TNT1 A 0 A_PlaySound ("L4D/Rochelle/takepistol")
		Stop
   }
}