actor "G18" : RGUWeapon
{
  obituary "%k sprayed %o with the G18."
  inventory.pickupmessage "Glock 18"  
  //attacksound "ump45/fire6"
  weapon.selectionorder 14
  weapon.ammotype "G18Clip"
  weapon.ammouse 1
  weapon.ammogive 0
  weapon.ammotype2 "G18Ammo"
  weapon.ammouse2 0
  weapon.ammogive2 0
  -NOAUTOFIRE
  states
  {
  Ready:
    G18A A 2 //A_PlayWeaponSound("m9/select")
    G18A BCDEFGH 2 A_WeaponReady(WRF_NOPRIMARY)
    G18A I 0 A_JumpIfNoAmmo("Reload")
    G18A I 0 A_JumpIfInventory("Aiming",1,5)
    G18A I 0 A_JumpIfInventory("Reloading",1,"Reload")
    G18A I 0 A_JumpIfInventory("ThrowingGrenade",1,"FragGrenade")
    G18A I 0 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18A I 1 A_WeaponReady
    goto Ready+8
    G18C F 0 A_JumpIfInventory("Reloading",1,"Reload")    
    G18C F 0 A_JumpIfInventory("ThrowingGrenade",1,"FragGrenade")
    G18C F 0 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18C F 1 A_WeaponReady(WRF_NOBOB)
    goto Ready+14
  Deselect:
    G18A K 0 A_TakeInventory("Aiming",1)
    G18A K 0 ACS_ExecuteAlways(602,0,0,0,0)
    G18A L 0 A_TakeInventory("Reloading",1)
    G18A L 0 A_ZoomFactor(1.0)
    G18A K 0 A_Lower
    G18A I 1 A_Lower
    goto Deselect+2
  Select:
    G18A A 0 A_Raise
	G18A A 0 ACS_ExecuteAlways(602,0,0,0,0)
	TNT1 F 0 A_GiveInventory("InCombatCrosshair", 35)
    loop
  Fire:	
    G18B A 0 A_JumpIfInventory("Aiming",1,"FireAim")
    G18B A 0 A_JumpIfNoAmmo("ReloadStart")
    G18B A 0 A_JumpIfInventory("Perk3_SteadyAim",1,"Fire_SteadyAim")
    G18B A 0 A_PlayWeaponSound("g18/fire")
    TNT1 F 0 A_GiveInventory("InCombatCrosshair", 17)
    TNT1 F 0 A_GiveInventory("InCombat", 5)
    G18B A 0 A_FireCustomMissile("WeaponSmokePuff",0,0,9,3)
    G18B A 1 BRIGHT A_FireBullets (10.0, 10.0, -1, 8, "HHBulletPuff", 1, 6000)
    G18B B 0 BRIGHT ACS_ExecuteAlways(600,0,120,0,0)
    G18B A 0 A_JumpIfNoAmmo("FireEmpty")
    G18B B 1 BRIGHT A_GunFlash
    G18B A 0 A_JumpIfInventory("G18Ammo",1,3)
    G18B CD 1 A_ReFire
    goto Ready+8
    G18B A 0 A_JumpIfNoAmmo("ReloadStart")
    G18B CD 1 A_ReFire
    goto Ready+8
  Hold:
    G18B A 0 A_JumpIfInventory("Aiming",1,"HoldAim")
    G18B A 0 A_JumpIfNoAmmo("ReloadStart")
    G18B A 0 A_JumpIfInventory("Perk3_SteadyAim",1,"Hold_SteadyAim")
    G18B A 0 A_PlayWeaponSound("g18/fire")
    TNT1 F 0 A_GiveInventory("InCombatCrosshair", 17)
    TNT1 F 0 A_GiveInventory("InCombat", 5)
    G18B A 0 A_FireCustomMissile("WeaponSmokePuff",0,0,9,3)
    G18B A 1 BRIGHT A_FireBullets (20.0, 20.0, -1, 8, "HHBulletPuff", 1, 6000)
    G18B B 0 BRIGHT ACS_ExecuteAlways(600,0,120,0,0)
    G18B A 0 A_JumpIfNoAmmo("FireEmpty")
    G18B B 1 BRIGHT A_GunFlash
    G18B A 0 A_JumpIfInventory("G18Ammo",1,3)
    G18B CD 1 A_ReFire
    goto Ready+8
    G18B A 0 A_JumpIfNoAmmo("ReloadStart")
    G18B CD 1 A_ReFire
    goto Ready+8
  FireEmpty:
    G18B B 1 BRIGHT A_GunFlash
    G18B CD 1 A_GiveInventory("G18Bolt",1)
    G18B A 0 A_JumpIfInventory("G18Ammo",1,2)
    G18B A 0 A_ReFire
    goto Ready+8
    G18B A 0 A_JumpIfNoAmmo("ReloadStart")
    G18B CD 1 A_ReFire
    goto Ready+8
  FireAim:
    G18C G 0 A_PlayWeaponSound("g18/fire")
    TNT1 F 0 A_GiveInventory("InCombatCrosshair", 17)
    TNT1 F 0 A_GiveInventory("InCombat", 5)
    G18C G 0 A_FireCustomMissile("WeaponSmokePuff",0,0,0,6)
    G18C G 1 BRIGHT A_FireBullets (3.0, 3.0, -1, 8, "HHBulletPuff", 1, 6000)
    G18C G 0 BRIGHT ACS_ExecuteAlways(600,0,120,0,0)
    G18C G 0 A_JumpIfNoAmmo("FireAimEmpty")
    G18C H 1 BRIGHT A_GunFlash
    G18C H 0 A_JumpIfInventory("G18Ammo",1,3)
    G18C IJ 1 A_ReFire
    goto Ready+14
    G18C A 0 A_JumpIfNoAmmo("ReloadStart")
    G18C IJ 1 A_ReFire
    goto Ready+14
  HoldAim:
    G18C G 0 A_PlayWeaponSound("g18/fire")
    TNT1 F 0 A_GiveInventory("InCombatCrosshair", 17)
    TNT1 F 0 A_GiveInventory("InCombat", 5)
    G18C G 0 A_FireCustomMissile("WeaponSmokePuff",0,0,0,6)
    G18C G 1 BRIGHT A_FireBullets (9, 9, -1, 6, "HHBulletPuff", 1, 6000)
    G18C G 0 BRIGHT ACS_ExecuteAlways(600,0,120,0,0)
    G18C G 0 A_JumpIfNoAmmo("FireAimEmpty")
    G18C H 1 BRIGHT A_GunFlash
    G18C H 0 A_JumpIfInventory("G18Ammo",1,3)
    G18C IJ 1 A_ReFire
    goto Ready+14
    G18C A 0 A_JumpIfNoAmmo("ReloadStart")
    G18C IJ 1 A_ReFire
    goto Ready+14
  FireAimEmpty:
    G18C H 1 BRIGHT A_GunFlash
    G18C IJ 1 A_GiveInventory("G18Bolt",1)
    G18C A 0 A_JumpIfInventory("G18Ammo",1,2)
    G18C A 0 A_ReFire
    goto Ready+14
    G18C A 0 A_JumpIfNoAmmo("ReloadStart")
    G18C IJ 0 A_ReFire
    goto Ready+14
  Reload: //AltFire:
    G18C A 0 A_JumpIfInventory("G18Ammo",1,"ReloadStart")
    G18C A 0 A_TakeInventory("Reloading",1)
    goto Ready+11
  ReloadStart:
  	TNT1 A 0 ACS_ExecuteAlways(652,0,0,0,0) // Shout "Reloading" 
    G18E H 0 A_JumpIfInventory("Aiming",1,"ReloadStartAim")
    G18E H 0 A_JumpIfInventory("G18Bolt",1,"ReloadStartBolt") 
    G18E H 0 A_JumpIfInventory("Perk1_SOH",1,"ReloadStart_SOH")
    G18E H 3 A_PlaySoundEx("g18/clipout","SoundSlot5")
    G18E IJKLMNOPQ 3 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18E RSTUVWXY 3 A_WeaponReady(WRF_NOFIRE)
    G18E Z 0 A_PlaySoundEx("g18/clipin","SoundSlot5")
    G18E Z 3 A_TakeInventory("Reloading",1)
    goto ReloadAmmo
  ReloadAmmo:
    G18E Z 0 A_GiveInventory("G18Clip",1)
    G18E Z 0 A_TakeInventory("G18Ammo",1)
    G18E Z 0 A_JumpIfInventory("G18Clip",33,"ReloadEnd")
    G18E Z 0 A_JumpIfInventory("G18Ammo",1,"ReloadAmmo")
    goto ReloadEnd
  ReloadEnd:
    G18F ABCD 3 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18F EFG 3 A_WeaponReady(WRF_NOFIRE)
    G18F G 0 A_ReFire
    goto Ready+8  
  ReloadStartBolt:
    G18D A 0 A_JumpIfInventory("Perk1_SOH",1,"ReloadStartBolt_SOH")
    G18D A 3 A_PlaySoundEx("g18/clipout","SoundSlot5")
    G18D BCDEFGHIJ 3 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18D KLMNOPQR 3 A_WeaponReady(WRF_NOFIRE)
    G18D S 0 A_PlaySoundEx("g18/clipin","SoundSlot5")
    G18D S 3 A_TakeInventory("Reloading",1)
    goto ReloadAmmoBolt
  ReloadAmmoBolt:
    G18E Z 0 A_GiveInventory("G18Clip",1)
    G18E Z 0 A_TakeInventory("G18Ammo",1)
    G18E Z 0 A_JumpIfInventory("G18Clip",33,"ReloadEndBolt")
    G18E Z 0 A_JumpIfInventory("G18Ammo",1,"ReloadAmmoBolt")
    goto ReloadEndBolt
  ReloadEndBolt:
    G18D Z 0 A_TakeInventory("G18Bolt",1)
    G18D TUVWXY 3 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18D Z 3 A_PlaySoundEx("g18/bolt","SoundSlot5")
    G18E ABCDEFG 3 A_WeaponReady(WRF_NOFIRE)
    G18E G 0 A_ReFire
    goto Ready+8
  AltFire:
    G18C A 0 A_ZoomFactor(1.2)
    G18C A 0 A_JumpIfInventory("Aiming",1,"AltFire2")
    G18C ABCDE 1
    G18C F 0 A_GiveInventory("Aiming",1)
    G18C F 0 ACS_ExecuteAlways(602,0,0,0,0)
    G18C F 0 A_Refire
    goto Ready+14
  AltFire2:
    G18C A 0 A_ZoomFactor(1.0)
    G18C EDCBA 1
    G18C A 0 A_TakeInventory("Aiming",1)
    G18C A 0 ACS_ExecuteAlways(602,0,0,0,0)
    G18C G 0 A_Refire
    goto Ready+8
  AltHold:
    G18A I 1 A_JumpIfInventory("Aiming",1,"AltHoldAim")
    G18A I 1 A_ReFire
    goto Ready+8
  AltHoldAim:
    G18C F 1
    G18C F 1 A_ReFire
    goto Ready+14
  ReloadStartAim:
    G18C A 0 A_ZoomFactor(1.0)
    G18C EDCBA 1
    G18C A 0 A_TakeInventory("Aiming",1)
    G18C A 0 ACS_ExecuteAlways(602,0,0,0,0)
    goto ReloadStart+1
  Flash:
    TNT1 A 2 bright A_Light1
    TNT1 A 0 bright A_Light0
    stop
  Spawn:
    WEAP Q 15
    WEAP Q 0 A_SpawnItemEx("G18Pickup")
    stop
  Fire_SteadyAim:
    G18B A 0 A_PlayWeaponSound("g18/fire")
    TNT1 F 0 A_GiveInventory("InCombatCrosshair", 17)
    TNT1 F 0 A_GiveInventory("InCombat", 5)
    G18B A 0 A_FireCustomMissile("WeaponSmokePuff",0,0,9,3)
    G18B A 1 BRIGHT A_FireBullets (6.6, 6.6, -1, 8, "HHBulletPuff", 1, 6000)
    G18B B 0 BRIGHT ACS_ExecuteAlways(600,0,120,0,0)
    G18B A 0 A_JumpIfNoAmmo("FireEmpty")
    G18B B 1 BRIGHT A_GunFlash
    G18B A 0 A_JumpIfInventory("G18Ammo",1,3)
    G18B CD 1 A_ReFire
    goto Ready+8
    G18B A 0 A_JumpIfNoAmmo("ReloadStart")
    G18B CD 1 A_ReFire
    goto Ready+8
  Hold_SteadyAim:
    G18B A 0 A_PlayWeaponSound("g18/fire")
    TNT1 F 0 A_GiveInventory("InCombatCrosshair", 17)
    TNT1 F 0 A_GiveInventory("InCombat", 5)
    G18B A 0 A_FireCustomMissile("WeaponSmokePuff",0,0,9,3)
    G18B A 1 BRIGHT A_FireBullets (13.2, 13.2, -1, 8, "HHBulletPuff", 1, 6000)
    G18B B 0 BRIGHT ACS_ExecuteAlways(600,0,120,0,0)
    G18B A 0 A_JumpIfNoAmmo("FireEmpty")
    G18B B 1 BRIGHT A_GunFlash
    G18B A 0 A_JumpIfInventory("G18Ammo",1,3)
    G18B CD 1 A_ReFire
    goto Ready+8
    G18B A 0 A_JumpIfNoAmmo("ReloadStart")
    G18B CD 1 A_ReFire
    goto Ready+8
  ReloadStart_SOH:
    G18E H 2 A_PlaySoundEx("g18/clipout","SoundSlot5")
    G18E IJKLMNOPQ 2 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18E RSTUVWXY 2 A_WeaponReady(WRF_NOFIRE)
    G18E Z 0 A_PlaySoundEx("g18/clipin","SoundSlot5")
    G18E Z 2 A_TakeInventory("Reloading",1)
    goto ReloadAmmo_SOH
  ReloadAmmo_SOH:
    G18E Z 0 A_GiveInventory("G18Clip",1)
    G18E Z 0 A_TakeInventory("G18Ammo",1)
    G18E Z 0 A_JumpIfInventory("G18Clip",33,"ReloadEnd_SOH")
    G18E Z 0 A_JumpIfInventory("G18Ammo",1,"ReloadAmmo_SOH")
    goto ReloadEnd_SOH
  ReloadEnd_SOH:
    G18F ABCD 2 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18F EFG 2 A_WeaponReady(WRF_NOFIRE)
    G18F G 0 A_ReFire
    goto Ready+8  
  ReloadStartBolt_SOH:
    G18D A 2 A_PlaySoundEx("g18/clipout","SoundSlot5")
    G18D BCDEFGHIJ 2 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18D KLMNOPQR 2 A_WeaponReady(WRF_NOFIRE)
    G18D S 0 A_PlaySoundEx("g18/clipin","SoundSlot5")
    G18D S 2 A_TakeInventory("Reloading",1)
    goto ReloadAmmoBolt_SOH
  ReloadAmmoBolt_SOH:
    G18E Z 0 A_GiveInventory("G18Clip",1)
    G18E Z 0 A_TakeInventory("G18Ammo",1)
    G18E Z 0 A_JumpIfInventory("G18Clip",33,"ReloadEndBolt_SOH")
    G18E Z 0 A_JumpIfInventory("G18Ammo",1,"ReloadAmmoBolt_SOH")
    goto ReloadEndBolt_SOH
  ReloadEndBolt_SOH:
    G18D Z 0 A_TakeInventory("G18Bolt",1)
    G18D TUVWXY 2 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18D Z 2 A_PlaySoundEx("g18/bolt","SoundSlot5")
    G18E ABCDEFG 2 A_WeaponReady(WRF_NOFIRE)
    G18E G 0 A_ReFire
    goto Ready+8
  FragGrenade:
    U45F A 0 A_ZoomFactor(1.0)
    U45A L 0 A_TakeInventory("Aiming",1)
    U45A L 0 A_TakeInventory("Reloading",1)
    U45F A 0 ACS_ExecuteAlways(602,0,0,0,0)
    U45A L 0 A_JumpIfInventory("Perk1_SOH_Pro",1,"FragGrenade_SOH")
    GRNA A 2 A_PlaySound("grenade/pinpull")
    GRNA BCDEFGH 2
    TNT1 A 15 
    TNT1 A 0 A_PlaySound("grenade/throw")
    GRNA A 0 A_PlaySoundEx("us/grenades","Voice")
    GRNA IJK 2
    GRNA L 0 A_TakeInventory("FragGrenadeAmmo",1)
    GRNA L 0 A_TakeInventory("ThrowingGrenade",1)
    U45A L 0 A_TakeInventory("Aiming",1)
    GRNA L 0 A_TakeInventory("KnifeAttack",1)
    GRNA L 2 A_FireCustomMissile("FragGrenade",0,0,0,16)
    GRNA MN 2 
    goto Ready+1
  FragGrenade_SOH:
    GRNA A 1 A_PlaySound("grenade/pinpull")
    GRNA BCDEFGH 1
    TNT1 A 10
    TNT1 A 0 A_PlaySound("grenade/throw")
    GRNA A 0 A_PlaySoundEx("us/grenades","Voice")
    GRNA IJK 1
    GRNA L 0 A_TakeInventory("FragGrenadeAmmo",1)
    GRNA L 0 A_TakeInventory("ThrowingGrenade",1)
    U45A L 0 A_TakeInventory("Aiming",1)
    GRNA L 0 A_TakeInventory("KnifeAttack",1)
    GRNA L 1 A_FireCustomMissile("FragGrenade",0,0,0,16)
    GRNA MN 1 
    goto Ready+1
  KnifeAttack:
    U45F A 0 A_ZoomFactor(1.0)
    U45A L 0 A_JumpIfInventory("ThrowingGrenade",1,"FragGrenade")
    U45A L 0 A_TakeInventory("Aiming",1)
    U45A L 0 A_TakeInventory("Reloading",1)
    U45F A 0 ACS_ExecuteAlways(602,0,0,0,0)
    U45A L 0 A_JumpIfInventory("Perk1_SOH_Pro",1,"KnifeAttack_SOH")
    U45C A 0 A_JumpIfInventory("Perk3_Commando",1,"KnifeAttack_Commando")
    KNFA A 0 ACS_ExecuteAlways(599,0,0,0,0)
    KNFA AB 1
    KNFA B 0 A_PlaySound("knife/swing")
    KNFA CDE 1 A_CustomPunch(34,1,0,"KnifePuff",96)
    KNFA FGHIJKL 1 
    TNT1 A 20
    GRNA L 0 A_TakeInventory("KnifeAttack",1)
    goto Ready+1
  KnifeAttack_Commando:
    KNFA A 0 ACS_ExecuteAlways(599,0,0,0,0)
    KNFA AB 1
    KNFA B 0 A_PlaySound("knife/swing")
    KNFA CDE 1 A_CustomPunch(34,1,0,"KnifePuff",160)
    KNFA FGHIJKL 1 
    TNT1 A 20
    GRNA L 0 A_TakeInventory("KnifeAttack",1)
    goto Ready+1
  KnifeAttack_SOH:
    U45C A 0 A_JumpIfInventory("Perk3_Commando",1,"KnifeAttack_SOH_Commando")
    KNFA A 0 ACS_ExecuteAlways(599,0,0,0,0)
    KNFA AB 1
    KNFA B 0 A_PlaySound("knife/swing")
    KNFA CDE 1 A_CustomPunch(34,1,0,"KnifePuff",96)
    KNFA FGHIJKL 1 
    TNT1 A 10
    GRNA L 0 A_TakeInventory("KnifeAttack",1)
    goto Ready+1
  KnifeAttack_SOH_Commando:
    KNFA A 0 ACS_ExecuteAlways(599,0,0,0,0)
    KNFA AB 1
    KNFA B 0 A_PlaySound("knife/swing")
    KNFA CDE 1 A_CustomPunch(34,1,0,"KnifePuff",160)
    KNFA FGHIJKL 1 
    TNT1 A 10
    GRNA L 0 A_TakeInventory("KnifeAttack",1)
    goto Ready+1
  }
}

