actor "Ranger" : RGUWeapon
{
  obituary "%k blew %o away with the Ranger."
  inventory.pickupmessage "Ranger"  
  //attacksound "ranger/fire"
  weapon.selectionorder 7
  weapon.ammotype "RangerClip"
  weapon.ammouse 1
  weapon.ammogive 0
  weapon.ammotype2 "RangerAmmo"
  weapon.ammouse2 0
  weapon.ammogive2 0
  +NOAUTOFIRE
  states
  {
  Ready:
    RNGA A 2 //A_PlayWeaponSound("m9/select")
    RNGA BCDEFGHIJ 2 A_WeaponReady(WRF_NOPRIMARY)
    RNGA K 0 A_JumpIfNoAmmo("Reload")
    RNGA K 0 A_JumpIfInventory("Reloading",1,"Reload")
    RNGA K 0 A_JumpIfInventory("ThrowingGrenade",1,"FragGrenade")
    RNGA K 0 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    RNGA K 1 A_WeaponReady
    goto Ready+11
  Deselect:
    RNGA J 0 A_TakeInventory("Aiming",1)
    RNGA A 0 ACS_ExecuteAlways(602,0,0,0,0)
    RNGA L 0 A_TakeInventory("Reloading",1)
    RNGA L 0 A_ZoomFactor(1.0)
    RNGA K 0 A_Lower
    RNGA K 1 A_Lower
    goto Deselect+2
  Select:
    M44A A 0 A_Raise
	M44A A 0 ACS_ExecuteAlways(602,0,0,0,0)
	TNT1 F 0 A_GiveInventory("InCombatCrosshair", 35)
    loop
  Fire:	
    RNGA K 1 A_JumpIfNoAmmo("ReloadStart")
    RNGA A 0 A_JumpIfInventory("Perk3_SteadyAim",1,"Fire_SteadyAim")
    RNGA A 0 A_PlayWeaponSound("ranger/fire")
    TNT1 F 0 A_GiveInventory("InCombatCrosshair",35)
    TNT1 F 0 A_GiveInventory("InCombat", 5)
    RNGA A 0 A_FireCustomMissile("WeaponSmokePuff_BigMuzzle",0,0,8,3)
    RNGA A 0 A_FireCustomMissile("WeaponSmokePuffShotgun",0,0,8,3)
    RNGA G 0 BRIGHT A_FireBullets (10.0, 10.0, 8, 5, "ShotgunPuff", 0, 200)
    RNGA G 1 BRIGHT A_FireBullets (10.0, 10.0, 8, 7, "ShotgunPuff", 1, 300)
	RNGA G 1 BRIGHT A_FireBullets (10.0, 10.0, 2, 2, "ShotgunPuff", 0, 500)
    RNGB B 0 BRIGHT ACS_ExecuteAlways(600,0,0,0,0)
    RNGB BC 1 BRIGHT A_GunFlash
    RNGB DE 1 BRIGHT 
    RNGB A 0 A_JumpIfInventory("RangerAmmo",1,4)
    RNGB FGH 1 A_ReFire
    goto Ready+11
    RNGB A 0 A_JumpIfNoAmmo("ReloadStart")
    RNGB FGH 1 A_ReFire
    goto Ready+11
  AltFire:	
	TNT1 F 0 A_GiveInventory("InCombatCrosshair", 35)
	TNT1 F 0 A_GiveInventory("InCombat", 5)
    RNGA K 1 A_JumpIfInventory("RangerClip",2,3)
    RNGA K 1 A_JumpIfInventory("RangerAmmo",1,1)
    goto Ready+11
    RNGA K 1
    goto Reload
    RNGA A 0 A_JumpIfInventory("Perk3_SteadyAim",1,"AltFire_SteadyAim")
    RNGA A 0 A_PlayWeaponSound("ranger/fire")
    TNT1 F 0 A_GiveInventory("InCombatCrosshair",35)
    TNT1 F 0 A_GiveInventory("InCombat", 5)
    RNGA J 0 A_TakeInventory("RangerClip",1)
    RNGA A 0 A_FireCustomMissile("WeaponSmokePuff_BigMuzzle",0,0,8,3)
    RNGA A 0 A_FireCustomMissile("WeaponSmokePuffShotgun",0,0,8,3)
	RNGA G 0 BRIGHT A_FireBullets (10.0, 10.0, 8, 5, "ShotgunPuff", 0, 200)
    RNGA G 1 BRIGHT A_FireBullets (10.0, 10.0, 8, 7, "ShotgunPuff", 1, 300)
	RNGA G 1 BRIGHT A_FireBullets (10.0, 10.0, 2, 2, "ShotgunPuff", 0, 500)
    RNGB B 0 BRIGHT ACS_ExecuteAlways(600,0,0,0,0)
    RNGA A 0 A_PlayWeaponSound("ranger/fire")
    TNT1 F 0 A_GiveInventory("InCombatCrosshair",35)
    TNT1 F 0 A_GiveInventory("InCombat", 5)
    RNGA J 0 A_TakeInventory("RangerClip",1)
    RNGA A 0 A_FireCustomMissile("WeaponSmokePuff_BigMuzzle",0,0,8,3)
    RNGA A 0 A_FireCustomMissile("WeaponSmokePuffShotgun",0,0,8,3)
	RNGA G 0 BRIGHT A_FireBullets (10.0, 10.0, 8, 5, "ShotgunPuff", 0, 200)
    RNGA G 1 BRIGHT A_FireBullets (10.0, 10.0, 8, 7, "ShotgunPuff", 1, 300)
	RNGA G 1 BRIGHT A_FireBullets (10.0, 10.0, 2, 2, "ShotgunPuff", 0, 500)
    RNGB B 0 BRIGHT ACS_ExecuteAlways(600,0,0,0,0)
    RNGB C 2 BRIGHT A_GunFlash
    RNGB DE 1 BRIGHT 
    RNGB A 0 A_JumpIfInventory("RangerAmmo",1,4)
    RNGB FGH 1 A_ReFire
    goto Ready+11
    RNGB FGH 1 A_ReFire
    goto Reload
  //Hold:
  //  RNGA K 3
  //  RNGA K 1 A_ReFire
  //  goto Ready+11
  Reload: //AltFire:
    RNGB A 0 A_JumpIfInventory("RangerAmmo",1,"ReloadStart")
    RNGB A 0 A_TakeInventory("Reloading",1)
    goto Ready+13
  ReloadStart:
  	TNT1 A 0 ACS_ExecuteAlways(652,0,0,0,0) // Shout "Reloading" 
    RNGC A 0 A_JumpIfInventory("Perk1_SOH",1,"ReloadStart_SOH")
    RNGC A 3 A_PlaySoundEx("ranger/open","SoundSlot5")
    RNGC BCDEFG 3 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    RNGC HIJKLM 3 A_WeaponReady(WRF_NOFIRE)
    RNGC N 3 A_PlaySoundEx("ranger/in","SoundSlot5")
    RNGC OPQRS 3 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    RNGC T 3 A_PlaySoundEx("ranger/in","SoundSlot5")
    RNGC R 0 A_TakeInventory("Reloading",1)
    goto ReloadAmmo
  ReloadAmmo:
    RNGC I 0 A_GiveInventory("RangerClip",1)
    RNGC I 0 A_TakeInventory("RangerAmmo",1)
    RNGC I 0 A_JumpIfInventory("RangerClip",2,"ReloadEnd")
    RNGC I 0 A_JumpIfInventory("RangerAmmo",1,"ReloadAmmo")
    goto ReloadEnd
  ReloadEnd:
    RNGC UVWXY 3 A_WeaponReady(WRF_NOFIRE)
    RNGC Z 3 A_PlaySoundEx("ranger/close","SoundSlot5")
    RNGD ABCD 3 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    RNGD C 0 A_ReFire
    goto Ready+11
  Flash:
    TNT1 A 2 bright A_Light1
    TNT1 A 0 bright A_Light0
    stop
  Spawn:
    WEAP U 15
    WEAP U 0 A_SpawnItemEx("RangerPickup")
    stop
  ReloadStart_SOH:
    RNGC A 2 A_PlaySoundEx("ranger/open","SoundSlot5")
    RNGC BCDEFG 2 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    RNGC HIJKLM 2 A_WeaponReady(WRF_NOFIRE)
    RNGC N 2 A_PlaySoundEx("ranger/in","SoundSlot5")
    RNGC OPQRS 2 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    RNGC T 2 A_PlaySoundEx("ranger/in","SoundSlot5")
    RNGC R 0 A_TakeInventory("Reloading",1)
    goto ReloadAmmo_SOH
  ReloadAmmo_SOH:
    RNGC I 0 A_GiveInventory("RangerClip",1)
    RNGC I 0 A_TakeInventory("RangerAmmo",1)
    RNGC I 0 A_JumpIfInventory("RangerClip",2,"ReloadEnd_SOH")
    RNGC I 0 A_JumpIfInventory("RangerAmmo",1,"ReloadAmmo_SOH")
    goto ReloadEnd_SOH
  ReloadEnd_SOH:
    RNGC UVWXY 2 A_WeaponReady(WRF_NOFIRE)
    RNGC Z 2 A_PlaySoundEx("ranger/close","SoundSlot5")
    RNGD ABCD 2 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    RNGD C 0 A_ReFire
    goto Ready+11
  Fire_SteadyAim:
    RNGA A 0 A_PlayWeaponSound("ranger/fire")
    TNT1 F 0 A_GiveInventory("InCombatCrosshair",35)
    TNT1 F 0 A_GiveInventory("InCombat", 5)
    RNGA A 0 A_FireCustomMissile("WeaponSmokePuff_BigMuzzle",0,0,8,3)
    RNGA A 0 A_FireCustomMissile("WeaponSmokePuffShotgun",0,0,8,3)
	RNGA G 0 BRIGHT A_FireBullets (8.0, 8.0, 8, 5, "ShotgunPuff", 0, 200)
    RNGA G 1 BRIGHT A_FireBullets (8.0, 8.0, 8, 7, "ShotgunPuff", 1, 300)
	RNGA G 1 BRIGHT A_FireBullets (8.0, 8.0, 2, 2, "ShotgunPuff", 0, 500)
    RNGB B 0 BRIGHT ACS_ExecuteAlways(600,0,0,0,0)
    RNGB BC 1 BRIGHT A_GunFlash
    RNGB DE 1 BRIGHT 
    RNGB A 0 A_JumpIfInventory("RangerAmmo",1,4)
    RNGB FGH 1 A_ReFire
    goto Ready+11
    RNGB A 0 A_JumpIfNoAmmo("ReloadStart")
    RNGB FGH 1 A_ReFire
    goto Ready+11
  AltFire_SteadyAim:
    RNGA A 0 A_PlayWeaponSound("ranger/fire")
    TNT1 F 0 A_GiveInventory("InCombatCrosshair",35)
    TNT1 F 0 A_GiveInventory("InCombat", 5)
    RNGA J 0 A_TakeInventory("RangerClip",1)
    RNGA A 0 A_FireCustomMissile("WeaponSmokePuff_BigMuzzle",0,0,8,3)
    RNGA A 0 A_FireCustomMissile("WeaponSmokePuffShotgun",0,0,8,3)
	RNGA G 0 BRIGHT A_FireBullets (8.0, 8.0, 8, 5, "ShotgunPuff", 0, 200)
    RNGA G 1 BRIGHT A_FireBullets (8.0, 8.0, 8, 7, "ShotgunPuff", 1, 300)
	RNGA G 1 BRIGHT A_FireBullets (8.0, 8.0, 2, 2, "ShotgunPuff", 0, 500)
    RNGB B 0 BRIGHT ACS_ExecuteAlways(600,0,0,0,0)
    RNGA A 0 A_PlayWeaponSound("ranger/fire")
    TNT1 F 0 A_GiveInventory("InCombatCrosshair",35)
    TNT1 F 0 A_GiveInventory("InCombat", 5)
    RNGA J 0 A_TakeInventory("RangerClip",1)
    RNGA A 0 A_FireCustomMissile("WeaponSmokePuff_BigMuzzle",0,0,8,3)
    RNGA A 0 A_FireCustomMissile("WeaponSmokePuffShotgun",0,0,8,3)
	RNGA G 0 BRIGHT A_FireBullets (8.0, 8.0, 8, 5, "ShotgunPuff", 0, 200)
    RNGA G 1 BRIGHT A_FireBullets (8.0, 8.0, 8, 7, "ShotgunPuff", 1, 300)
	RNGA G 1 BRIGHT A_FireBullets (8.0, 8.0, 2, 2, "ShotgunPuff", 0, 500)
    RNGB B 0 BRIGHT ACS_ExecuteAlways(600,0,0,0,0)
    RNGB C 2 BRIGHT A_GunFlash
    RNGB DE 1 BRIGHT 
    RNGB A 0 A_JumpIfInventory("RangerAmmo",1,4)
    RNGB FGH 1 A_ReFire
    goto Ready+11
    RNGB FGH 1 A_ReFire
    goto Reload
  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 RangerClip : Ammo
{
    inventory.icon "CLIPA0"
    inventory.amount 0
    inventory.maxamount 2
    ammo.backpackamount 0
    ammo.backpackmaxamount 2
    +IGNORESKILL
}

actor RangerPickup : CustomInventory
{
  inventory.pickupmessage "Ranger"  
  inventory.pickupsound "misc/w_pkup"
  +INVENTORY.AUTOACTIVATE
  inventory.respawntics 35
  scale 0.15
  States
  {
  Spawn:
    WEAP U -1
    stop
  Pickup:
    JDGP A 0
    JDGP A 0 A_JumpIfInventory("Ranger",1,"FailPickup") // If the player already has this weapon, they get more ammo for it
    JDGP A 0 A_JumpIfInventory("MaxWeaponsFilled",0,"FailPickup2")
    BKPK A 0 ACS_ExecuteWithResult(618,19,0,0)
    stop
  AmmoPickup:
    JDGP A 0
    JDGP A 0 A_JumpIfInventory("RangerAmmo",0,"FailPickup")
    JDGP A 0 A_GiveInventory("RangerAmmo",4)
    stop
  FailPickup:
    WEAP U 1
    fail
  FailPickup2:
    WEAP U 1 
    BKPK A 0 ACS_ExecuteAlways(620,0,1,0,0)
    fail
  }
}
