ACTOR Matches : G2_Weapon {
	scale 0.2
	Inventory.PickupMessage "Picked up a Lighter"
	Inventory.PickupSound "weapons/lighter_open"
	//Weapon.UpSound "weapons/matches_select"
	Weapon.AmmoType "Matchsticks"
	Weapon.AmmoUse 0
	Weapon.AmmoGive 100
	Weapon.AmmoType2 "MatchstickLife"
	Weapon.AmmoUse2 0
	Weapon.AmmoGive2 0
	+WEAPON.NOAUTOFIRE
	+INVENTORY.UNDROPPABLE
	States
	{
		Spawn:
			LIT1 H 1
			Loop
		Ready:
			MTCH A 1 A_WeaponReady
			MTCH A 0 A_TakeInventory("G2_UsesLightSource",1)
			MTCH A 0 A_TakeInventory("MatchstickLife",10000)
			Goto Ready
		Select:
			MTCH A 1 A_Raise
			MTCH A 0 A_Raise
			Loop
		Deselect:
			MTCH A 0
			MTCH A 0 A_TakeInventory("G2_UsesLightSource",1)
			MTCH A 0 A_Light0
			MTCH A 0 A_JumpIfInventory("MatchstickLife",1,"Altfire")
			MTCH A 1 A_Lower
			MTCH A 0 A_Lower
			Goto Deselect+4
		Fire:
			MTCH A 0
			MTCH A 0 A_JumpIfInventory("MatchstickLife",1,"AltFire")
			MTCH A 0 A_JumpIfInventory("Matchsticks",1,"DoFire")
			MTCH A 15
			goto Ready
		DoFire:
			MTCH A 0 A_GiveInventory("MatchstickLife",10000)
			MTCH A 0 A_PlaySound("Weapons/Matches_Ignite",CHAN_AUTO)
			MTCH A 0 ACS_NamedExecuteWithResult("sound_alert_matches")
			
			MTCH A 1
			MTCH B 1 A_PlaySound("Weapons/Matches_IgniteTip",CHAN_AUTO)
			MTCH C 1
			
			MTCH C 0 A_TakeInventory("Matchsticks",1)
			MTCH DEFGH 2 bright A_SpawnItemEx("MatchesLightprojectile3",0,0,40,random(-2,2),random(-2,2),random(-2,2))
			MTCH IJKL 1 bright
			TNT1 A 0 A_Light1
			TNT1 A 0 A_GiveInventory("G2_UsesLightSource",1)
			TNT1 A 0 ACS_NamedExecuteWithResult("lights_matches")
		Hold:
			TNT1 A 0
			TNT1 A 0 A_FireCustomMissile("G2_IgnitionLight",0,0,0,0,0,0)
			TNT1 A 1 A_WeaponReady
			TNT1 A 0 A_TakeInventory("MatchstickLife",1)
			TNT1 A 0 A_JumpIfInventory("MatchstickLife",1,"Hold")
			goto Drop
		AltFire:
		AltHold:
			MTCH A 0
			MTCH A 0 A_JumpIfInventory("MatchstickLife",100,"DropFull")
			MTCH A 0 A_JumpIfInventory("MatchstickLife",1,"Drop")
			MTCH A 0 A_JumpIfInventory("Matchsticks",3,"DoDrop")
			MTCH A 0 A_JumpIfInventory("Matchsticks", 1, "DropSingle")
			goto Ready
		DoDrop:
			MTCH A 0 A_PlaySound("Weapons/Matches_Drop", CHAN_AUTO)
			MTCH A 0 ACS_NamedExecuteWithResult("sound_alert_matches")
			MTCH A 0 A_FireCustomMissile("ThrownMatchStickPickup")
			MTCH A 11 A_TakeInventory("Matchsticks",3)
			MTCH A 0 A_Refire
			goto Ready
		DropSingle:
			MTCH A 0 A_PlaySound("Weapons/Matches_Drop", CHAN_AUTO)
			MTCH A 0 ACS_NamedExecuteWithResult("sound_alert_matches")
			MTCH A 0 A_FireCustomMissile("ThrownMatchStickPickup2")
			MTCH A 11 A_TakeInventory("Matchsticks",3)
			MTCH A 0 A_Refire
			goto Ready
		DropFull:
			MTCH A 0
			MTCH A 0 A_TakeInventory("MatchstickLife",10000)
			MTCH A 0 A_TakeInventory("G2_UsesLightSource",1)
			MTCH A 0 A_FireCustomMissile("ThrownMatchstick")
			MTCH A 0 A_Light0
			MTCH A 0
			goto Ready
		Drop:
			MTCH A 0
			MTCH A 0 A_TakeInventory("G2_UsesLightSource",1)
			MTCH A 0 A_TakeInventory("MatchstickLife",10000)
			MTCH A 0 A_FireCustomMissile("ThrownMatchstick2")
			MTCH A 0 A_Light0
			MTCH A 0
			goto Ready
	}
}