actor G18Clip : Ammo
{
    inventory.icon "CLIPA0"
    inventory.amount 0
    inventory.maxamount 33
    ammo.backpackamount 0
    ammo.backpackmaxamount 33
    +IGNORESKILL
}

actor G18Bolt : Inventory
{
    inventory.amount 0
    inventory.maxamount 1
}
actor "G18 Ex Mags" : "G18"
{
  obituary "%k sprayed %o with the G18."
  inventory.pickupmessage "Glock 18"  
  //attacksound "ump45/fire6"
  weapon.selectionorder 14
  weapon.ammotype "G18Clip2"
  weapon.ammouse 1
  weapon.ammogive 0
  weapon.ammotype2 "G18Ammo"
  weapon.ammouse2 0
  weapon.ammogive2 0
  -NOAUTOFIRE
  states
  {
  Reload: //AltFire:
    G18C A 0 A_JumpIfInventory("G18Ammo",1,"ReloadStart")
    G18C A 0 A_TakeInventory("Reloading",1)
    goto Ready+11
  ReloadStart:
  	TNT1 A 0 ACS_ExecuteAlways(652,0,0,0,0) // Shout "Reloading" 
    G18E H 0 A_JumpIfInventory("Aiming",1,"ReloadStartAim")
    G18E H 0 A_JumpIfInventory("G18Bolt",1,"ReloadStartBolt") 
    G18E H 0 A_JumpIfInventory("Perk1_SOH",1,"ReloadStart_SOH")
    G18E H 3 A_PlaySoundEx("g18/clipout","SoundSlot5")
    G18E IJKLMNOPQ 3 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18E RSTUVWXY 3 A_WeaponReady(WRF_NOFIRE)
    G18E Z 0 A_PlaySoundEx("g18/clipin","SoundSlot5")
    G18E Z 3 A_TakeInventory("Reloading",1)
    goto ReloadAmmo
  ReloadAmmo:
    G18E Z 0 A_GiveInventory("G18Clip2",1)
    G18E Z 0 A_TakeInventory("G18Ammo",1)
    G18E Z 0 A_JumpIfInventory("G18Clip2",50,"ReloadEnd")
    G18E Z 0 A_JumpIfInventory("G18Ammo",1,"ReloadAmmo")
    goto ReloadEnd
  ReloadEnd:
    G18F ABCD 3 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18F EFG 3 A_WeaponReady(WRF_NOFIRE)
    G18F G 0 A_ReFire
    goto Ready+8  
  ReloadStartBolt:
    G18D A 0 A_JumpIfInventory("Perk1_SOH",1,"ReloadStartBolt_SOH")
    G18D A 3 A_PlaySoundEx("g18/clipout","SoundSlot5")
    G18D BCDEFGHIJ 3 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18D KLMNOPQR 3 A_WeaponReady(WRF_NOFIRE)
    G18D S 0 A_PlaySoundEx("g18/clipin","SoundSlot5")
    G18D S 3 A_TakeInventory("Reloading",1)
    goto ReloadAmmoBolt
  ReloadAmmoBolt:
    G18E Z 0 A_GiveInventory("G18Clip2",1)
    G18E Z 0 A_TakeInventory("G18Ammo",1)
    G18E Z 0 A_JumpIfInventory("G18Clip2",50,"ReloadEndBolt")
    G18E Z 0 A_JumpIfInventory("G18Ammo",1,"ReloadAmmoBolt")
    goto ReloadEndBolt
  ReloadEndBolt:
    G18D Z 0 A_TakeInventory("G18Bolt",1)
    G18D TUVWXY 3 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18D Z 3 A_PlaySoundEx("g18/bolt","SoundSlot5")
    G18E ABCDEFG 3 A_WeaponReady(WRF_NOFIRE)
    G18E G 0 A_ReFire
    goto Ready+8
  ReloadStartAim:
    G18C A 0 A_ZoomFactor(1.0)
    G18C EDCBA 1
    G18C A 0 A_TakeInventory("Aiming",1)
    G18C A 0 ACS_ExecuteAlways(602,0,0,0,0)
    goto ReloadStart+1
  ReloadStart_SOH:
    G18E H 2 A_PlaySoundEx("g18/clipout","SoundSlot5")
    G18E IJKLMNOPQ 2 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18E RSTUVWXY 2 A_WeaponReady(WRF_NOFIRE)
    G18E Z 0 A_PlaySoundEx("g18/clipin","SoundSlot5")
    G18E Z 2 A_TakeInventory("Reloading",1)
    goto ReloadAmmo_SOH
  ReloadAmmo_SOH:
    G18E Z 0 A_GiveInventory("G18Clip2",1)
    G18E Z 0 A_TakeInventory("G18Ammo",1)
    G18E Z 0 A_JumpIfInventory("G18Clip2",50,"ReloadEnd_SOH")
    G18E Z 0 A_JumpIfInventory("G18Ammo",1,"ReloadAmmo_SOH")
    goto ReloadEnd_SOH
  ReloadEnd_SOH:
    G18F ABCD 2 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18F EFG 2 A_WeaponReady(WRF_NOFIRE)
    G18F G 0 A_ReFire
    goto Ready+8  
  ReloadStartBolt_SOH:
    G18D A 2 A_PlaySoundEx("g18/clipout","SoundSlot5")
    G18D BCDEFGHIJ 2 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18D KLMNOPQR 2 A_WeaponReady(WRF_NOFIRE)
    G18D S 0 A_PlaySoundEx("g18/clipin","SoundSlot5")
    G18D S 2 A_TakeInventory("Reloading",1)
    goto ReloadAmmoBolt_SOH
  ReloadAmmoBolt_SOH:
    G18E Z 0 A_GiveInventory("G18Clip2",1)
    G18E Z 0 A_TakeInventory("G18Ammo",1)
    G18E Z 0 A_JumpIfInventory("G18Clip2",50,"ReloadEndBolt_SOH")
    G18E Z 0 A_JumpIfInventory("G18Ammo",1,"ReloadAmmoBolt_SOH")
    goto ReloadEndBolt_SOH
  ReloadEndBolt_SOH:
    G18D Z 0 A_TakeInventory("G18Bolt",1)
    G18D TUVWXY 2 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18D Z 2 A_PlaySoundEx("g18/bolt","SoundSlot5")
    G18E ABCDEFG 2 A_WeaponReady(WRF_NOFIRE)
    G18E G 0 A_ReFire
    goto Ready+8
  }
}

