local function FireChemicles(player)
	if G_BuildMapName(mapnum) == "MAPXC" then
	chatprint("\x81".."*".."\x87".."Lava Lifts Zone".."\x81".."* ".."\x85".."Volcanic eruption! Sudden death! Race to the top sector!")
	elseif G_BuildMapName(mapnum) == "MAPXE" then
	chatprint("\x83".."*".."\x81".."Chemical Clash Zone".."\x83".."* ".."\x85".."Draining chemicals! Closing outer sector.")
	elseif G_BuildMapName(mapnum) == "MAPXD" then
	chatprint("\x86".."*".."\x83".."Radioactive Ring Zone".."\x86".."* ".."\x82".."Apmlifying chemical power to painful.")
		elseif G_BuildMapName(mapnum) == "MAPXH" then
	chatprint("\x8F".."*".."\x8D".."Rocket Castle Zone".."\x8F".."* ".."\x85".."The death moat is rising! Flee to the castle!")

	end
end

local function ChemDrain(player)
	if G_BuildMapName(mapnum) == "MAPXE" then
	chatprint("\x83".."*".."\x81".."Chemical Clash Zone".."\x83".."* Chemicals drained! Opening outer sector.")
	elseif G_BuildMapName(mapnum) == "MAPXD" then
	chatprint("\x86".."*".."\x83".."Radioactive Ring Zone".."\x86".."* ".."\x85".."Apmlifying chemical power to lethal.")
	end
end

addHook("LinedefExecute", FireChemicles, "DRAGONEV")
addHook("LinedefExecute", ChemDrain, "DRAGONVE")

mobjinfo[MT_POTION_NOTICE] = {
	doomednum = -1,
	spawnstate = S_POTION_FOLLOW,
	radius = 4*FRACUNIT,
	height = 4*FRACUNIT,
	flags = MF_NOGRAVITY|MF_SCENERY|MF_NOCLIP
}

states[S_POTION_FOLLOW] = {
	sprite = SPR_POTN,
	frame = A,
	tics = 2,
	nextstate = S_NULL
}

/*
yes hi
I did this
pog
*/

addHook("PlayerThink", function(player)
	if player.potion == nil then player.potion = 0 end
	if player.weapongot == nil then player.weapongot = 0 end
	if not (player.mo.PrevWepHeld) then
		player.mo.PrevWepHeld = 0
	end	
	if (player.cmd.buttons & BT_WEAPONPREV) then
		    player.mo.PrevWepHeld = $1+1
	end
	
	if not (player.cmd.buttons & BT_WEAPONPREV) and (player.mo.PrevWepHeld > 0) then
		player.mo.PrevWepHeld = 0
	end	
end)

addHook("MapLoad", function()
	for player in players.iterate do
		player.potion = 0
		player.weapongot = 0
	end
	server.supernova = false
end)

addHook("PlayerThink", function(player)
	if player.mo and player.valid and not player.exiting and not player.powers[pw_nocontrol] and player.playerstate == PST_LIVE
		if player.mo.PrevWepHeld == 1 and (player.cmd.buttons & BT_WEAPONPREV) and player.potion
			player.powers[pw_nocontrol] = 5
				if player.potion == 0
				print("Console note: How the fuck.")
			//	elseif player.potion ==
				elseif player.potion == 1
					player.powers[pw_sneakers] = 10*TICRATE
				elseif player.potion == 2
					player.powers[pw_invulnerability] = 5*TICRATE
				elseif player.potion == 3
					player.mo.momz = (20*FRACUNIT)*P_MobjFlip(player.mo)
				elseif player.potion == 4
					player.rings = 0
					player.powers[pw_invulnerability] = 5*TICRATE
					player.powers[pw_sneakers] = 5*TICRATE
				elseif player.potion == 5
					player.mo.scale = FRACUNIT/4
					player.mo.scalespeed = (FRACUNIT/4)/(TICRATE*10)
					player.mo.destscale = 1*FRACUNIT
				else
				print("Console note: What the fuck.")
				end
			S_StartSound(player.mo,sfx_ptnuse,everyone)
			player.potion = 0
		end
	end
end)

addHook("PlayerThink", function(player)
	if player.mo and player.valid and not player.exiting and not player.powers[pw_nocontrol] and player.playerstate == PST_LIVE
		if not player.mo.PrevWepHeld == 1 and (player.cmd.buttons & BT_WEAPONPREV) and player.weapongot
			UseWeapon(player)
			S_StartSound(player.mo,sfx_wpnuse,everyone)
		end
		if player.weapongot
			WeaponFollow(player)
		end
	end
end)

local function PotionFollow(player)
	if player.mo and player.valid and not player.exiting and player.playerstate == PST_LIVE and player.potion
		if P_MobjFlip(player.mo) == 1
		local potnn = P_SpawnMobj(player.mo.x, player.mo.y, ((player.mo.z)+(player.mo.height))+10*FRACUNIT, MT_POTION_NOTICE)
			if player.potion == 0
			potnn.color = SKINCOLOR_GREY
			elseif player.potion == 1
			potnn.color = SKINCOLOR_BLUE
			elseif player.potion == 2
			potnn.color = SKINCOLOR_SILVER
			elseif player.potion == 3
			potnn.color = SKINCOLOR_YELLOW
			elseif player.potion == 4
			potnn.color = SKINCOLOR_CRIMSON
			elseif player.potion == 5
			potnn.color = SKINCOLOR_ORANGE
			else
			potnn.color = SKINCOLOR_GREY
			end
		else
		local potnn = P_SpawnMobj(player.mo.x, player.mo.y, ((player.mo.z)- (10*FRACUNIT)), MT_POTION_NOTICE)
			if player.potion == 0
			potnn.color = SKINCOLOR_GREY
			elseif player.potion == 1
			potnn.color = SKINCOLOR_BLUE
			elseif player.potion == 2
			potnn.color = SKINCOLOR_SILVER
			elseif player.potion == 3
			potnn.color = SKINCOLOR_YELLOW
			elseif player.potion == 4
			potnn.color = SKINCOLOR_CRIMSON
			elseif player.potion == 5
			potnn.color = SKINCOLOR_ORANGE
			else
			potnn.color = SKINCOLOR_GREY
			end
		end
	end
end

local function PotionGift(line,mo)
	if mo and mo.player.valid and not mo.player.exiting and mo.player.playerstate == PST_LIVE and mo.player.potion == 0
		mo.player.potion = P_RandomRange(1, 5)
	end
end

local function PotionBuy(line,mo)
	if mo and mo.player.valid and not mo.player.exiting and mo.player.playerstate == PST_LIVE and mo.player.potion == 0
		if mo.player.rings >= 25
			mo.player.potion = P_RandomRange(1, 5)
			mo.player.rings = $1-25
			S_StartSound(mo, sfx_chchng)
		else
			S_StartSound(mo, sfx_lose)
		end
	end
end

local function SunsetSlapsUp(line, mo)
	if mo and mo.player.valid and not mo.player.exiting and mo.player.playerstate == PST_LIVE
		mo.momz = 35*FRACUNIT
		mo.state = S_PLAY_PAIN
		S_StartSound(mo, sfx_bsnipe)
	end
end


addHook("PlayerThink", PotionFollow)
addHook("LinedefExecute", PotionGift, "SUNSETPF")
addHook("LinedefExecute", PotionBuy, "SUNSETPB")
addHook("LinedefExecute", SunsetSlapsUp, "SUNSLAPU")



local function WeaponFollow(player)

end