actor ThrownMatchStick
{
	PROJECTILE
	-NOGRAVITY
	+BOUNCEONWALLS
	+BOUNCEONFLOORS
	+BOUNCEAUTOOFF
	bouncefactor 0.3
	speed 18
	damagetype "fire"
	damage 5
	scale 0.125
	height 3
	radius 2
	States
	{
		Spawn:
			MTST A 0 bright
			MTST A 0 bright Thing_ChangeTID(0, 3495)
			MTST A 0 bright A_GiveInventory("G2_IsThrowable", 1)
			MTST AB 4 bright A_JumpIf(waterlevel > 0,"Off")
			loop
		Off:
			MTST G 0 bright A_GiveInventory("Cell", 1)
			MTST G 350
			stop
		Death:
			MTST A 0 
			MTST A 0 A_JumpIf(waterlevel > 0,"Off")
			MTST A 0 A_JumpIfInventory("Cell", 1, "Off")
			MTST A 0 bright A_SpawnItemEx("ThrownMatchStickClientside", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE | SXF_NOCHECKPOSITION)
			MTST A 0 bright A_SpawnItemEx("ThrownMatchStickServerside", 0, 0, 0, 0, 0, 0, 0, SXF_NOCHECKPOSITION)
			stop
	}
}

actor ThrownMatchStick2 : ThrownMatchStick
{
	States
	{
		Death:
			MTST A 0
			MTST A 0 A_JumpIf(waterlevel > 0,"Off")
			MTST A 0 A_JumpIfInventory("Cell", 1, "Off")
			MTST A 0 bright A_SpawnItemEx("ThrownMatchStickClientside2", 0, 0, 0, 0, 0, 0, 0, SXF_CLIENTSIDE | SXF_NOCHECKPOSITION)
			MTST A 0 bright A_SpawnItemEx("ThrownMatchStickServerside2", 0, 0, 0, 0, 0, 0, 0, SXF_NOCHECKPOSITION)
			stop
	}
}

actor ThrownMatchStickClientSide
{
	scale 0.125
	height 2
	radius 2
	+CLIENTSIDEONLY
	health 1
	States
	{
		Spawn:
			MTST A 0 bright
			MTST A 0 bright A_GiveInventory("G2_IsThrowable", 1)
			MTST A 0 bright Thing_ChangeTID(0, 3500 + ((random(x,x)+10000)/1000) + (((random(y,y)+10000)/1000)*20))
			MTST ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB 4 bright
			MTST CDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCD 4 bright
			MTST EFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEF 4 bright
			MTST GFGFG 3 bright
			stop
		Off_Server:
		Off_Event:
			GSTC A 0 Thing_ChangeTID(0, 3496)
			GSTC A 0 ACS_NamedExecuteWithResult("light_offState")
			fail
		Off_Client:
		Off:
			MTST G 350
			stop
	}
}


actor ThrownMatchStickClientside2 : ThrownMatchStickClientside
{
	States {
		Spawn:
		MTST E 0 bright
		MTST E 0 bright A_GiveInventory("G2_IsThrowable", 1)
		MTST E 0 bright Thing_ChangeTID(0, 3500 + ((random(x,x)+10000)/1000) + (((random(y,y)+10000)/1000)*20))
		MTST EFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEF 4 bright
		MTST GFGFG 3 bright
		Off:
		MTST G 350
		stop
	}
}

actor ThrownMatchStickServerside : ThrownMatchStickClientside
{
	+SERVERSIDEONLY
	-CLIENTSIDEONLY
	renderstyle none
	health 1000
}
actor ThrownMatchStickServerside2 : ThrownMatchStickClientside2
{
	+SERVERSIDEONLY
	-CLIENTSIDEONLY
	renderstyle none
	health 1000
}


ACTOR MatchesLightprojectile {
	+NOCLIP
	-SOLID
	+DONTSPLASH
	+CLIENTSIDEONLY
	+NOTIMEFREEZE
	+NOINTERACTION
	-RANDOMIZE
	States {
		Spawn:
			TNT1 A -1
			Stop
	}
}

ACTOR MatchesLightprojectile2 : MatchesLightprojectile { }
ACTOR MatchesLightprojectile3 : MatchesLightprojectile {
	States {
		Spawn:
			TNT1 AAA 1
			Stop
	}
}

actor G2_Matches_Flare : G2_Flashlight_Flare {
	alpha 0.9
	scale 0.05
	States {
		Spawn:
			LFLR B 1 bright 
			loop
	}
}