actor G18Clip2 : Ammo
{
    inventory.icon "CLIPA0"
    inventory.amount 0
    inventory.maxamount 50
    ammo.backpackamount 0
    ammo.backpackmaxamount 50
    +IGNORESKILL
}

actor G18ExMags : Inventory
{
    inventory.amount 0
    inventory.maxamount 1
}

actor "G18 Akimbo" : "G18"
{
  obituary "%k sprayed %o with the G18."
  inventory.pickupmessage "Glock 18"  
  //attacksound "ump45/fire6"
  weapon.selectionorder 14
  weapon.ammotype "G18Clip3"
  weapon.ammouse 1
  weapon.ammogive 0
  weapon.ammotype2 "G18Ammo"
  weapon.ammouse2 0
  weapon.ammogive2 0
  -NOAUTOFIRE
  states
  {
  Ready:
    G18G A 2 //A_PlayWeaponSound("m9/select")
    G18G BCDEFGH 2 A_WeaponReady(WRF_NOPRIMARY)
    G18G I 0 A_JumpIfNoAmmo("Reload")
    G18G I 0 A_JumpIfInventory("Aiming",1,5)
    G18G I 0 A_JumpIfInventory("Reloading",1,"Reload")
    G18G I 0 A_JumpIfInventory("ThrowingGrenade",1,"FragGrenade")
    G18G I 0 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18G I 1 A_WeaponReady
    goto Ready+8
  Deselect:
    G18G K 0 A_TakeInventory("Aiming",1)
    G18G K 0 ACS_ExecuteAlways(602,0,0,0,0)
    G18G L 0 A_TakeInventory("Reloading",1)
    G18G L 0 A_ZoomFactor(1.0)
    G18G K 0 A_Lower
    G18G I 1 A_Lower
    goto Deselect+2
  Select:
    G18G A 0 A_Raise
	G18G A 0 ACS_ExecuteAlways(602,0,0,0,0)
	TNT1 F 0 A_GiveInventory("InCombatCrosshair", 35)
    loop
  Fire:	
    G18H A 0 A_JumpIfInventory("Aiming",1,"FireAim")
    G18H A 0 A_JumpIfNoAmmo("ReloadStart")
    G18H A 0 A_JumpIfInventory("Perk3_SteadyAim",1,"Fire_SteadyAim")
    G18H A 0 A_PlayWeaponSound("g18/fire")
    TNT1 F 0 A_GiveInventory("InCombatCrosshair", 17)
    TNT1 F 0 A_GiveInventory("InCombat", 5)
    G18H A 0 A_FireCustomMissile("WeaponSmokePuff",0,0,20,3)
    G18H A 1 BRIGHT A_FireBullets (10.0, 10.0, -1, 8, "HHBulletPuff", 1, 6000)
    G18H AA 0 BRIGHT ACS_ExecuteAlways(600,0,120,0,0)
    G18H A 0 A_JumpIfNoAmmo("FireEmpty")
    G18H B 0 A_PlaySoundEx("g18/fire","SoundSlot5")
    TNT1 F 0 A_GiveInventory("InCombatCrosshair", 17)
    TNT1 F 0 A_GiveInventory("InCombat", 5)
    G18H B 0 A_FireCustomMissile("WeaponSmokePuff",0,0,-20,3)
    G18H B 1 BRIGHT A_FireBullets (10.0, 10.0, -1, 8, "HHBulletPuff", 1, 6000)
    G18H A 0 A_JumpIfNoAmmo("FireEmpty")
    G18H C 0 BRIGHT A_GunFlash
    G18H A 0 A_JumpIfInventory("G18Ammo",1,4)
    G18H DE 1 A_ReFire
    goto Ready+8
    G18H A 0 A_JumpIfNoAmmo("ReloadStart")
    G18H DE 1 A_ReFire
    goto Ready+8
  Hold:
    G18H A 0 A_JumpIfInventory("Perk3_SteadyAim",1,"Hold_SteadyAim")
    G18H A 0 A_PlayWeaponSound("g18/fire")
    TNT1 F 0 A_GiveInventory("InCombatCrosshair", 17)
    TNT1 F 0 A_GiveInventory("InCombat", 5)
    G18H A 0 A_FireCustomMissile("WeaponSmokePuff",0,0,20,3)
    G18H A 1 BRIGHT A_FireBullets (20.0, 20.0, -1, 8, "HHBulletPuff", 1, 6000)
    G18H AA 0 BRIGHT ACS_ExecuteAlways(600,0,120,0,0)
    G18H A 0 A_JumpIfNoAmmo("FireEmpty")
    G18H B 0 A_PlaySoundEx("g18/fire","SoundSlot5")
    TNT1 F 0 A_GiveInventory("InCombatCrosshair", 17)
    TNT1 F 0 A_GiveInventory("InCombat", 5)
    G18H A 0 A_FireCustomMissile("WeaponSmokePuff",0,0,-20,3)
    G18H B 1 BRIGHT A_FireBullets (20.0, 20.0, -1, 8, "HHBulletPuff", 1, 6000)
    G18H A 0 A_JumpIfNoAmmo("FireEmpty")
    G18H C 0 BRIGHT A_GunFlash
    G18H A 0 A_JumpIfInventory("G18Ammo",1,4)
    G18H CDE 1 A_ReFire
    goto Ready+8
    G18H A 0 A_JumpIfNoAmmo("ReloadStart")
    G18H CDE 1 A_ReFire
    goto Ready+8
  FireEmpty:
    G18H B 1 BRIGHT A_GunFlash
    G18H CDE 1 A_GiveInventory("G18Bolt",1)
    G18H A 0 A_JumpIfInventory("G18Ammo",1,2)
    G18H A 0 A_ReFire
    goto Ready+8
    G18H A 0 A_JumpIfNoAmmo("ReloadStart")
    G18H CDE 1 A_ReFire
    goto Ready+8
  Reload: //AltFire:
    G18I A 0 A_JumpIfInventory("G18Ammo",1,"ReloadStart")
    G18I A 0 A_TakeInventory("Reloading",1)
    goto Ready+11
  ReloadStart:
  	TNT1 A 0 ACS_ExecuteAlways(652,0,0,0,0) // Shout "Reloading" 
    G18I H 0 A_JumpIfInventory("Aiming",1,"ReloadStartAim")
    G18I H 0 A_JumpIfInventory("G18Bolt",1,"ReloadStartBolt") 
    G18I H 0 A_JumpIfInventory("Perk1_SOH",1,"ReloadStart_SOH")
    G18I A 3 A_PlaySoundEx("g18/clipout","SoundSlot5")
    G18I BCDEFGHI 3 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18I JKL 3 A_WeaponReady(WRF_NOFIRE)
    TNT1 AAAAA 3 A_WeaponReady(WRF_NOFIRE)
    TNT1 A 0 A_PlaySoundEx("g18/clipin","SoundSlot5")
    TNT1 A 3 A_TakeInventory("Reloading",1)
    goto ReloadAmmo
  ReloadAmmo:
    G18J Z 0 A_GiveInventory("G18Clip3",1)
    G18J Z 0 A_TakeInventory("G18Ammo",1)
    G18J Z 0 A_JumpIfInventory("G18Clip3",66,"ReloadEnd")
    G18J Z 0 A_JumpIfInventory("G18Ammo",1,"ReloadAmmo")
    goto ReloadEnd
  ReloadEnd:
    G18G ABCDE 3 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18G FGHI 3 A_WeaponReady(WRF_NOFIRE)
    G18G G 0 A_ReFire
    goto Ready+8  
  ReloadStartBolt:
    G18J A 0 A_JumpIfInventory("Perk1_SOH",1,"ReloadStartBolt_SOH")
    G18J A 3 A_PlaySoundEx("g18/clipout","SoundSlot5")
    G18J BCDEFGHIJ 3 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18J K 3 A_WeaponReady(WRF_NOFIRE)
    TNT1 AAAAAA 3 A_WeaponReady(WRF_NOFIRE)
    TNT1 A 0 A_PlaySoundEx("g18/clipin","SoundSlot5")
    TNT1 A 3 A_TakeInventory("Reloading",1)
    goto ReloadAmmoBolt
  ReloadAmmoBolt:
    G18J Z 0 A_GiveInventory("G18Clip3",1)
    G18J Z 0 A_TakeInventory("G18Ammo",1)
    G18J Z 0 A_JumpIfInventory("G18Clip3",66,"ReloadEndBolt")
    G18J Z 0 A_JumpIfInventory("G18Ammo",1,"ReloadAmmoBolt")
    goto ReloadEndBolt
  ReloadEndBolt:
    G18J O 0 A_TakeInventory("G18Bolt",1)
    TNT1 AA 3 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18J LMN 3 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18J O 3 A_PlaySoundEx("g18/bolt","SoundSlot5")
    G18J PQRST 3 A_WeaponReady(WRF_NOFIRE)
    G18J G 0 A_ReFire
    goto Ready+8
  AltFire:
    G18G I 3
    goto Ready+8
  Flash:
    TNT1 A 2 bright A_Light1
    TNT1 A 0 bright A_Light0
    stop
  Spawn:
    WEAP Q 15
    WEAP Q 0 A_SpawnItemEx("G18Pickup")
    stop
  ReloadStart_SOH:
    G18I A 2 A_PlaySoundEx("g18/clipout","SoundSlot5")
    G18I BCDEFGHI 2 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18I JKL 2 A_WeaponReady(WRF_NOFIRE)
    TNT1 AAAAA 2 A_WeaponReady(WRF_NOFIRE)
    TNT1 A 0 A_PlaySoundEx("g18/clipin","SoundSlot5")
    TNT1 A 2 A_TakeInventory("Reloading",1)
    goto ReloadAmmo_SOH
  ReloadAmmo_SOH:
    G18J Z 0 A_GiveInventory("G18Clip3",1)
    G18J Z 0 A_TakeInventory("G18Ammo",1)
    G18J Z 0 A_JumpIfInventory("G18Clip3",66,"ReloadEnd_SOH")
    G18J Z 0 A_JumpIfInventory("G18Ammo",1,"ReloadAmmo_SOH")
    goto ReloadEnd_SOH
  ReloadEnd_SOH:
    G18G ABCDE 2 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18G FGHI 2 A_WeaponReady(WRF_NOFIRE)
    G18G G 0 A_ReFire
    goto Ready+8  
  ReloadStartBolt_SOH:
    G18J A 2 A_PlaySoundEx("g18/clipout","SoundSlot5")
    G18J BCDEFGHIJ 2 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18J K 2 A_WeaponReady(WRF_NOFIRE)
    TNT1 AAAAAA 2 A_WeaponReady(WRF_NOFIRE)
    TNT1 A 0 A_PlaySoundEx("g18/clipin","SoundSlot5")
    TNT1 A 2 A_TakeInventory("Reloading",1)
    goto ReloadAmmoBolt_SOH
  ReloadAmmoBolt_SOH:
    G18J Z 0 A_GiveInventory("G18Clip3",1)
    G18J Z 0 A_TakeInventory("G18Ammo",1)
    G18J Z 0 A_JumpIfInventory("G18Clip3",66,"ReloadEndBolt_SOH")
    G18J Z 0 A_JumpIfInventory("G18Ammo",1,"ReloadAmmoBolt_SOH")
    goto ReloadEndBolt_SOH
  ReloadEndBolt_SOH:
    G18J O 0 A_TakeInventory("G18Bolt",1)
    TNT1 AA 2 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18J LMN 2 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    G18J O 2 A_PlaySoundEx("g18/bolt","SoundSlot5")
    G18J PQRST 2 A_WeaponReady(WRF_NOFIRE)
    G18J G 0 A_ReFire
    goto Ready+8
  Fire_SteadyAim:
    G18H A 0 A_PlayWeaponSound("g18/fire")
    TNT1 F 0 A_GiveInventory("InCombatCrosshair", 17)
    TNT1 F 0 A_GiveInventory("InCombat", 5)
    G18H A 0 A_FireCustomMissile("WeaponSmokePuff",0,0,20,3)
    G18H A 1 BRIGHT A_FireBullets (6.6, 4.0, -1, 8, "HHBulletPuff", 1, 6000)
    G18H AA 0 BRIGHT ACS_ExecuteAlways(600,0,120,0,0)
    G18H A 0 A_JumpIfNoAmmo("FireEmpty")
    G18H B 0 A_PlaySoundEx("g18/fire","SoundSlot5")
    TNT1 F 0 A_GiveInventory("InCombatCrosshair", 17)
    TNT1 F 0 A_GiveInventory("InCombat", 5)
    G18H B 0 A_FireCustomMissile("WeaponSmokePuff",0,0,-20,3)
    G18H B 1 BRIGHT A_FireBullets (6.6, 4.0, -1, 8, "HHBulletPuff", 1, 6000)
    G18H A 0 A_JumpIfNoAmmo("FireEmpty")
    G18H C 0 BRIGHT A_GunFlash
    G18H A 0 A_JumpIfInventory("G18Ammo",1,4)
    G18H DE 1 A_ReFire
    goto Ready+8
    G18H A 0 A_JumpIfNoAmmo("ReloadStart")
    G18H DE 1 A_ReFire
    goto Ready+8
  Hold_SteadyAim:
    G18H A 0 A_PlayWeaponSound("g18/fire")
    TNT1 F 0 A_GiveInventory("InCombatCrosshair", 17)
    TNT1 F 0 A_GiveInventory("InCombat", 5)
    G18H A 0 A_FireCustomMissile("WeaponSmokePuff",0,0,20,3)
    G18H A 1 BRIGHT A_FireBullets (13.2, 13.2, -1, 8, "HHBulletPuff", 1, 6000)
    G18H AA 0 BRIGHT ACS_ExecuteAlways(600,0,120,0,0)
    G18H A 0 A_JumpIfNoAmmo("FireEmpty")
    G18H B 0 A_PlaySoundEx("g18/fire","SoundSlot5")
    TNT1 F 0 A_GiveInventory("InCombatCrosshair", 17)
    TNT1 F 0 A_GiveInventory("InCombat", 5)
    G18H A 0 A_FireCustomMissile("WeaponSmokePuff",0,0,-20,3)
    G18H B 1 BRIGHT A_FireBullets (13.2, 13.2, -1, 8, "HHBulletPuff", 1, 6000)
    G18H A 0 A_JumpIfNoAmmo("FireEmpty")
    G18H C 0 BRIGHT A_GunFlash
    G18H A 0 A_JumpIfInventory("G18Ammo",1,4)
    G18H CDE 1 A_ReFire
    goto Ready+8
    G18H A 0 A_JumpIfNoAmmo("ReloadStart")
    G18H CDE 1 A_ReFire
    goto Ready+8
  FragGrenade:
    U45F A 0 A_ZoomFactor(1.0)
    U45A L 0 A_TakeInventory("Aiming",1)
    U45A L 0 A_TakeInventory("Reloading",1)
    U45F A 0 ACS_ExecuteAlways(602,0,0,0,0)
    U45A L 0 A_JumpIfInventory("Perk1_SOH_Pro",1,"FragGrenade_SOH")
    GRNA A 2 A_PlaySound("grenade/pinpull")
    GRNA BCDEFGH 2
    TNT1 A 15 
    TNT1 A 0 A_PlaySound("grenade/throw")
    GRNA A 0 A_PlaySoundEx("us/grenades","Voice")
    GRNA IJK 2
    GRNA L 0 A_TakeInventory("FragGrenadeAmmo",1)
    GRNA L 0 A_TakeInventory("ThrowingGrenade",1)
    U45A L 0 A_TakeInventory("Aiming",1)
    GRNA L 0 A_TakeInventory("KnifeAttack",1)
    GRNA L 2 A_FireCustomMissile("FragGrenade",0,0,0,16)
    GRNA MN 2 
    goto Ready+1
  FragGrenade_SOH:
    GRNA A 1 A_PlaySound("grenade/pinpull")
    GRNA BCDEFGH 1
    TNT1 A 10
    TNT1 A 0 A_PlaySound("grenade/throw")
    GRNA A 0 A_PlaySoundEx("us/grenades","Voice")
    GRNA IJK 1
    GRNA L 0 A_TakeInventory("FragGrenadeAmmo",1)
    GRNA L 0 A_TakeInventory("ThrowingGrenade",1)
    U45A L 0 A_TakeInventory("Aiming",1)
    GRNA L 0 A_TakeInventory("KnifeAttack",1)
    GRNA L 1 A_FireCustomMissile("FragGrenade",0,0,0,16)
    GRNA MN 1 
    goto Ready+1
  KnifeAttack:
    U45F A 0 A_ZoomFactor(1.0)
    U45A L 0 A_JumpIfInventory("ThrowingGrenade",1,"FragGrenade")
    U45A L 0 A_TakeInventory("Aiming",1)
    U45A L 0 A_TakeInventory("Reloading",1)
    U45F A 0 ACS_ExecuteAlways(602,0,0,0,0)
    U45A L 0 A_JumpIfInventory("Perk1_SOH_Pro",1,"KnifeAttack_SOH")
    U45C A 0 A_JumpIfInventory("Perk3_Commando",1,"KnifeAttack_Commando")
    KNFA A 0 ACS_ExecuteAlways(599,0,0,0,0)
    KNFA AB 1
    KNFA B 0 A_PlaySound("knife/swing")
    KNFA CDE 1 A_CustomPunch(34,1,0,"KnifePuff",96)
    KNFA FGHIJKL 1 
    TNT1 A 20
    GRNA L 0 A_TakeInventory("KnifeAttack",1)
    goto Ready+1
  KnifeAttack_Commando:
    KNFA A 0 ACS_ExecuteAlways(599,0,0,0,0)
    KNFA AB 1
    KNFA B 0 A_PlaySound("knife/swing")
    KNFA CDE 1 A_CustomPunch(34,1,0,"KnifePuff",160)
    KNFA FGHIJKL 1 
    TNT1 A 20
    GRNA L 0 A_TakeInventory("KnifeAttack",1)
    goto Ready+1
  KnifeAttack_SOH:
    U45C A 0 A_JumpIfInventory("Perk3_Commando",1,"KnifeAttack_SOH_Commando")
    KNFA A 0 ACS_ExecuteAlways(599,0,0,0,0)
    KNFA AB 1
    KNFA B 0 A_PlaySound("knife/swing")
    KNFA CDE 1 A_CustomPunch(34,1,0,"KnifePuff",96)
    KNFA FGHIJKL 1 
    TNT1 A 10
    GRNA L 0 A_TakeInventory("KnifeAttack",1)
    goto Ready+1
  KnifeAttack_SOH_Commando:
    KNFA A 0 ACS_ExecuteAlways(599,0,0,0,0)
    KNFA AB 1
    KNFA B 0 A_PlaySound("knife/swing")
    KNFA CDE 1 A_CustomPunch(34,1,0,"KnifePuff",160)
    KNFA FGHIJKL 1 
    TNT1 A 10
    GRNA L 0 A_TakeInventory("KnifeAttack",1)
    goto Ready+1
  }
}

