ACTOR Weapon_Glock22 : Weapon_Base
{
  Weapon.AmmoUse1 1
  Weapon.AmmoGive1 20
  Weapon.AmmoType1 "Weapon_Glock22_Mag"
  Obituary "$OB_MPPISTOL"
  +WEAPON.AMMO_OPTIONAL
  +WEAPON.NOAUTOFIRE

  Weapon.SlotNumber 2
  
  States
  {
  Ready:
	PISG A 0
	PISG A 0 A_PlaySound("weapons/equip",CHAN_6)
	  PISG A 1 Offset(0,8)
	  PISG A 1 Offset(0,12)
	  PISG A 1 Offset(0,18)
	  PISG A 1 Offset(0,24)
	  PISG A 1 Offset(0,28)
	  PISG A 0 Offset(0,32)
	  PISG A 1 A_WeaponReady
	  Goto Idle
  
  Idle:
	PISG A 0 A_GiveInventory("YouPlayer_HoldingPistol",1)
    PISG A 1 A_WeaponReady(WRF_ALLOWRELOAD)
    Loop
	
	Empty:
	PISG A 1
	PISG A 0 A_PlaySound("weapons/empty",CHAN_VOICE)
	Goto Reload
	
  Fire:
	PISG A 0 A_JumpIfNoAmmo("Empty")
  
	PISG A 0 A_FireBullets (3, 3, -1, 5, "BulletPuff")
	PISG A 0 A_PlaySound("weapons/glock22/fire", CHAN_WEAPON, 1.0, false, 0.8)
	
	PISG A 0 A_FireCustomMissile ("MuzzleFlash_PistolHandler",0,false,30,5)
	PISG A 0 A_SetPitch(pitch-2.5,SPF_INTERPOLATE)
	
	MDL1 FG 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
    MDL1 H 2 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	MDL1 I 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	MDL1 JKLMNOPQRS 2 A_WeaponReady(WRF_ALLOWRELOAD)
	PISG A 0
    Goto Idle
	
	Reload:
	PISG A 1 A_WeaponReady
	PISG A 0 A_JumpIfInventory("Weapon_Glock22_Mag",0,"Idle")
	PISG A 0 A_JumpIfInventory("Weapon_Glock22_Ammo",1,"ReloadYes")
	Goto Idle
	ReloadYes:
	PISG A 0 A_PlaySound ("weapons/glock22/reload",CHAN_7)
	MDL1 TUVWXYZ 2 A_WeaponReady(WRF_NOFIRE)
	MDL2 ABCDEFGHIJKLMNOP 2 A_WeaponReady(WRF_NOFIRE)
	MDL2 Q 0 A_GunFlash("ReloadSystem",GFF_NOEXTCHANGE)
	MDL2 QRSTUVWXYZ 2 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
	PISG A 0
	Goto Idle
	
	ReloadSystem:
	TNT1 A 0 A_JumpIfInventory("Weapon_Glock22_Mag",0,"ReloadSystemEND")
	TNT1 A 0 A_JumpIfInventory("Weapon_Glock22_Ammo",1,"ReloadSystemConfirm")
	Goto ReloadSystemEND
	ReloadSystemConfirm:
	TNT1 A 0 A_GiveInventory("Weapon_Glock22_Mag",1)
	TNT1 A 0 A_TakeInventory("Weapon_Glock22_Ammo",1)
	Goto ReloadSystem
	
	ReloadSystemEND:
	TNT1 A 1
	Stop
	
  Spawn:
    PIST A -1
    Stop
	Done:
	MDL1 A 0
	MDL2 A 0
	MDL3 A 0
	MDL4 A 0
	MDL5 A 0
	MDL6 A 0
	MDL7 A 0
	MDL8 A 0
	MDL9 A 0
	Stop
  }
}

ACTOR Weapon_Glock22_Mag : Ammo
{
	Inventory.Amount 1
	Inventory.MaxAmount 17
}

ACTOR Weapon_Glock22_Ammo : Ammo
{
	Inventory.Amount 17
	Inventory.MaxAmount 85
}

ACTOR AmmoPkup_Glock22_single : CustomInventory Replaces Clip
{
	Scale 0.5
	+QUIET
	+COUNTITEM
	States
	{
	Spawn:
	AMMO C -1
	Stop
	Pickup:
	TNT1 A 0 A_JumpIfInventory("Weapon_Glock22_Ammo",0,"FailPickup")
	TNT1 A 0 A_GiveInventory("Weapon_Glock22_Ammo",17)
	TNT1 A 0 ACS_NamedExecute("PlayerPickupMessage",0,0)
	Stop
	FailPickup:
	TNT1 A 1
	Fail
	}
}

ACTOR AmmoPkup_Glock22_double : CustomInventory Replaces ClipBox
{
	Scale 0.5
	+QUIET
	+COUNTITEM
	States
	{
	Spawn:
	AMMO D -1
	Stop
	Pickup:
	TNT1 A 0 A_JumpIfInventory("Weapon_Glock22_Ammo",0,"FailPickup")
	TNT1 A 0 A_GiveInventory("Weapon_Glock22_Ammo",34)
	TNT1 A 0 ACS_NamedExecute("PlayerPickupMessage",0,1)
	Stop
	FailPickup:
	TNT1 A 1
	Fail
	}
}

ACTOR GunPkup_Glock22 : CustomInventory Replaces Chainsaw
{
	Scale 0.5
	+QUIET
	+COUNTITEM
	States
	{
	Spawn:
	GUNN A -1
	Stop
	Pickup:
	TNT1 A 0 A_JumpIfInventory("Weapon_Glock22",0,"FailPickup")
	TNT1 A 0 A_GiveInventory("Weapon_Glock22",1)
	TNT1 A 0 ACS_NamedExecute("PlayerPickupMessage",0,5)
	Fail
	FailPickup:
	TNT1 A 1
	Fail
	}
}