actor ThrownMatchStickPickup
{
	PROJECTILE
	-NOGRAVITY
	+DOOMBOUNCE
	bouncefactor 0.3
	speed 18
	scale 0.2
	height 8
	radius 4

	States {
		Spawn:
			MBPC B -1
			loop
		Death:
			MBPC B 0 A_SpawnItem("MatchstickTripple")
			stop
	}
}


actor ThrownMatchStickPickup2 : ThrownMatchStickPickup
{
	States {
		Spawn:
			MBPC C -1
			loop
		Death:
			MBPC C 0 A_SpawnItem("Matchsticks")
			stop
	}
}

ACTOR Matchsticks : Ammo 31103
{
	Inventory.PickupMessage "Picked up a match"
	Inventory.PickupSound "Weapons/Matches_Pickup"
	Inventory.Amount 1
	Inventory.MaxAmount 200
	Ammo.BackpackAmount 35
	Ammo.BackpackMaxAmount 200
	+INVENTORY.IGNORESKILL
	scale 0.2
	States {
		Spawn:
			MBPC C -1
			Stop
	}
}

ACTOR MatchesReturn : Ammo {
	Inventory.PickupMessage "Picked up dummy inventory that keeps track of how many matches player has took from a box..."
	Inventory.Amount 1
	Inventory.MaxAmount 200
	Ammo.BackpackAmount 0
	Ammo.BackpackMaxAmount 200
	+INVENTORY.IGNORESKILL
	States {
		Spawn:
			CLIP A 1
			Stop
	}
}


actor MatchstickTripple : CustomInventory 31104
{
	Inventory.PickupMessage "Picked up three matchsticks"
	Inventory.PickupSound "Weapons/Matches_Pickup"
	scale 0.2
	+INVENTORY.IGNORESKILL
	States
	{
		Spawn:
			MBPC B -1
			loop
		Pickup:
			TNT1 A 0
			TNT1 A 0 A_JumpIfInventory("Matchsticks", 200, "Full")

		Picking:
			TNT1 A 0 
			TNT1 A 0 A_JumpIfInventory("MatchesReturn", 3, "Finish")	
			TNT1 A 0 A_JumpIfInventory("Matchsticks", 200, "Finish")
			TNT1 A 0 A_GiveInventory("Matchsticks", 1)
			TNT1 A 0 A_GiveInventory("MatchesReturn", 1)
			loop
		Finish:
			TNT1 A 0 
			TNT1 A 0 A_JumpIfInventory("MatchesReturn", 3, "Complete")
			TNT1 A 0 A_SpawnItemEx("Matchsticks", 0, 0, 48, frandom(-1, 1), frandom(-1, 1), frandom(1, 2))
			TNT1 A 0 A_GiveInventory("MatchesReturn", 1)
			loop			
		Complete:
			TNT1 A 0 
			TNT1 A 0 A_TakeInventory("MatchesReturn", 200)
			stop

		Full:
			TNT1 A 0
			fail
	}
}


actor MatchstickBox : CustomInventory 31105
{
	Inventory.PickupMessage "Picked up a box of matchsticks"
	Inventory.PickupSound "Weapons/Matches_Pickup"
	scale 0.1
	+INVENTORY.IGNORESKILL
	States
	{
		Spawn:
			MBPC A -1
			loop
		Pickup:
			TNT1 A 0
			TNT1 A 0 A_JumpIfInventory("Matchsticks", 200, "Full")

		Picking:
			TNT1 A 0 
			TNT1 A 0 A_JumpIfInventory("MatchesReturn", 8, "Finish")
			TNT1 A 0 A_JumpIfInventory("Matchsticks", 200, "Finish")
			TNT1 A 0 A_GiveInventory("Matchsticks", 1)
			TNT1 A 0 A_GiveInventory("MatchesReturn", 1)
			loop
		Finish:
			TNT1 A 0 
			TNT1 A 0 A_JumpIfInventory("MatchesReturn", 8, "Complete")
			TNT1 A 0 A_SpawnItemEx("Matchsticks", 0, 0, 48, frandom(-1, 1), frandom(-1, 1), frandom(1, 2))
			TNT1 A 0 A_GiveInventory("MatchesReturn", 1)
			loop			
		Complete:
			TNT1 A 0 
			TNT1 A 0 A_TakeInventory("MatchesReturn", 200)
			stop

		Full:
			TNT1 A 0
			fail
	}
}



ACTOR MatchstickLife : Ammo {
	Inventory.PickupMessage "Picked up a matchstick's life... How cruel!"
	Inventory.Amount 1
	Inventory.MaxAmount 1200
	Ammo.BackpackAmount 0
	Ammo.BackpackMaxAmount 1200
	+INVENTORY.IGNORESKILL
	States {
		Spawn:
			CLIP A 1
			Stop
	}
}