actor G18Clip3 : Ammo
{
    inventory.icon "CLIPA0"
    inventory.amount 0
    inventory.maxamount 66
    ammo.backpackamount 0
    ammo.backpackmaxamount 66
    +IGNORESKILL
}
actor G18Akimbo : Inventory
{
    inventory.amount 0
    inventory.maxamount 1
}

actor G18Pickup : CustomInventory
{
  inventory.pickupmessage "G18"  
  inventory.pickupsound "misc/w_pkup"
  +INVENTORY.AUTOACTIVATE
  inventory.respawntics 35
  scale 0.15
  States
  {
  Spawn:
    WEAP Q -1
    stop
  Pickup:
    JDGP A 0
    JDGP A 0 A_JumpIfInventory("G18",1,"FailPickup") // If the player already has this weapon, they get more ammo for it
    JDGP A 0 A_JumpIfInventory("G18 Ex Mags",1,"FailPickup")
    JDGP A 0 A_JumpIfInventory("G18 Akimbo",1,"FailPickup")
    JDGP A 0 A_JumpIfInventory("MaxWeaponsFilled",0,"FailPickup2")
    BKPK A 0 ACS_ExecuteWithResult(618,15,0,0)
    stop
  AmmoPickup:
    JDGP A 0
    JDGP A 0 A_JumpIfInventory("G18Ammo",0,"FailPickup")
    JDGP A 0 A_GiveInventory("G18Ammo",33)
    stop
  FailPickup:
    WEAP Q 1
    fail
  FailPickup2:
    WEAP Q 1 
    BKPK A 0 ACS_ExecuteAlways(620,0,2,0,0)
    fail
  }
}
