ACTOR GezzdtAutomag : UWeapon replaces Pistol
{
	Weapon.SelectionOrder 1200
	Weapon.SlotNumber 2
	Weapon.AmmoType "UClip"
	Weapon.AmmoUse 1
	Weapon.AmmoGive 20
	Weapon.AmmoType2 "UClip"
	Weapon.AmmoUse2 1
	Weapon.AmmoGive2 0
	Inventory.PickupMessage  "You got the Automag." 
	Obituary "%o got gatted by %k's Automag."
	+WEAPON.AMMO_CHECKBOTH
	Tag "Automag"
	Inventory.Icon "1001I0"
	scale 0.1
	States
	{
	Select:
		TNT1 A 0 a_playsound ("automag/cock",6)
		UPRL YZ 1 Offset(1, 32)
		UPR1 ABCDEFGHIJK 1
		TNT1 A 0 A_JumpIfInventory("AutomagMag", 20,"SelectReloadFinish")
		TNT1 A 0 A_JumpIfInventory("UClip", 1, "SelectReload")
		PIDL A 0 A_Raise
		wait
	SelectReload:
		TNT1 A 0 A_TakeInventory ("UClip",1,TIF_NOTAKEINFINITE)
		TNT1 A 0 A_TakeInventory ("Magleer",1,TIF_NOTAKEINFINITE)
		TNT1 A 0 A_GiveInventory("AutomagMag", 1)
		TNT1 A 0 A_GiveInventory("UClip", 1)
		TNT1 A 0 A_JumpIfInventory("AutomagMag", 20, "SelectReloadFinish")
		TNT1 A 0 A_JumpIfInventory("UClip", 1, "SelectReload")
	SelectReloadFinish:
		TNT1 A 0
		PIDL A 0 A_Raise
		goto ready
	Deselect:
		TNT1 A 0 A_Weaponready(WRF_NOFIRE)
		TNT1 A 0 A_Playsound ("weapons/holster", 0)
		TNT1 A 0 A_JumpIfInventory("UClip",1,"holster")
		TNT1 A 0 A_TakeInventory("AutomagMag", 0,TIF_NOTAKEINFINITE)
	holster:
		TNT1 A 0 A_JumpIfInventory ("AutomagAlt",1,"holster2")
		PIDL A 0 A_Lower
		PIDL A 1 A_Lower
		loop
	holster2:
		UPAE A 0 A_Lower
		UPAE A 1 A_Lower
		loop
	Ready:
		TNT1 A 0 A_JumpIfInventory("UClip",1,"Ready1")
		TNT1 A 0 A_TakeInventory("AutomagMag", 0,TIF_NOTAKEINFINITE)
	Ready1:
		PIDL A 1 A_WeaponReady
		Loop
	Fire:
		UPAL A 0 A_JumpIfInventory("UClip",1,1)
		goto reloading
		UPAL A 0 A_JumpIfInventory("AutomagMag",1,1)
		goto reloading
		UPIF AB 2
		TNT1 A 0 A_PlaySound ("automag/Fire",6)
		PFIR A 1 A_Firebullets (0,0,1,17,"UBulletpuff",FBF_USEAMMO|FBF_NORANDOM)
		TNT1 A 0 A_SpawnItemEx("ucasing", 33,cos(pitch)*18,sin(-pitch)*25+42, frandom(0.5,1.2),frandom(0.5,1.2),frandom(1.5,2.5))
		TNT1 A 0 A_Quake(2,3,0,1,"none")
		TNT1 A 0 A_GiveInventory ("Magleer", 1)
		TNT1 A 0 A_TakeInventory("AutomagMag", 1,TIF_NOTAKEINFINITE)
		TNT1 A 0 A_JumpIfInventory("Magleer",17,3)
		UPIF D 2
		TNT1 A 0 A_Jump(256,2)
		UPIF D 2 A_Playsound("weapons/click",7)
		UPIF EFGHIJK 1
		UPIF L 0 A_Refire("Hold")
	Fireend:
		UPIF LMNOPQRSTU 1 A_Weaponready(WRF_NOSWITCH)
		Goto Ready
	Hold:
		UPAL A 0 A_JumpIfInventory("UClip",1,1)
		goto reloading
		UPAL A 0 A_JumpIfInventory("AutomagMag",1,1)
		goto reloading
		TNT1 A 0 A_PlaySound ("automag/Fire",6)
		PFIR A 1 A_Firebullets (0,0,1,17,"UBulletpuff",FBF_USEAMMO|FBF_NORANDOM)
		TNT1 A 0 A_SpawnItemEx("ucasing", 33,cos(pitch)*18,sin(-pitch)*25+42, frandom(0.5,1.2),frandom(0.5,1.2),frandom(1.5,2.5))
		TNT1 A 0 A_Quake(2,3,0,1,"none")
		TNT1 A 0 A_GiveInventory ("Magleer", 1)
		TNT1 A 0 A_TakeInventory("AutomagMag", 1,TIF_NOTAKEINFINITE)
		TNT1 A 0 A_JumpIfInventory("Magleer",17,3)
		UPIF D 2
		TNT1 A 0 A_Jump(256,2)
		UPIF D 2 A_Playsound("weapons/click",7)
		UPIF EFGHIJK 1
		UPIF L 0 A_Refire("Hold")
		Goto Fireend
	AltFire:
		UPAL A 0 A_JumpIfInventory("UClip",1,1)
		goto reloading
		UPAL A 0 A_JumpIfInventory("AutomagMag",1,1)
		goto reloading
		TNT1 A 0 A_GiveInventory ("AutomagAlt",1)
		UPAF ABC 1
		UPAF D 1
		UPAF EFG 1
		UPAF H 1
		UPAF I 1
		TNT1 A 0 A_PlaySound ("automag/Fire")
		PFIR B 1 A_Firebullets (7,5,1,17,"UBulletpuff",FBF_USEAMMO|FBF_NORANDOM)
		TNT1 A 0 A_SpawnItemEx("ucasing", 33,cos(pitch)*10,sin(-pitch)*25+37, frandom(0.5,1.2),frandom(0.5,1.2),frandom(1.5,2.5))
		TNT1 A 0 A_Quake(2,3,0,1,"none")
		TNT1 A 0 A_GiveInventory ("Magleer",1)
		TNT1 A 0 A_TakeInventory("AutomagMag", 1)
		TNT1 A 0 A_JumpIfInventory("Magleer",17,3)
		UPAF K 1
		TNT1 A 0 A_Jump(256,2)
		UPAF K 1 A_Playsound("weapons/click",7)
		UPAF LMNOPQR 1
		TNT1 A 0 A_Refire("AltFireloop")
		goto AltFireend
	AltFireloop:
		UPAL A 0 A_JumpIfInventory("AutomagMag",1,"AltFireloop2")
		goto AltFireend
	AltFireloop2:
		UPAL A 0 A_JumpIfInventory("UClip",1,1)
		Goto AltFireend
		UPAL A 0 A_JumpIfInventory("AutomagMag",1,1)
		Goto AltFireend
		TNT1 A 0 A_PlaySound ("automag/Fire")
		TNT1 A 0 A_GiveInventory ("AutomagAlt",1)
		UPAL A 1
		PFIR C 1 A_Firebullets (7,5,1,17,"UBulletpuff",FBF_USEAMMO|FBF_NORANDOM)
		TNT1 A 0 A_SpawnItemEx("ucasing", 33,cos(pitch)*10,sin(-pitch)*25+37, frandom(0.5,1.2),frandom(0.5,1.2),frandom(1.5,2.5))
		TNT1 A 0 A_Quake(2,3,0,1,"none")
		TNT1 A 0 A_GiveInventory ("Magleer",1)
		TNT1 A 0 A_TakeInventory("AutomagMag", 1)
		TNT1 A 0 A_JumpIfInventory("Magleer",17,3)
		UPAL C 1
		TNT1 A 0 A_Jump(256,2)
		UPAL C 1 A_Playsound("weapons/click",7)
		UPAL DEFGH 1
		UPAL H 0 A_Refire("AltFireloop2")
	AltFireend:
		TNT1 A 0 A_TakeInventory ("AutomagAlt",1)
		UPAE ABCDEFGHIJKLMNOPQRST 1
		TNT1 A 0 A_JumpIfInventory("Magleer",20,"reloading")
		Goto Ready
	reloading:
		TNT1 A 0 A_JumpIfInventory("AutomagMag", 20, 2)
		TNT1 A 0 A_JumpIfInventory("UClip", 1, "Startreload")
		PIDL A 1 A_WeaponReady
		Goto Ready
	Startreload:
		TNT1 A 0 A_PlaySound ("automag/Reload",6)
		UPRL ABCDEFGHIJKLM 1
	ReloadLoop:
		TNT1 A 0 A_TakeInventory ("UClip",1,TIF_NOTAKEINFINITE)
		TNT1 A 0 A_TakeInventory ("Magleer",1,TIF_NOTAKEINFINITE)
		TNT1 A 0 A_GiveInventory("AutomagMag", 1)
		TNT1 A 0 A_GiveInventory("UClip", 1)
		TNT1 A 0 A_JumpIfInventory("AutomagMag", 20, "ReloadFinish")
		TNT1 A 0 A_JumpIfInventory("UClip", 1, "ReloadLoop")
		Goto ReloadFinish
	ReloadFinish:
		TNT1 A 0 A_PlaySound ("automag/cock",6)
		UPRL NOPQRSTUVWXYZ 1
		UPR1 ABCDEFGHIJK 1
		Goto Ready
	Spawn:
		ATMG A -1
		Stop
	}
}

ACTOR AutomagAlt : inventory
{inventory.maxamount 1}

ACTOR AutomagMag : inventory
{inventory.maxamount 20}

actor Magleer : inventory
{inventory.maxamount 20}