freeslot("sfx_mch3")
freeslot("sfx_mch4")
freeslot("sfx_mcbp")
freeslot("sfx_bump")
freeslot("sfx_grab")
freeslot("sfx_taunt")
freeslot("sfx_poww")
freeslot("sfx_ouchie")
freeslot("sfx_pizzah")
freeslot("sfx_lap2")
freeslot("sfx_ahh")
freeslot("sfx_ah")
freeslot("sfx_yeow")
freeslot("sfx_aww")
freeslot("sfx_staun")
freeslot("sfx_bash")
freeslot("sfx_sjr")
freeslot("sfx_sjh")
freeslot("sfx_sjs")
freeslot("sfx_cbonk")
freeslot("sfx_kill")
freeslot("sfx_scare")
freeslot("sfx_upper")
freeslot("sfx_roll")
freeslot("sfx_dive")
/* This is the exact same sound has cbonk lol */ freeslot("sfx_bd")
freeslot("sfx_bs")
freeslot("sfx_bl")
freeslot("sfx_mch1")
freeslot("sfx_mch2")
sfxinfo[sfx_mch3].caption = "Mach 3 Run"
sfxinfo[sfx_mch4].caption = "Mach 4 Run"
sfxinfo[sfx_mcbp].caption = "Bump but harder"
sfxinfo[sfx_bump].caption = "Bump"
sfxinfo[sfx_grab].caption = "Grab"
sfxinfo[sfx_taunt].caption = "Strike a Pose!"
sfxinfo[sfx_poww].caption = "Not gonna sugarcoat it"
sfxinfo[sfx_ouchie].caption = "cry cry"
sfxinfo[sfx_pizzah].caption = "IT'S SHOWTIME"
sfxinfo[sfx_lap2].caption = "One more time"
sfxinfo[sfx_ahh].caption = "AHHHHHHHHHHH"
sfxinfo[sfx_ah].caption = ":("
sfxinfo[sfx_yeow].caption = "Yeochie!"
sfxinfo[sfx_aww].caption = "Man..."
sfxinfo[sfx_staun].caption = "Style on your enemies!"
sfxinfo[sfx_bash].caption = "Wind it up and dash!"
sfxinfo[sfx_sjr].caption = "Let's Fly!"
sfxinfo[sfx_sjh].caption = "Steady..."
sfxinfo[sfx_sjs].caption = "Ready for liftoff!"
sfxinfo[sfx_cbonk].caption = "squash"
sfxinfo[sfx_kill].caption = "BAM!"
sfxinfo[sfx_scare].caption = "Uh oh"
sfxinfo[sfx_upper].caption = "Yipee!"
sfxinfo[sfx_roll].caption = "They see me rollin, they hate itit."
sfxinfo[sfx_dive].caption = "Down we go!"
sfxinfo[sfx_bs].caption = "Ready?"
sfxinfo[sfx_bl].caption = "Here we go!"
sfxinfo[sfx_bd].caption = "You ok dude? You hit your head hard."
sfxinfo[sfx_mch1].caption = "Getting started..."
sfxinfo[sfx_mch2].caption = "Almost there..!"
sfxinfo[sfx_hello].caption = "Hello There!"

local pillarboi = nil
local PBPizzaTime = false
local PBStartX = 0
local PBStartY = 0
local PBStartZ = 0
local jind = 77*FRACUNIT
local MaxTime = 9999999
local TimeTilPF = 99999
local PIZZATIME = false
local SpawnSector = nil
local FirstTime = false
local pizzaboispawned = false
local pizzaboi = nil
local Lap2 = false
local SSF_REALEXIT = 1<<7
local lapportal = nil
local sword = nil
local gate = nil
local PRank = false
local STR_MACH = STR_GUARD|STR_WALL|STR_SPIKE
local STR_JUMP = STR_GUARD|STR_CEILING|STR_SPIKE
local STR_SLAM = STR_GUARD|STR_FLOOR|STR_SPIKE|STR_SPRING
local STR_KNIGHT = STR_GUARD|STR_FLOOR|STR_SPIKE|STR_CEILING|STR_WALL
local LapImpossible = false
local SecretCount = 0
rawset(_G, "ModdersBypass", false)
local Warned = false
local Classic = false
local Bash = true
local GFL2 = false
local DefeatedBoss = false
local Lap3 = false //DID I LIE?
rawset(_G, "NoMoveset", false) //I guess I did

addHook("PlayerThink", function(player)
	if player.combo == nil
		player.combo = 0
	end
	if player.comboamount == nil
		player.comboamount = 0
	end
	if player.posed == nil
		player.posed = false
	end
	if (player.combo > 0) and not (player.pflags & PF_FINISHED) and mapheaderinfo[gamemap].bonustype ~= 1 and mapheaderinfo[gamemap].bonustype ~= 2
		player.combo = player.combo - 1
	end
	if player.ignoreexit == nil
		player.ignoreexit = false
	end
	if player.lostfirstcombo == nil
		player.lostfirstcombo = false
	end
	if player.combo == 1
		S_StartSound(player.mo, 163, player)
		player.lostfirstcombo = true
	end
	if player.combo > 200
		player.combo = 200
	end
	if player.enemieskilled == nil
		player.enemieskilled = 0
	end
	if player.supertaunt == nil
		player.supertaunt = false
	end
	if player.enemieskilled == 10
		player.supertaunt = true
		player.enemieskilled = 0
	end
	if player.haslostcombo == nil
		player.haslostcombo = false
	end
	if player.congrats == nil
		player.congrats = false
	end
	if (player.exiting or (player.pflags & PF_FINISHED)) and (player.ignoreexit == false)
		player.combo = 0
		player.congrats = true
		player.ignoreexit = true
	end
	if player.combo == 0
		P_AddPlayerScore(player, player.comboamount*500)
		player.comboamount = 0
		player.enemieskilled = 0
		player.ones = 0
		player.tens = 0
		player.hund = 0
	end
	if player.combo < 0
		player.combo = 0
	end
	if player.ones == nil
		player.ones = 0
	end
	if player.tens == nil
		player.tens = 0
	end
	if player.hund == nil
		player.hund = 0
	end
	if player.ones >= 10
		player.tens = player.tens + 1
		player.ones = player.ones - 10
	end
	if player.tens >= 10
		player.hund = player.hund + 1
		player.tens = player.tens - 10
	end
	if player.machrun == nil
		player.machrun = false
	end
	if player.machrun3 == nil
		player.machrun3 = false
	end
	if player.machrun4 == nil
		player.machrun4 = false
	end
	if (player.cmd.buttons & BT_USE)
		player.machrun = true
	else
		player.machrun = false
	end
	if not NoMoveset
		if (player.charability2 ~= CA2_NONE)
			player.charability2 = CA2_NONE
		end
	end
	if player.rolling == nil
		player.rolling = false
	end
	if player.diving == nil
		player.diving = false
	end
	if player.bodyslam == nil
		player.bodyslam = false
	end
	if player.grabbing == nil
		player.grabbing = 0
	end
	if player.grabbing > 0
		player.grabbing = player.grabbing - 1
	end
	if player.grabbing < 0
		player.grabbing = 0
	end
	if player.grabbing > 30
		player.grabbing = 30
	end
	if player.wallrunning == nil
		player.wallrunning = false
	end
	if player.sliding == nil
		player.sliding = 0
	end
	if player.sliding > 0
		player.sliding = player.sliding - 1
	end
	if player.superjumpbuild == nil
		player.superjumpbuild = false
	end
	if player.superjump == nil
		player.superjump = 0
	end
	if player.superjump > 0
		player.superjump = player.superjump - 1
	end
	if player.bash == nil
		player.bash = 0
	end
	if player.bash > 0
		player.bash = player.bash - 1
	end
	if player.redirecting == nil
		player.redirecting = false
	end
	if player.redirecttimer == nil
		player.redirecttimer = 0
	end
	if player.redirecttimer < 0
		player.redirecttimer = 0
	end
	if Lap2 == true and player.lostfirstcombo == false
		PRank = true
	end
	if player.lostfirstcombo == true and PRank == true
		PRank = false
	end
	if player.transformation == nil
		player.transformation = 0
	end
	if not NoMoveset
		if (player.charability ~= CA_NONE) and (player.transformation == 0)
			player.charability = CA_NONE
		elseif (player.charability ~= CA_DOUBLEJUMP) and (player.transformation == 1)
			player.charability = CA_DOUBLEJUMP
		end
	end
	if not NoMoveset
		if player.normalspeed > 15*FRACUNIT and player.machrun == false and player.mach3 == false and player.mach4 == false and player.taunting == false
			player.normalspeed = 15*FRACUNIT
		end
	end
	if player.knightslide == nil
		player.knightslide = false
	end
	if player.prevx == nil
		player.prevx = 0*FRACUNIT
	end
	if player.prevy == nil
		player.prevy = 0*FRACUNIT
	end
	if player.prevz == nil
		player.prevz = 0*FRACUNIT
	end
	if player.liquiddamage == nil
		player.liquiddamage = false
	end
	if player.losescore == nil
		player.losescore = 0
	end
	if player.crushed == nil
		player.crushed = 0
	end
	if player.squishedtimer == nil
		player.squishedtimer = 0
	end
	if player.squished == nil
		player.squished = false
	end
	if player.jumpcount == nil
		player.jumpcount = 0
	end
	if player.jumping == nil
		player.jumping = false
	end
	if player.smallroll == nil
		player.smallroll = 0
	end
	if player.techdifficulty == nil
		player.techdifficulty = 0
	end
	if player.techscreen == nil
		player.techscreen = false
	end
	if player.boost == nil
		player.boost = 0
	end
	if player.superboost == nil
		player.superboost = 0
	end
	if player.boostedangle == nil
		player.boostedangle = 0*FRACUNIT
	end
	if player.flying == nil
		player.flying = false
	end
	if player.sprung == nil
		player.sprung = false
	end
	if player.homingattack == nil
		player.homingattack = false
	end
	if player.guncooldown == nil
		player.guncooldown = 0
	end
	if player.hammerjumped == nil
		player.hammerjumped = false
	end
	if player.hammerslam == nil
		player.hammerslam = false
	end
	if player.rised == nil
		player.rised = 0
	end
	if player.cantrise == nil
		player.cantrise = false
	end
	if player.breakdance == nil
		player.breakdance = false
	end
	if player.breakdancetimer == nil
		player.breakdancetimer = 0
	end
	if player.normalspeed < 15*FRACUNIT
		player.normalspeed = 15*FRACUNIT
	end
	if player.uncappedspeed == nil
		player.uncappedspeed = false
	end
	if player.ceilbonk == nil
		player.ceilbonk = 0
	end
	if player.knightdrop == nil
		player.knightdrop = false
	end
	if player.redrawangle == nil
		player.redrawangle = player.drawangle
	end
	if player.cooleffect == nil
		player.cooleffect = 0
	end
	if player.windeffect == nil
		player.windeffect = 0*FRACUNIT
	end
	if not LapImpossible
		player.lives = INFLIVES
	elseif not LapImpossible
	and player.lives == INFLIVES
		player.lives = 3
	end
	if player.cmd.buttons & BT_CUSTOM3 > 0 then-- if p is pressing Custom2
		player.custom3down = $1 + 1 -- increment custom2 variable
	else
		player.custom3down = 0 -- reset custom2 variable
	end
	if player.cmd.buttons & BT_FIRENORMAL > 0 then-- if p is pressing Custom2
		player.firenormdown = $1 + 1 -- increment custom2 variable
	else
		player.firenormdown = 0 -- reset custom2 variable
	end
	if player.bashed == nil
		player.bashed = false
	end
	if player.hp == nil
		player.hp = 0
	end
	if player.prevz == nil
		player.previousz = player.mo.z
	end
	if player.mach1 == nil
		player.mach1 = false
	end
	if player.mach2 == nil
		player.mach2 = false
	end
	if player.dish3 == nil
		player.dish3 = false
	end
	if player.sjair == nil
		player.sjair = false
	end
	if player.thenoise == nil
		player.thenoise = false
	end
end)

COM_AddCommand("finalchallenge", function(player, arg)
	if arg == "on" then
		if LapImpossible ~= true
			LapImpossible = true
			print "successfully activated"
		elseif LapImpossible == true
			print "Now's not the time turning something on!"
		end
	elseif arg == "off" then
		if LapImpossible ~= false
			LapImpossible = false
			print "successfully disactivated"
		elseif LapImpossible == false
			print "This was already off silly!"
		end
	else
		print "Not valid, choose on or off"
	end
end, COM_ADMIN)

COM_AddCommand("uncappedspeed", function(player, arg)
	if arg == "on" then
		if player.uncappedspeed ~= true
			player.uncappedspeed = true
			print ("Move as fast as you want!")
		elseif player.uncappedspeed == true
			print ("Already on!")
		end
	elseif arg == "off" then
		if player.uncappedspeed ~= false
			player.uncappedspeed = false
			print ("Your movement is restricted")
		elseif player.uncappedspeed == false
			print ("Already off!")
		end
	else
		print ("Valid Arguments are On and Off!")
	end
end)

COM_AddCommand("suicide", function(player, arg)
	P_KillMobj(player.mo)
end)

COM_AddCommand("SAGETime", function(player, arg)
	if arg == "on" then
		if Classic == false
			Classic = true
			print ("The Pizza Time Bar shall begone!")
		elseif Classic == true
			print ("Already on!")
		end
	elseif arg == "off" then
		if Classic == true
			Classic = false
			print ("We're back in the present day!")
		elseif Classic == false
			print ("Already off!")
		end
	else
		print ("Valid Arguments are On and Off!")
	end
end, COM_ADMIN)

COM_AddCommand("PresentDayBash", function(player, arg)
	if arg == "on" then
		if Bash == false
			Bash = true
			print ("Present Day bash is here!")
		elseif Bash == true
			print ("Already on!")
		end
	elseif arg == "off" then
		if Bash == true
			Bash = false
			print ("It took me so long to make the bash work :(")
		elseif Bash == false
			print ("Already off, but you can turn it back on :)")
		end
	else
		print ("Valid Arguments are On and Off!")
	end
end, COM_ADMIN)

COM_AddCommand("Restart", function(player)
	G_ExitLevel(gamemap, 1)
end, COM_ADMIN)

COM_AddCommand("3dish", function(player, arg)
	if arg == "on" then
		if player.dish3 == false
			player.dish3 = true
			print ("You're now 3d sorta")
		elseif player.dish3 == true
			print ("You're already dish3")
		end
	elseif arg == "off" then
		if player.dish3 == true
			player.dish3 = false
			print ("you are back to 2dish")
		elseif player.dish3 == false
			print ("You are flat")
		end
	else
		print ("Valid Arguments are On and Off!")
		print ("Does the NTOPP dish3 thing")
	end
end)

COM_AddCommand("superjumpinair", function(player)
	if player.sjair == false
		player.sjair = true
		print (L_Choose("WE STOLE YOUR THING NTOPP, I AM THE PIZZA TOWER MOD NOW!", "2 can play that game", "Despicable Me"))
	else
		player.sjair = false
		print (L_Choose("I promise I didn't steal", "Angelic Us", "1 can play that game"))
	end
end)

COM_AddCommand("DisableMoveset", function(player)
	if NoMoveset == false
		NoMoveset = true
		CONS_Printf(player, "You can now use any character in Pizza Blast!")
		player.charability = skins[player.mo.skin].ability
		player.charability2 = skins[player.mo.skin].ability2
		player.normalspeed = skins[player.mo.skin].normalspeed
	else
		NoMoveset = false
		CONS_Printf(player, "Pizza Blast moveset is enabled! Don't use other characters!")
	end
end, COM_ADMIN)

COM_AddCommand("noisemode", function(player)
	if player.mo and player.mo.valid
		if player.noiseunlocked == false
		or not (player.mo and player.mo.valid)
			CONS_Printf(player, "Unknown command 'noisemode'")
		else
			if player.thenoise == false
				player.thenoise = true
				CONS_Printf(player, "Let's make some noise")
			elseif player.thenoise == true
				player.thenoise = false
				CONS_Printf(player, "Now back to THAAT guy :/")
			end
		end
	end
end)


//I just want some cool developer commands, not actually used during testing, more just used for fun!
//So uh, I actually ended up using it! That's cool!
//This mod died before it even released, so these get to stay usable
//The mod is no longer dead? Idk man I all the sudden got inspiration at 11/20/2023

COM_AddCommand("PizzaTime", function(player, arg)
	if arg == "yeth" then
		PBPizzaTime = true
	elseif arg == "nuhuh" then
		PBPizzaTime = false
	end
end, COM_ADMIN)


//This command doesnt work lol
//I made it work
COM_AddCommand("panic", function(player, arg)
	arg = tonumber(arg)
	if arg == nil
		print "Use a number dummy!"
	end
	if arg >= 0
		TimeTilPF = arg*TICRATE
		if not PBPizzaTime
			PBPizzaTime = true
		end
		for mobj in mobjs.iterate(mobj)
			if mobj and mobj.valid
			and mobj.type == MT_PILLARBOI
				P_RemoveMobj(mobj)
			end
		end
	end
	if arg < 0
		print "Make it greather than 0!"
	end
end, COM_ADMIN)

COM_AddCommand("SetTime", function(player, arg)
	arg = tonumber(arg)
	if arg == nil
		print "Use a number dummy!"
	end
	if arg >= 0
		TimeTilPF = arg*TICRATE
	end
	if arg < 0
		print "Make it greather than 0!"
	end
end, COM_ADMIN)

addHook("MobjDamage", function(target, inflictor, source, damagetype)
	if source and source.valid and source.player and source.player.valid and not (source.player.pflags & PF_FINISHED) and (target.flags & MF_ENEMY or target.flags & MF_MONITOR)
		source.player.combo = source.player.combo + 50
	end
end)

addHook("TouchSpecial", function(special, toucher)
	if toucher and toucher.valid and toucher.player.combo > 0 and not (toucher.player.pflags & PF_FINISHED)
		toucher.player.combo = toucher.player.combo + 20
	end
end, MT_RING)

addHook("TouchSpecial", function(special, toucher)
	if toucher and toucher.valid and not toucher.player.powers[pw_flashing] and not (toucher.player.pflags & PF_FINISHED)
		P_AddPlayerScore(toucher.player, 150)
	end
end, MT_RING)

addHook("TouchSpecial", function(special, toucher)
	if toucher.player.starpostnum < special.health and toucher.player.combo > 0 and not (toucher.player.pflags & PF_FINISHED)
		toucher.player.combo = 200
		toucher.player.comboamount = toucher.player.comboamount + 1
		toucher.player.enemieskilled = toucher.player.enemieskilled + 1
	end
	if toucher.player.starpostnum < special.health and not (toucher.player.pflags & PF_FINISHED)
		P_AddPlayerScore(toucher.player, 1000)
	end
end, MT_STARPOST)

addHook("PlayerSpawn", function(player)
	if player.congrats == true
		player.congrats = false
	end
	if player.ignoreexit == true
		player.ignoreexit = false
	end
	if PRank == true
		PRank = false
	end
	if player.mo and player.mo.valid
		player.score = 0
		player.combo = 0
		player.comboamount = 0
		player.enemieskilled = 0
		player.supertaunt = false
		PRank = false
		player.lostfirstcombo = false
		player.transformation = 0
		player.crushed = 0
		player.squished = false
		player.squishedtimer = 0
		player.smallroll = 0
		player.grabbing = 0
		player.sliding = 0
		player.ptportal = 0
		DefeatedBoss = false
		player.scared = {}
		player.gonnadie = {}
		Lap3 = false
		player.bodyslam = false
		player.superjump = 0
		player.divebomb = false
	end
	if mapheaderinfo[gamemap].bonustype > 0
		player.hp = 5
	else
		player.hp = 0
	end
end)

addHook("ThinkFrame", function()
	for player in players.iterate do
		if player.congrats == true
			if player.score < 500
				print(player.name+" just got a D! Sucks to be them!")
				player.congrats = false
			end
			if player.score >= 500 and player.score < 15000
				print(player.name+" just got a C! That's alright...")
				player.congrats = false
			end
			if player.score >= 15000 and player.score < 25000
				print(player.name+" just got a B! They're doing just fine!")
				player.congrats = false
			end
			if player.score >= 25000 and player.score < 30000
				print(player.name+" just got a A! They're doing real good!")
				player.congrats = false
			end
			if player.score >= 30000 and PRank == false
				print(player.name+" just got a S! I'm shocked!")
				player.congrats = false
			end
			if player.score >= 35000 and PRank == true and LapImpossible == false
				print(player.name+" just got a P! A true perfectionist!")
				player.congrats = false
			end
			if player.score >= 35000 and PRank == true and LapImpossible == true
				print(player.name+" is the picture of perfection.")
				player.congrats = false
			end
		end
	end
end)
			

-- The HUD code, developed by MARIOMARIO13531.
-- Some of the code is from boss hud mod made by Inuyasha.
--Lol I took this from Boost, well, the beginning part
local function comb(v, player)
	if player.mo and player.mo.valid
		if (maptol & TOL_NIGHTS) or player.combo == nil then -- Prevents the code from running in a Nights special stage
			return
		end 
		
			local comindanim = ((leveltime/2) % 8) + 1
			local p_comb = v.cachePatch("COMBR") --this junk is mine
			local p_ind = v.cachePatch( 'COMIND' .. comindanim )
			local p_0 = v.cachePatch("NUMB0")
			local p_1 = v.cachePatch("NUMB1")
			local p_2 = v.cachePatch("NUMB2")
			local p_3 = v.cachePatch("NUMB3")
			local p_4 = v.cachePatch("NUMB4")
			local p_5 = v.cachePatch("NUMB5")
			local p_6 = v.cachePatch("NUMB6")
			local p_7 = v.cachePatch("NUMB7")
			local p_8 = v.cachePatch("NUMB8")
			local p_9 = v.cachePatch("NUMB9")
			local posx = (player.combo/3)

		if player.mo.valid and player.combo > 0
		v.drawScaled(posx*FRACUNIT, 15*FRACUNIT, FRACUNIT/2, p_ind, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER|V_HUDTRANS)
		v.drawScaled(FRACUNIT, FRACUNIT, FRACUNIT/2, p_comb, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER|V_HUDTRANS)
			if (player.ones == 0) and (player.tens > 0) or (player.hund > 1)
				v.drawScaled(15*FRACUNIT, 45*FRACUNIT, FRACUNIT/2, p_0, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.ones == 1
				v.drawScaled(15*FRACUNIT, 45*FRACUNIT, FRACUNIT/2, p_1, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.ones == 2
				v.drawScaled(15*FRACUNIT, 45*FRACUNIT, FRACUNIT/2, p_2, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.ones == 3
				v.drawScaled(15*FRACUNIT, 45*FRACUNIT, FRACUNIT/2, p_3, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.ones == 4
				v.drawScaled(15*FRACUNIT, 45*FRACUNIT, FRACUNIT/2, p_4, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.ones == 5
				v.drawScaled(15*FRACUNIT, 45*FRACUNIT, FRACUNIT/2, p_5, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.ones == 6
				v.drawScaled(15*FRACUNIT, 45*FRACUNIT, FRACUNIT/2, p_6, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.ones == 7
				v.drawScaled(15*FRACUNIT, 45*FRACUNIT, FRACUNIT/2, p_7, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.ones == 8
				v.drawScaled(15*FRACUNIT, 45*FRACUNIT, FRACUNIT/2, p_8, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.ones == 9
				v.drawScaled(15*FRACUNIT, 45*FRACUNIT, FRACUNIT/2, p_9, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			end
			if player.tens == 0 and player.hund > 0
				v.drawScaled(5*FRACUNIT, 40*FRACUNIT, FRACUNIT/2, p_0, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.tens == 1
				v.drawScaled(5*FRACUNIT, 40*FRACUNIT, FRACUNIT/2, p_1, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.tens == 2
				v.drawScaled(5*FRACUNIT, 40*FRACUNIT, FRACUNIT/2, p_2, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.tens == 3
				v.drawScaled(5*FRACUNIT, 40*FRACUNIT, FRACUNIT/2, p_3, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.tens == 4
				v.drawScaled(5*FRACUNIT, 40*FRACUNIT, FRACUNIT/2, p_4, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.tens == 5
				v.drawScaled(5*FRACUNIT, 40*FRACUNIT, FRACUNIT/2, p_5, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.tens == 6
				v.drawScaled(5*FRACUNIT, 40*FRACUNIT, FRACUNIT/2, p_6, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.tens == 7
				v.drawScaled(5*FRACUNIT, 40*FRACUNIT, FRACUNIT/2, p_7, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.tens == 8
				v.drawScaled(5*FRACUNIT, 40*FRACUNIT, FRACUNIT/2, p_8, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.tens == 9
				v.drawScaled(5*FRACUNIT, 40*FRACUNIT, FRACUNIT/2, p_9, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			end
			if player.hund == 1
				v.drawScaled(0*FRACUNIT, 30*FRACUNIT, FRACUNIT/2, p_1, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.hund == 2
				v.drawScaled(0*FRACUNIT, 30*FRACUNIT, FRACUNIT/2, p_2, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.hund == 3
				v.drawScaled(0*FRACUNIT, 30*FRACUNIT, FRACUNIT/2, p_3, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.hund == 4
				v.drawScaled(0*FRACUNIT, 30*FRACUNIT, FRACUNIT/2, p_4, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.hund == 5
				v.drawScaled(0*FRACUNIT, 30*FRACUNIT, FRACUNIT/2, p_5, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.hund == 6
				v.drawScaled(0*FRACUNIT, 30*FRACUNIT, FRACUNIT/2, p_6, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.hund == 7
				v.drawScaled(0*FRACUNIT, 30*FRACUNIT, FRACUNIT/2, p_7, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.hund == 8
				v.drawScaled(0*FRACUNIT, 30*FRACUNIT, FRACUNIT/2, p_8, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			elseif player.hund == 9
				v.drawScaled(0*FRACUNIT, 30*FRACUNIT, FRACUNIT/2, p_9, V_SNAPTOTOP|V_SNAPTORIGHT|V_PERPLAYER)
			end
		end
	end
end
hud.add(comb, "game")

local function ranks(v, player)
	if player.mo and player.mo.valid
		if (maptol & TOL_NIGHTS) then -- Prevents the code from running in a Nights special stage
			return
		end 
			local p_rand = v.cachePatch("RANKD") --this junk is mine
			local p_ranc = v.cachePatch("RANKC")
			local p_ranb = v.cachePatch("RANKB")
			local p_rana = v.cachePatch("RANKA")
			local p_rans = v.cachePatch("RANPEE")
			local p_ranp = v.cachePatch("RANKP")
				
		if player.mo.valid and player.score < 500
			v.drawScaled(100*FRACUNIT, 25*FRACUNIT, FRACUNIT/2, p_rand, V_SNAPTOTOP|V_SNAPTOLEFT|V_PERPLAYER|V_HUDTRANS)
		end
		if player.mo.valid and player.score >= 500 and player.score < 15000
			v.drawScaled(100*FRACUNIT, 25*FRACUNIT, FRACUNIT/2, p_ranc, V_SNAPTOTOP|V_SNAPTOLEFT|V_PERPLAYER|V_HUDTRANS)
		end
		if player.mo.valid and player.score >= 15000 and player.score < 25000
			v.drawScaled(100*FRACUNIT, 25*FRACUNIT, FRACUNIT/2, p_ranb, V_SNAPTOTOP|V_SNAPTOLEFT|V_PERPLAYER|V_HUDTRANS)
		end
		if player.mo.valid and player.score >= 25000 and player.score < 30000
			v.drawScaled(100*FRACUNIT, 25*FRACUNIT, FRACUNIT/2, p_rana, V_SNAPTOTOP|V_SNAPTOLEFT|V_PERPLAYER|V_HUDTRANS)
		end
		if player.mo.valid and player.score >= 30000
			v.drawScaled(100*FRACUNIT, 25*FRACUNIT, FRACUNIT/2, p_rans, V_SNAPTOTOP|V_SNAPTOLEFT|V_PERPLAYER|V_HUDTRANS)
		end
		if player.mo.valid and player.score >= 35000 and PRank == true
			v.drawScaled(100*FRACUNIT, 25*FRACUNIT, FRACUNIT/2, p_ranp, V_SNAPTOTOP|V_SNAPTOLEFT|V_PERPLAYER|V_HUDTRANS)
		end
	end
end
hud.add(ranks, "game")

addHook("PlayerThink", function(player)
	if NoMoveset return end
	if (player.cmd.buttons & BT_FIRENORMAL) and (player.supertaunt == true) and (player.transformation == 0)
		player.mo.state = S_PLAY_SUPER_TRANS1
		player.tauntbubble = P_SpawnMobj(player.mo.x, player.mo.y, player.mo.z, MT_TAUNT)
		player.tauntbubble.scale = player.mo.scale + FRACUNIT/6
		P_NukeEnemies(player.mo, player.mo, 2500*FRACUNIT)
		S_StartSound(player.mo, sfx_staun)
		player.supertaunt = false
	end
end)

//There was supposed to be a sponsored segment of PTAI, but instead, get *bonk*
addHook("PlayerThink", function(player)
if NoMoveset return end
	if player and player.valid and player.mo.valid then
		if P_IsObjectOnGround(player.mo) or (player.mo.eflags & MFE_SPRUNG)
			player.bonk = false
		end
	end
end)
	

addHook("MobjMoveBlocked", function(mo, mobj, line)
if NoMoveset return end
local player = mo.player
	if mobj and mobj.valid return end
	if line and line.valid
	and (player.bonk == false 
	and (player.mach3 == true or player.mach4 == true) 
	and P_IsObjectOnGround(player.mo)) 
	and not (player.thenoise == true and player.mo.standingslope)
	or player.diving or player.sliding
		P_DoPlayerPain(player)
		player.normalspeed = 20*FRACUNIT
		if player.mach3 == true
			S_StartSound(player.mo, sfx_bump)
		elseif player.mach4 == true
			S_StartSound(player.mo, sfx_mcbp)
		end
		if player.transformation > 0
			player.transformation = 0
		end
		player.bonk = true
	end
end, MT_PLAYER)
				
// Now it's back to me :D

local function PB_LaunchEnemies(player)
	searchBlockmap("objects", function(refmobj, foundmobj)
		if foundmobj and foundmobj.valid
		and ((foundmobj.flags & MF_ENEMY) or (foundmobj.flags & MF_MONITOR) or (foundmobj.flags & MF_SPRING))
		and not (foundmobj.flags & MF_NOGRAVITY)
			P_SetObjectMomZ(foundmobj, 20*FRACUNIT, false)
		end
	end, player.mo, player.mo.x - 512*FRACUNIT, player.mo.x + 512*FRACUNIT, player.mo.y - 512*FRACUNIT, player.mo.y + 512*FRACUNIT)
end

addHook("PlayerThink", function(player)
if NoMoveset return end
	if not player.rolling and (player.machrun == true) and (player.cmd.buttons & BT_CUSTOM1) and (P_IsObjectOnGround(player.mo)) and (player.grabbing == 0) and (player.sliding == 0) and (player.transformation == 0) and not (player.liquiddamage) and not (player.superjumpbuild) and (player.superjump == 0)
		player.rolling = true
		S_StartSoundAtVolume(player.mo, sfx_roll, 55)
	end
	if player.rolling and ((player.machrun == false) or not (player.cmd.buttons & BT_CUSTOM1) or not (P_IsObjectOnGround(player.mo)) or (player.grabbing > 0) or (player.sliding > 0) or (player.transformation > 0) or (player.mo.eflags & MFE_SPRUNG) or (player.liquiddamage))
		player.rolling = false
		if S_SoundPlaying(player.mo, sfx_roll)
			S_StopSoundByID(player.mo, sfx_roll)
		end
	end
	if player.rolling == true
		player.mo.state = S_PLAY_ROLL
		player.height = 1572864
	else
		player.height = 3145728
	end
	if not player.diving and (player.machrun == true) and (player.cmd.buttons & BT_CUSTOM1) and not (P_IsObjectOnGround(player.mo)) and (player.speed >= 40*FRACUNIT) and (player.grabbing == 0) and (player.sliding == 0) and (player.transformation == 0) and not (player.liquiddamage) and (player.superjump == 0) and not player.divebomb
		player.diving = true
		S_StartSound(player.mo, sfx_dive)
		if player.thenoise
			P_SetObjectMomZ(player.mo, -30*FRACUNIT, false)
		end
	end
	if player.diving and ((player.machrun == false) or (player.thenoise == false and P_IsObjectOnGround(player.mo)) or (player.grabbing > 0) or (player.sliding > 0) or (player.mo.eflags & MFE_GOOWATER or player.powers[pw_carry] or P_PlayerInPain(player) or player.playerstate == PST_DEAD or (player.mo.eflags & MFE_SPRUNG)) or (player.transformation > 0) or (player.mo.eflags & MFE_SPRUNG) or (player.liquiddamage) or player.divebomb)
		player.diving = false
		if S_SoundPlaying(player.mo, sfx_dive)
			S_StopSoundByID(player.mo, sfx_dive)
		end
	end
	if player.diving == true
		if not player.thenoise
			P_SetObjectMomZ(player.mo, -30*FRACUNIT, false)
		else
			if (P_IsObjectOnGround(player.mo) or (player.mo.eflags & MFE_JUSTHITFLOOR))
				player.diving = false
				P_DoJump(player, true)
				player.walllaunch = true
			end
		end
	end
	if not player.bodyslam and (player.cmd.buttons & BT_CUSTOM1) and not (P_IsObjectOnGround(player.mo)) and (player.speed <= 39*FRACUNIT) and (player.grabbing == 0) and (player.sliding == 0) and (player.transformation == 0) and not (player.liquiddamage) and (player.superjump == 0) and not (player.superjumpbuild)
		player.bodyslam = true
		S_StartSound(player.mo, sfx_bs)
		P_DoJump(player, true)
	end
	if player.bodyslam
		if not S_SoundPlaying(player.mo, sfx_bs)
			if not S_SoundPlaying(player.mo, sfx_bl)
				S_StartSound(player.mo, sfx_bl)
			end
		end
	end
	if P_IsObjectOnGround(player.mo) and player.bodyslam == true or player.grabbing > 0 and player.bodyslam == true or player.sliding > 0 and player.bodyslam == true or ((player.mo.eflags & MFE_GOOWATER) or player.powers[pw_carry] or P_PlayerInPain(player) or (player.playerstate == PST_DEAD) or (player.transformation > 0) or (player.mo.eflags & MFE_SPRUNG) or (player.liquiddamage)) and player.bodyslam
		player.bodyslam = false
		S_StartSound(player.mo, sfx_bd)
		if P_IsObjectOnGround(player.mo)
			PB_LaunchEnemies(player)
		end
		if S_SoundPlaying(player.mo, sfx_bl)
			S_StopSoundByID(player.mo, sfx_bl)
		end
		if S_SoundPlaying(player.mo, sfx_bs)
			S_StopSoundByID(player.mo, sfx_bs)
		end
		if player.mo.skin == "knuckles"
			P_NukeEnemies(player.mo, player.mo, 1000*FRACUNIT)
			S_StartSound(player.mo, 93)
			P_InstaThrust(player.mo, player.mo.angle, 0*FRACUNIT)
			player.mo.state = S_PLAY_GLIDE_LANDING
		end
		if player.mo.standingslope
			P_InstaThrust(player.mo, player.drawangle, 40*FRACUNIT)
			if not player.mach3
				player.normalspeed = 40*FRACUNIT
			end
		end
	end
	if player.bodyslam == true
		P_SetObjectMomZ(player.mo, -FRACUNIT/2, true)
	end
end)

addHook("PlayerThink", function(player)
if NoMoveset return end
	if (player.cmd.buttons & BT_ATTACK) and not (player.rolling) and not (player.diving) and not (player.bodyslam) and (player.grabbing == 0) and (player.superjump == 0) and not (player.bash) and (player.transformation == 0) and not (player.liquiddamage) and not (player.superjumpbuild) and not player.bashed and not player.sliding and not player.redirecting and not player.wallrunning
		player.grabbing = 30
	end
	if player.grabbing > 0
		player.normalspeed = 30*FRACUNIT
		P_InstaThrust(player.mo, player.mo.angle, 30*FRACUNIT)
		player.mo.state = S_PLAY_ROLL
		if not S_SoundPlaying(player.mo, sfx_grab)
			S_StartSound(player.mo, sfx_grab)
		end
	end
	if player.grabbing == 1
		player.normalspeed = 30*FRACUNIT
		player.mo.state = S_PLAY_RUN
	end
	if (player.grabbing > 0) and (player.cmd.buttons & BT_CUSTOM1) and (P_IsObjectOnGround(player.mo)) and (player.transformation == 0) and not (player.liquiddamage)
		player.sliding = 40
		player.grabbing = 0
	elseif not (P_IsObjectOnGround(player.mo) or player.transformation > 0) and (player.sliding)
		if not (player.pflags & PF_JUMPED)
			player.sliding = 0
			player.height = 3145728
			player.diving = true
			player.mo.state = S_PLAY_FALL
		elseif (player.pflags & PF_JUMPED)
			player.normalspeed = 20*FRACUNIT
		end
	end
	if player.sliding > 15
		P_InstaThrust(player.mo, player.mo.angle, 40*FRACUNIT)
		player.mo.state = S_PLAY_PAIN
		player.height = 1572864
	elseif player.sliding > 1 and player.sliding < 15
		P_InstaThrust(player.mo, player.mo.angle, 40*FRACUNIT)
		player.mo.state = S_PLAY_ROLL
		player.height = 1572864
	elseif player.sliding == 1
		player.normalspeed = 40*FRACUNIT
		player.mo.state = S_PLAY_RUN
		player.height = 3145728
	end
	if player.sliding > 1 or player.grabbing
		player.normalspeed = 30*FRACUNIT
	end
end)

addHook("MobjMoveBlocked", function(mo, mobj, line)
if NoMoveset return end
local player = mo.player
	if mobj and mobj.valid return end
	if line and line.valid
	and (player.machrun == true) 
	and not (P_IsObjectOnGround(player.mo)) 
	and ((player.pflags & PF_JUMPED) 
	or not player.grabbing 
	or not player.sprung) 
	and (player.transformation == 0) 
	and not player.divebomb 
	and not player.diving
	and not player.bodyslam
	and not player.bonk
	and not player.walllaunch
		if not player.thenoise
			player.wallrunning = true
		elseif player.thenoise
		and (player.cmd.buttons & BT_JUMP)
			player.walllaunch = true
			P_DoJump(player, true)
			P_SetObjectMomZ(player.mo, 30*FRACUNIT, false)
			player.mo.state = S_PLAY_SPRING
		end
	end
end, MT_PLAYER)

addHook("PlayerThink", function(player)
if NoMoveset return end
	if not (player.powers[pw_pushing] or player.transformation > 0 or not (player.machrun or (player.cmd.buttons & BT_USE))) and (player.wallrunning == true)
		player.wallrunning = false
		P_InstaThrust(player.mo, player.mo.angle, player.normalspeed)
		P_SetObjectMomZ(player.mo, 0*FRACUNIT, false)
	end
	if (player.wallrunning == true) and (player.cmd.buttons & BT_JUMP)
		if player.mach3
			P_InstaThrust(player.mo, player.mo.angle, -10*FRACUNIT)
		elseif player.mach4
			P_InstaThrust(player.mo, player.mo.angle, -20*FRACUNIT)
		elseif player.mach4 and player.normalspeed == 80*FRACUNIT
			P_InstaThrust(player.mo, player.mo.angle, -30*FRACUNIT)
		elseif player.mach4 and player.normalspeed > 80*FRACUNIT
			P_InstaThrust(player.mo, player.mo.angle, ((player.normalspeed/2) - 10))
		else
			P_InstaThrust(player.mo, player.mo.angle, -5*FRACUNIT)
		end
		P_SetObjectMomZ(player.mo, 15*FRACUNIT, false)
		player.mo.angle = R_PointToAngle2(0,0,player.mo.momx,player.mo.momy)
		player.mo.state = S_PLAY_FALL
		player.wallrunning = false
	end
	if player.wallrunning == true
		P_InstaThrust(player.mo, player.mo.angle, 10*FRACUNIT)
		player.normalspeed = player.normalspeed + (FU/3)
		player.mo.state = S_PLAY_SPRING
		if player.mach3
			P_SetObjectMomZ(player.mo, 20*FRACUNIT, false)
		elseif player.mach4
			P_SetObjectMomZ(player.mo, 30*FRACUNIT, false)
		elseif player.normalspeed == 80*FRACUNIT and player.mach4
			P_SetObjectMomZ(player.mo, 40*FRACUNIT, false)
		elseif player.normalspeed > 80*FRACUNIT and player.mach4
			P_SetObjectMomZ(player.mo, (player.normalspeed/2), false)
		else
			P_SetObjectMomZ(player.mo, 10*FRACUNIT, false)
		end
	end
end)

addHook("PlayerThink", function(player)
if NoMoveset return end
	if ((player.sjair == false and P_IsObjectOnGround(player.mo) or player.sjair == true and not player.sjnosj) and (player.cmd.buttons & BT_CUSTOM2) and (player.mach3 == true or (player.mach4 == true)) and (player.sliding == 0) and (player.wallrunning == false) and (player.grabbing == 0) and not (player.diving) and not (player.rolling) and not (player.bodyslam) and (player.transformation == 0) and not (player.liquiddamage) and not (player.superjumpbuild))
		player.superjumpbuild = true
		S_StartSound(player.mo, sfx_sjs)
	end
	if not (player.cmd.buttons & BT_CUSTOM2) and player.superjumpbuild == true and not (player.liquiddamage)
		player.superjump = 60
		player.superjumpbuild = false
		if S_SoundPlaying(player.mo, sfx_sjs)
			S_StopSoundByID(player.mo, sfx_sjs)
		end
		if S_SoundPlaying(player.mo, sfx_sjh)
			S_StopSoundByID(player.mo, sfx_sjh)
		end
		S_StartSound(player.mo, sfx_sjr)
	end
	if player.superjumpbuild == true
		player.normalspeed = 5*FRACUNIT
		player.mo.state = S_PLAY_SPINDASH
		player.pflags = $ + PF_JUMPSTASIS
		if not S_SoundPlaying(player.mo, sfx_sjs)
			if not S_SoundPlaying(player.mo, sfx_sjh)
				S_StartSound(player.mo, sfx_sjh)
			end
		end
	end
	if player.superjump > 1
		P_SetObjectMomZ(player.mo, player.superjump*FRACUNIT, false)
		player.mo.state = S_PLAY_SPRING
		player.pflags = $ + PF_FULLSTASIS
		P_InstaThrust(player.mo, player.mo.angle, 0*FRACUNIT)
		player.normalspeed = 30*FRACUNIT
		player.drawangle = player.redrawangle
		player.redrawangle = $ + ANG20
		if player.sjair == true
			player.sjnosj = true
		end
	end
	
	if (P_IsObjectOnGround(player.mo)
	or (player.mo.eflags & MFE_JUSTHITFLOOR))
	and player.sjnosj == true
		player.sjnosj = false
	end
	if player.mo.momz == 0 and player.superjump > 1
		player.superjump = 0
	end
	if player.superjump == 1
		player.mo.state = S_PLAY_PAIN
		player.pflags = $  & ~PF_FULLSTASIS
		player.pflags = $  & ~PF_JUMPSTASIS
		player.normalspeed = 15*FRACUNIT
	end
	if Bash == true
	if player.superjump > 1 and (player.cmd.buttons & BT_ATTACK)
		player.superjump = 0
		player.bash = 20
		S_StartSound(player.mo, sfx_bash)
	end
	if player.bash > 1
		P_SetObjectMomZ(player.mo, 0*FRACUNIT, false)
		player.mo.state = S_PLAY_ROLL
	end
	if player.bash == 1
		P_InstaThrust(player.mo, player.mo.angle, 40*FRACUNIT)
		player.normalspeed = 40*FRACUNIT
		player.pflags = $ + PF_JUMPED
	end
	elseif Bash == false
		if player.superjump > 1 and (player.cmd.buttons & BT_ATTACK)
			player.superjump = 0
			P_SetObjectMomZ(player.mo, 0*FRACUNIT, false)
			P_InstaThrust(player.mo, player.mo.angle, 40*FRACUNIT)
			player.normalspeed = 40*FRACUNIT
			player.pflags = $ + PF_JUMPED
			player.mo.state = S_PLAY_RUN
			player.bashed = true
			local x,y = cos(player.drawangle),sin(player.drawangle)
			local runmacheffect = P_SpawnMobjFromMobj(player.mo,-30*x,-30*y,0,MT_MACHE)
			runmacheffect.angle = (R_PointToAngle2(runmacheffect.x, runmacheffect.y, player.mo.x, player.mo.y) + ANGLE_90)
		end
	end
	if (P_IsObjectOnGround(player.mo) or player.mo.eflags & MFE_JUSTHITFLOOR) and player.bashed
		player.bashed = false
	end
	if (player.mo.z+player.mo.height == player.mo.ceilingz or (player.mo.flags2 & MF2_OBJECTFLIP) and player.mo.z+player.mo.height == player.mo.floorz) and player.superjump > 0
		player.superjump = 0
		player.squished = true
		player.squishedtimer = 30
		player.ceilbonk = 30
		player.transformation = 2
		player.mo.spriteyscale = (FU/3)
		player.mo.spritexscale = (player.mo.spriteyscale*8)
		player.height = 1048576
		S_StartSound(player.mo, sfx_cbonk)
	end
	if player.ceilbonk > 1
		player.ceilbonk = player.ceilbonk - 1
		P_SetObjectMomZ(player.mo, 100*FRACUNIT, false)
		P_InstaThrust(player.mo, player.mo.angle, 0*FRACUNIT)
		player.smallroll = 0
		player.mo.state = S_PLAY_DEAD
	elseif player.ceilbonk == 1
		player.ceilbonk = player.ceilbonk - 1
		P_SetObjectMomZ(player.mo, 100*FRACUNIT, false)
		P_InstaThrust(player.mo, player.mo.angle, 0*FRACUNIT)
		player.mo.state = S_PLAY_PAIN
	end
end)

// Sponsored Segment for TGTLS!
addHook("PlayerThink", function(p)
	if not (p.cmd.buttons & BT_TOSSFLAG)
	and not p.taunting
	and p.mo and p.mo.valid
		p.prevmomx = p.mo.momx
		p.prevmomy = p.mo.momy
		p.prevmomz = p.mo.momz
		p.prevstate = p.mo.state
		p.prevspeed = p.normalspeed
	end
	if p.tftics == nil
		p.tftics = 0
	end
	if (p.cmd.buttons & BT_TOSSFLAG) and (p.transformation == 0) and not (p.liquiddamage)
		p.tftics = $1+1
	else
		p.tftics = 0
	end
end)

addHook("PostThinkFrame", do
if NoMoveset return end
	for p in players.iterate
		
		if p.tauntingtimer == nil
			p.tauntingtimer = 0
		end
		
		if p.tftics == 1
		and not p.taunting
		and p.mo and p.mo.valid
		and not p.powers[pw_carry]
		and p.playerstate == PST_LIVE
		and not P_PlayerInPain(p)
		and not p.powers[pw_nocontrol]
		and p.grabbing == 0
		and not p.bodyslam
		and not p.diving
		and not p.rolling
		and not p.superjumpbuild
		and p.superjump == 0
		and p.bash == 0
		and not p.wallrunning
		and p.sliding == 0
			S_StartSound(p.mo, sfx_taunt)
			p.taunting = true
		end
		if p.taunting == nil
			p.taunting = false
		end
		if p.taunting == true
			p.mo.momx = 0
			p.tauntbubble = P_SpawnMobj(p.mo.x,p.mo.y,p.mo.z,MT_TAUNT)
			p.tauntbubble.scale = p.mo.scale+FRACUNIT/6
			p.mo.momy = 0
			p.mo.momz = 0
			p.normalspeed = 15*FRACUNIT
			p.grabbing = 0
			p.pflags = $|PF_JUMPSTASIS
			p.tauntingtimer = $1+1
			if p.posed
			and p.mo.state ~= p.ps
				p.mo.state = p.ps
			end
			if PBPizzaTime
				p.score = p.score + 8
			end
		end
		if (p.mo.eflags & MFE_VERTICALFLIP)
			p.tauntbubble.eflags = $|MFE_VERTICALFLIP
		end
		if p.tauntingtimer == 16
			p.taunting = false
			p.tauntingtimer = 0
			p.tauntbubble = nil
			p.mo.momx = p.prevmomx
			p.mo.momy = p.prevmomy
			p.pflags = $ & ~PF_JUMPSTASIS
			p.mo.momz = p.prevmomz
			p.mo.state = p.prevstate
			p.normalspeed = p.prevspeed
			p.posed = false
			if (p.cmd.buttons & BT_TOSSFLAG) and p.speed == 0*FRACUNIT
				p.breakdance = true
			end
		end
	end
end)

//made by clairbun
rawset(_G, "L_Choose", function(...)
	local args = {...}
	local choice = P_RandomRange(1,#args)
	return args[choice]
end)

addHook("PostThinkFrame", function()
if NoMoveset return end
	for p in players.iterate()
		if p.taunting
		and p.mo and p.mo.valid
		and p.posed == false
			p.mo.state = L_Choose(S_PLAY_ROLL,S_PLAY_SPRING,S_PLAY_PAIN,S_PLAY_DEAD,S_PLAY_RUN,S_PLAY_WAIT,S_PLAY_SUPER_TRANS1,S_PLAY_EDGE,S_PLAY_STND,S_PLAY_SPINDASH,S_PLAY_DASH)
			p.posed = true
			p.ps = p.mo.state
		end
	end
end)

// A little bit of code from another project

addHook("ShouldDamage", function(target, inflictor)
if NoMoveset return end
	if target and target.valid
	and inflictor and inflictor.valid
	and target.player and target.player.valid
	//and (inflictor.flags & MF_MISSILE)
	and target.player.taunting
		local player = target.player
		player.powers[pw_flashing] = 1*TICRATE
		inflictor.momx = -$
		inflictor.momy = -$
		inflictor.momz = -$
		inflictor.target = target
		player.taunting = false
		player.tauntingtimer = 0
		S_StartSound(target, sfx_poww)
		P_InstaThrust(target, target.angle, -7*FRACUNIT)
		target.state = L_Choose(S_PLAY_SUPER_TRANS1, S_PLAY_ROLL, S_PLAY_STND)
		if player.mo.state == S_PLAY_SUPER_TRANS1
			player.powers[pw_flashing] = $ + 1*TICRATE
		end
		return false
	end
end)

addHook("ShouldDamage", function(target, inflictor, source, damage, damagetype)
if NoMoveset return end
    if target and target.valid
	and inflictor and inflictor.valid
	and source and source.valid
    and target.player.taunting
	and not (inflictor.flags & MF_MISSILE)
		target.player.powers[pw_flashing] = 1*TICRATE
		if source.player and source.player.valid
			P_KillMobj(source, target, target)
		else
			P_DamageMobj(source, target, target)
		end
		target.player.taunting = false
		target.player.tauntingtimer = 0
		S_StartSound(target, sfx_poww)
		P_InstaThrust(target, target.angle, -7*FRACUNIT)
		target.state = L_Choose(S_PLAY_SUPER_TRANS1, S_PLAY_ROLL, S_PLAY_STND)
		if inflictor.type == MT_PIZZAFACE
			target.player.powers[pw_invulnerability] = 1*TICRATE
			inflictor.state = S_PIZZAFACERECOVER
		end
        return false
    end
end, MT_PLAYER)

// Sponsored Segment Over, back to me!

addHook("PlayerThink", function(player) // My Check (garbage)
	if (PBPizzaTime == true) and (player.speed == 0*FRACUNIT) and (P_IsObjectOnGround(player.mo)) and (player.mo.state == S_PLAY_WALK or player.mo.state == S_PLAY_STND or player.mo.state == S_PLAY_WAIT)
		player.mo.sprite2 = SPR2_CNT1
	end
	if player.speed ~= 0*FRACUNIT and player.mo.sprite2 == SPR2_CNT1
		player.mo.state = S_PLAY_WALK
	end
end)

addHook('MapLoad', function()
	PBPizzaTime = false
	PBStartX = 0*FRACUNIT
	PBStartY = 0*FRACUNIT
	PBStartZ = 0*FRACUNIT
	jind = 77*FRACUNIT
	PIZZATIME = false
	FirstTime = false
	pizzaboispawned = false
	Lap2 = false
	SpawnSector = nil
	PRank = false
	pillarboi = nil
	SecretCount = 0
	GFL2 = false
end)

addHook("MapLoad", function() //omg guys, look, it;s the uhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh map thing load
local PBLapPortalReal = nil
local NoPBStart = false
	for thing in mapthings.iterate
		if thing.type == 501
			pillarboi = P_SpawnMobj(thing.x*FU,thing.y*FU,thing.z*FU,MT_PILLARBOI)
			pillarboi.inv = 0
			pillarboi.hits = 0
			pillarboi.isdead = false
			pillarboi.hitby = {}
			pillarboi.hittimer = 10*TICRATE
			pillarboi.deadtime = 5*TICRATE
			PBStartX = thing.x*FU
			PBStartY = thing.y*FU
			PBStartZ = thing.z*FU
			P_RemoveMobj(thing.mobj)
		else
			NoPBStart = true
		end
		if thing.type == 3002
			PBLapPortalReal = true
		end
		if NoPBStart
		and thing.type == 3005
			PBStartX = thing.x*FU
			PBStartY = thing.y*FU
			PBStartZ = thing.z*FU
			P_RemoveMobj(thing.mobj)
		end
	end
	for sector in sectors.iterate do
		if (sector.specialflags & SSF_REALEXIT) and (pillarboi ~= nil)
			sector.specialflags = 0
		end
	end
end)


// Another sponsor, welcome in Nick!

addHook('TouchSpecial', function(lapportal, mo)
local player = mo.player
	if lapportal.fake return end
	if Lap2 == false 
	and PBPizzaTime == true
	and not player.ptportal
	or PBPizzaTime
	and Lap2
	and not Lap3
	and gamemap == 28
	and LapImpossible
	and not player.ptportal
		if not Lap2
			local fakeportal = P_SpawnMobj(PBStartX, PBStartY, PBStartZ, MT_LAPPORTAL)
			fakeportal.tics = 50
			fakeportal.fake = true
			fakeportal.target = player.mo
			player.ptportal = 50
			if player.comboamount > 0
				player.combo = 200
			end
			P_InstaThrust(player.mo, player.mo.angle, 0*FRACUNIT)
			player.score = player.score + 10000
			Lap2 = true
			if gamemap == 28
			and LapImpossible
				local SNICK = P_SpawnMobj(PBStartX - 50*FRACUNIT, PBStartY - 50*FRACUNIT, PBStartZ + 150*FRACUNIT, MT_SNICK)
				S_StartSound(SNICK, sfx_hello)
				S_StartSound(player.mo, sfx_hello, player)
				P_BossTargetPlayer(SNICK, true)
				rawset(_G, "SNICK", SNICK)
			end
		elseif Lap2
		and not Lap3
			local fakeportal = P_SpawnMobj(PBStartX, PBStartY, PBStartZ, MT_LAPPORTAL)
			fakeportal.tics = 50
			fakeportal.fake = true
			fakeportal.target = player.mo
			player.ptportal = 50
			if player.comboamount > 0
				player.combo = 200
			end
			P_InstaThrust(player.mo, player.mo.angle, 0*FRACUNIT)
			player.score = player.score + 10000
			Lap3 = true
			if SNICK and SNICK.valid
				SNICK.state = S_SNICK
				P_SetOrigin(SNICK, PBStartX - 50*FRACUNIT, PBStartY - 50*FRACUNIT, PBStartZ + 150*FRACUNIT)
				S_StartSound(SNICK, sfx_hello)
				S_StartSound(player.mo, sfx_hello, player)
			end
		end
	end
return true
end, MT_LAPPORTAL)

addHook("PlayerThink", function(player)
	if player.ptportal == nil
		player.ptportal = 0
	end
	if player.ptportal
		player.ptportal = $ - 1
		player.mo.state = S_PLAY_ROLL
		player.normalspeed = 0
		player.mo.momz = 0
		P_InstaThrust(player.mo, player.mo.angle, 0*FRACUNIT)
		if player.ptportal > 25
			player.mo.spritexscale = $ - FRACUNIT/25
			player.mo.spriteyscale = $ - FRACUNIT/25
		elseif player.ptportal < 25
			player.mo.spritexscale = $ + FRACUNIT/25
			player.mo.spriteyscale = $ + FRACUNIT/25
		elseif player.ptportal == 25
			P_SetOrigin(player.mo, PBStartX, PBStartY, PBStartZ)
			S_ChangeMusic("DEAOLI", true, i)
			S_StartSound(player.mo, sfx_lap2)
			if PRank
				player.score = player.score + 10000
			end
			if player.comboamount > 0
				player.combo = 200
			end
			if pizzaboispawned
				P_SetOrigin(pizzaboi, player.mo.x + 50*FRACUNIT, player.mo.y + 50*FRACUNIT, player.mo.z + 50*FRACUNIT)
			end
		elseif player.ptportal == 1
			player.normalspeed = 15*FRACUNIT
			player.mo.state = S_PLAY_STND
		end
	end
	if player.ptportal
	and not GFL2
		GFL2 = true
	elseif not player.ptportal
	and GFL2
		GFL2 = false
	end
end)

addHook("MobjThinker", function(mobj)
	if GFL2
		return true
	end
end)

addHook("MobjThinker", function(mobj)
	if mobj and mobj.valid
	and mobj.fake == true
	and not mobj.target.player.ptportal
		mobj.spritexscale = $ - FRACUNIT/50
		mobj.spriteyscale = $ - FRACUNIT/50
	end
end, MT_LAPPORTAL)

//Quick moment of me
addHook('TouchSpecial', function(sword, mo)
local player = mo.player
	if player.transformation == 0 and sword.state == S_SWORD_SPAWN
		player.transformation = 1
		sword.state = S_SWORD_GONE
	end
return true
end, MT_SWORD)

addHook("PlayerCanDamage", function(player)
	if player.transformation == 1 or player.smallroll > 0
		return true
	end
end)
//K back to Nick

addHook('TouchSpecial', function(pillarboi, mo)
	if not mo.player then return true end
	if PBPizzaTime then return end
	local p = mo.player
	if P_PlayerCanDamage(p, pillarboi) and not pillarboi.inv then
		if pillarboi.hits
			if not executePTHook('Before_HitPillarBoi', {pillarboi, mo})
				if not L_TableContains(pillarboi.hitby, p) then
					table.insert(pillarboi.hitby, p)
				end
				S_StartSound(pillarboi, sfx_ouchie)
				S_ChangeMusic('PHOBIA', true, p)
				pillarboi.hits = $-1
				pillarboi.inv = TICRATE
				pillarboi.hittimer = 10*TICRATE
				if pillarboi.state ~= S_PILLARBOI_UHOH then pillarboi.state = S_PILLARBOI_UHOH end
			end
			executePTHook('HitPillarBoi', {pillarboi, mo})
		else
			if not executePTHook('KillPillarBoi', {pillarboi, mo})
				P_KillMobj(pillarboi, nil, mo)
				S_StartSound(pillarboi, sfx_ouchie)
				PBPizzaTime = true
				if MaxTime == nil then
					MaxTime = leveltime * 2
					TimeTilPF = MaxTime
				end
			end
			executePTHook('KillPillarBoi', {pillarboi, mo})
		end
		mo.momx = $*-1
		mo.momy = $*-1
		mo.momz = $*-1
	end
	return true
end, MT_PILLARBOI)

addHook('MobjSpawn', function(pillarboi)
	pillarboi.inv = 0
	pillarboi.hits = 0
	pillarboi.isdead = false
	pillarboi.hitby = {}
	pillarboi.hittimer = 10*TICRATE
	pillarboi.deadtime = 5*TICRATE
	PBPizzaTime = false
	PBStartX = 0*FRACUNIT
	PBStartY = 0*FRACUNIT
	PBStartZ = 0*FRACUNIT
	jind = 77*FRACUNIT
	PIZZATIME = false
	FirstTime = false
	pizzaboispawned = false
	Lap2 = false
	SpawnSector = nil
	PRank = false
	SecretCount = 0
end, MT_PILLARBOI)

addHook('MobjThinker', function(pillarboi)
	for player in players.iterate
		if R_PointToDist2(player.mo.x, player.mo.y, pillarboi.x, pillarboi.y) <= 1000*FRACUNIT and P_PlayerCanDamage(player, pillarboi) and pillarboi.valid and not PBPizzaTime
			S_ChangeMusic('PHOBIA', true, player)
			pillarboi.state = S_PILLARBOI_UHOH
		elseif R_PointToDist2(player.mo.x, player.mo.y, pillarboi.x, pillarboi.y) > 1000*FRACUNIT or not pillarboi.valid or PBPizzaTime
			if not PBPizzaTime
				S_ChangeMusic(mapmusname)
				pillarboi.state = S_PILLARBOI
			end
		end
	end
end, MT_PILLARBOI)

addHook('MobjThinker', function(pillarboi)
	if not pillarboi.valid then return end
	if pillarboi.hittimer and pillarboi.hitby[1] then
		pillarboi.hittimer = $-1
	elseif not pillarboi.hittimer and pillarboi.hitby[1]
		for _,i in pairs(pillarboi.hitby) do
			if i.valid then
				S_ChangeMusic("PHOBIA", true, i)
			end
		end
		pillarboi.hitby = {}
		pillarboi.state = S_PILLARBOI
	end
	if pillarboi.inv then
		pillarboi.inv = $-1
	end
	if pillarboi.isdead then
		if pillarboi.deadtime then
			pillarboi.momz = $-(FU/2)
			pillarboi.deadtime = $-1
		else
			P_RemoveMobj(pillarboi)
		end
	end
end, MT_PILLARBOI)

addHook('MobjDeath', function(pillarboi, i, s)
	if s then
		pillarboi.momx = s.momx
		pillarboi.momy = s.momy
	end
	pillarboi.momz = 16*FU
	pillarboi.flags = $|MF_NOCLIP|MF_NOCLIPHEIGHT
	pillarboi.isdead = true
	PBPizzaTime = true
	S_ChangeMusic("PIZTIM", true, i)
end, MT_PILLARBOI)

addHook("PlayerThink", function(player)
if NoMoveset return end
	if (P_IsObjectOnGround(player.mo)
	or (player.mo.eflags & MFE_JUSTHITFLOOR))
	or not player.wallrunning
		if player.machrun == true and player.sliding == 0 and player.grabbing == 0 and player.transformation == 0 and not (player.mach3 or player.mach4) and (player.cmd.forwardmove ~= 0 or player.cmd.sidemove ~= 0)
			player.normalspeed = player.normalspeed + (FU/5)
		elseif player.machrun == true and player.mach3 == true and player.sliding == 0 and player.grabbing == 0 and player.transformation == 0 and (player.cmd.forwardmove ~= 0 or player.cmd.sidemove ~= 0)
			player.normalspeed = player.normalspeed + (FU/20)
		elseif player.machrun == true and player.mach4 == true and player.sliding == 0 and player.grabbing == 0 and player.transformation == 0 and (player.cmd.forwardmove ~= 0 or player.cmd.sidemove ~= 0)
			player.normalspeed = player.normalspeed + (FU/20)
		end
	end
	if player.machrun == true and player.normalspeed < skins[player.mo.skin].runspeed and (player.cmd.forwardmove ~= 0 or player.cmd.sidemove ~= 0) and player.mach4 == false and player.mach3 == false and player.mach2 == false and (player.transformation == 0)
		player.mach1 = true
	else
		player.mach1 = false
	end
	if player.machrun == true and player.normalspeed >= skins[player.mo.skin].runspeed and (player.cmd.forwardmove ~= 0 or player.cmd.sidemove ~= 0) and player.mach4 == false and player.mach3 == false and (player.transformation == 0)
		player.mach2 = true
	else
		player.mach2 = false
	end
	if player.machrun == true and player.normalspeed >= 40*FRACUNIT and (player.cmd.forwardmove ~= 0 or player.cmd.sidemove ~= 0) and player.mach4 == false and (player.transformation == 0)
		player.mach3 = true
	else
		player.mach3 = false
	end
	if player.machrun == true and player.normalspeed >= 60*FRACUNIT  and (player.cmd.forwardmove ~= 0 or player.cmd.sidemove ~= 0) and (player.transformation == 0)
		player.mach4 = true
	else
		player.mach4 = false
	end
	if player.mach4 and player.normalspeed > 80*FRACUNIT and player.uncappedspeed == false
		player.normalspeed = 80*FRACUNIT
	end
	if player.mach4 == true and player.mach3 == true
		player.mach3 = false
	end
	if player.mach1 
	and not S_SoundPlaying(player.mo, sfx_mch1)
	and P_IsObjectOnGround(player.mo)
	and not player.sliding
	and not player.grabbing
	and not player.rolling
		S_StartSound(player.mo, sfx_mch1)
	end
	if player.mach2 
	and not S_SoundPlaying(player.mo, sfx_mch2)
	and P_IsObjectOnGround(player.mo)
	and not player.sliding
	and not player.grabbing
	and not player.rolling
		S_StartSound(player.mo, sfx_mch2)
	end
	if player.mach3 and not S_SoundPlaying(player.mo, sfx_mch3)
		S_StartSound(player.mo, sfx_mch3)
	end
	if not player.mach1
	or not P_IsObjectOnGround(player.mo)
	or player.sliding
	or player.grabbing
	or player.rolling
		if S_SoundPlaying(player.mo, sfx_mch1)
			S_StopSoundByID(player.mo, sfx_mch1)
		end
	end
	if not player.mach2
	or not P_IsObjectOnGround(player.mo)
	or player.sliding
	or player.grabbing
	or player.rolling
		if S_SoundPlaying(player.mo, sfx_mch2)
			S_StopSoundByID(player.mo, sfx_mch2)
		end
	end
	if player.mach4
		if not S_SoundPlaying(player.mo, sfx_mch4)
			S_StartSound(player.mo, sfx_mch4)
		end
	end
	if not player.mach3
		if S_SoundPlaying(player.mo, sfx_mch3)
			S_StopSoundByID(player.mo, sfx_mch3)
		end
	end
	if not player.mach4
		if S_SoundPlaying(player.mo, sfx_mch4)
			S_StopSoundByID(player.mo, sfx_mch4)
		end
	end
	if player.mach2
	and S_SoundPlaying(player.mo, sfx_mch1)
		S_StopSoundByID(player.mo, sfx_mch1)
	end
	if player.mach3
	and S_SoundPlaying(player.mo, sfx_mch2)
		S_StopSoundByID(player.mo, sfx_mch2)
	end
	if player.mach4
	and S_SoundPlaying(player.mo, sfx_mch3)
		S_StopSoundByID(player.mo, sfx_mch3)
	end
	if player.mach3 or player.mach4 or player.redirecting
		player.charflags = $1|SF_RUNONWATER
	elseif not player.mach3 or not player.mach4 or not player.redirecting or player.divebomb
		player.charflags = $1 & ~SF_RUNONWATER
	end
end)

//Sponsor over

addHook("PlayerThink", function(player)
if NoMoveset return end
	if player.redirecttype == nil
		player.redirecttype = "mach3"
	end
	if (player.cmd.buttons & BT_CUSTOM3) and (player.redirecting == false) and (P_IsObjectOnGround(player.mo)) and not (player.rolling) and not (player.grabbing) and not (player.sliding) and not (player.superjumpbuild) and player.machrun and (player.transformation == 0)
		player.redirecting = true
		player.redirecttimer = 30
		player.mo.momx = (player.mo.momx/2)
		player.mo.momy = (player.mo.momy/2)
		if not (player.mach3 or player.mach4)
			player.redirecttype = "mach"
		else
			player.redirecttype = "mach3"
		end
	end
	if player.redirecting == true
		if player.redirecttype == "mach3"
			if P_IsObjectOnGround(player.mo)
				player.mo.state = S_PLAY_SPINDASH
			elseif player.redirecttimer <= 0 and not P_IsObjectOnGround(player.mo)
				player.mo.state = S_PLAY_PAIN
			end
			if player.mo.floorrover and player.mo.floorrover.valid
			and (player.mo.floorrover.flags & FF_SWIMMABLE)
				player.mo.momz = 0
			end
		else
			if P_IsObjectOnGround(player.mo)
				player.mo.state = S_PLAY_SKID
			elseif player.redirecttimer <= 0 and not P_IsObjectOnGround(player.mo)
				player.mo.state = S_PLAY_DEAD
			end
		end
		player.redirecttimer = player.redirecttimer - 1
		player.pflags = $ + PF_FULLSTASIS
		player.normalspeed = player.speed
	end
	if player.redirecting == true and player.redirecttimer <= 0 and P_IsObjectOnGround(player.mo)
		player.pflags = $ & ~PF_FULLSTASIS
		if player.redirecttype == "mach3"
			P_InstaThrust(player.mo, player.mo.angle, 40*FRACUNIT)
		else
			P_InstaThrust(player.mo, player.mo.angle, 20*FRACUNIT)
		end
		if player.mach4
			player.mach4 = false
			player.mach3 = true
		end
		if player.redirecttype == "mach3"
			player.mo.state = S_PLAY_RUN
		else
			player.mo.state = S_PLAY_WALK
		end
		player.normalspeed = 40*FRACUNIT
		player.redirecting = false
	end
	if (player.mo.eflags & MFE_SPRUNG) and (player.redirecting == true)
		player.redirecting = false
		player.redirecttimer = 0
	end
end)
//ITS PIZZA TIME!!!!!!!!

local levelTimes = {
    ["Greenflower Zone 1"] = 70*TICRATE,
    ["Green Grove Zone 2"] = 95*TICRATE,
	["Square Valley Zone 3"] = 1*TICRATE,
    ["Techno Hill Zone 1"] = 105*TICRATE,
    ["TechnoVade Zone 2"] = 150*TICRATE,
	["Techno Gone Wrong Zone 3"] = 1*TICRATE,
	["Deep Sea Zone 1"] = 85*TICRATE,
	["Deep Dive 8 Zone 2"] = 190*TICRATE,
	["Too Deep In Zone 3"] = 1*TICRATE,
	["Castle Eggman Zone 1"] = 95*TICRATE,
	["Fortress Eggman Zone 2"] = 120*TICRATE,
	["Colosseum Eggman Zone 3"] = 1*TICRATE,
	["Arid Canyon Zone 1"] = 95*TICRATE,
	["Arid Ride Zone 2"] = 180*TICRATE,
	["It's Nerf or Nothin Zone 3"] = 1*TICRATE,
	["Bloodsauce Volcano Zone 1"] = 300*TICRATE,
	["Egg Rock Zone 1"] = 300*TICRATE,
	["Eggman Land Zone 2"] = 5*TICRATE,
	["Stardust Replay Zone 1"] = 1*TICRATE,
	["Made of Metal Zone 2"] = 1*TICRATE,
	["Final Stretch Zone 1"] = 1*TICRATE,
	["Big Rock Acts Kindly Zone 3"] = 1*TICRATE,
	["Eggman's Downfall"] = 1*TICRATE,
	["Hub World 1 Zone"] = 1*TICRATE,
	["Hub World 2 Zone"] = 1*TICRATE,
	["Hub World 3 Zone"] = 1*TICRATE,
	["Hub World 4 Zone"] = 1*TICRATE,
	["Hub World 5 Zone"] = 1*TICRATE,
	["Hub World 6 Zone"] = 1*TICRATE,
	["Hub World 7 Zone"] = 1*TICRATE
}
rawset(_G, "levelTimes", levelTimes)

addHook("MapLoad", function()
	local time = levelTimes[G_BuildMapTitle(gamemap)]
    if time then
        MaxTime = time
    else -- no preset time
        MaxTime = nil
    end
	TimeTilPF = MaxTime
end)


local function time(v, player)
	if player.mo and player.mo.valid
		if (maptol & TOL_NIGHTS) or PBPizzaTime == nil then -- Prevents the code from running in a Nights special stage
			return
		end
		local jind = (
			77*FU + 
			FU*(MaxTime-TimeTilPF)/MaxTime*148
		)
		local timeanim = ((leveltime/2) % 22) + 1
		local pizzaanim = ((leveltime/2) % 17) + 1
		local p_bar = v.cachePatch("PTTBAR") --this junk is mine
		local p_time = v.cachePatch( 'SMOLJ' .. timeanim )
		local p_pizza = v.cachePatch( 'PIZZAB' .. pizzaanim )
		local p_showt = v.cachePatch("SHOWT")

		if player.mo.valid and PBPizzaTime == true
			if Classic == false
				v.drawScaled(85*FRACUNIT, 175*FRACUNIT, FRACUNIT/2, p_bar, V_HUDTRANS)
				v.drawScaled(jind, 178*FRACUNIT, FRACUNIT/2, p_time, V_HUDTRANS)
			end
			if Classic == false
				v.drawString(150, 165, string.format( '%d:%02d', G_TicsToMinutes(TimeTilPF), G_TicsToSeconds(TimeTilPF) ))
			elseif Classic == true
				v.drawString(150, 170, string.format( '%d:%02d', G_TicsToMinutes(TimeTilPF), G_TicsToSeconds(TimeTilPF) ))
			end
			if Classic == false
				if jind < 225*FRACUNIT
					v.drawScaled(245*FRACUNIT,150*FRACUNIT, FRACUNIT/2, p_pizza,V_HUDTRANS)
				elseif jind == 225*FRACUNIT
					v.drawScaled(245*FRACUNIT,135*FRACUNIT, FRACUNIT/2, p_showt, V_HUDTRANS)
				end
			end
		end
	end
end
hud.add(time, "game")

local function SpawnPizzaFace(x,y,z,p) //AI Pizza Pasta Put it in the box, come on, lets go
	if not pizzaboispawned and TimeTilPF <= 0
		if not executePTHook('SpawnAIPizzaface', {x,y,z,p})
			pizzaboi = P_SpawnMobjFromMobj(p.mo, 10*FRACUNIT,10*FRACUNIT,10*FRACUNIT, MT_PIZZAFACE)
			pizzaboi.gofor = p.mo
			p.powers[pw_invulnerability] = 10*TICRATE
			pizzaboi.speedToGo = (p.normalspeed - (25 * FRACUNIT)) / FRACUNIT
		end
	elseif pizzaboi and pizzaboi.valid and not pizzaboi.pizzaface_stun and p.mo and p.mo == pizzaboi.gofor
		if not executePTHook('TeleportAIPizzaface', {x,y,z,p})
			pizzaboi.pizzaface_stun = 10*TICRATE
			P_SetOrigin(pizzaboi, p.mo.x + 10*FRACUNIT,p.mo.y + 10*FRACUNIT,p.mo.z + 10*FRACUNIT)
		end
	end
end

addHook("MobjThinker", function(mobj)
	if mobj and mobj.valid 
	and pizzaboispawned
	and leveltime % 5 == 0
		local ghost = P_SpawnGhostMobj(mobj)
		ghost.colorized = true
		ghost.fuse = 180
		ghost.tics = 10
		ghost.color = R_GetColorByName("After Image Red")
		ghost.frame = TR_TRANS10|mobj.frame|FF_FULLBRIGHT
	end
end, MT_PIZZAFACE)

addHook("PlayerThink", function(player)
	if TimeTilPF > 0
		pizzaboispawned = false
	end
end)

addHook("PlayerThink", function(p)
	if not NoMoveset
		if pizzaboispawned == true and LapImpossible == false
			pizzaboi.speedToGo = p.normalspeed - (25 * FRACUNIT) / FRACUNIT
		elseif pizzaboispawned == true and LapImpossible == true
			pizzaboi.speedToGo = p.normalspeed - (8 * FRACUNIT) / FRACUNIT
		elseif pizzaboispawned == true and LapImpossible == false and p.powers[pw_underwater]
			pizzaboi.speedToGo = p.speed - (2 * FRACUNIT) / FRACUNIT
		elseif pizzaboispawned == true and LapImpossible == true and p.powers[pw_underwater]
			pizzaboi.speedToGo = p.speed - (1 * FRACUNIT) / FRACUNIT
		end
	else
		if p.speed > 12*FRACUNIT
			if pizzaboispawned == true and LapImpossible == false
				pizzaboi.speedToGo = p.speed - (12 * FRACUNIT) / FRACUNIT
			elseif pizzaboispawned == true and LapImpossible == true
				pizzaboi.speedToGo = p.speed - (4 * FRACUNIT) / FRACUNIT
			elseif pizzaboispawned == true and LapImpossible == false and p.powers[pw_underwater]
				pizzaboi.speedToGo = p.speed - (2 * FRACUNIT) / FRACUNIT
			elseif pizzaboispawned == true and LapImpossible == true and p.powers[pw_underwater]
				pizzaboi.speedToGo = p.speed - (1 * FRACUNIT) / FRACUNIT
			end
		else
			pizzaboi.speedToGo = 12*FRACUNIT
		end
	end
end)

addHook("ThinkFrame", function ()
	if TimeTilPF <= 0
		PIZZATIME = true
	end
	if PBPizzaTime
	and TimeTilPF > 0
		if not LapImpossible
			TimeTilPF = $ - 1
		else
			TimeTilPF = $ - 4
		end
	end
	if TimeTilPF < 0
		TimeTilPF = 0
	end
end)

addHook("PlayerThink", function(p)	
	if PIZZATIME == true and pizzaboispawned == false
		SpawnPizzaFace(x,y,z,p)
		pizzaboispawned = true
	end
end)

addHook("MapLoad", function()
	for thing in mapthings.iterate
		if thing.type == 1
			P_SpawnMobj(thing.x*FU, thing.y*FU, thing.z*FU, MT_GATE)
		end
	end
end)

addHook("MobjThinker", function(gate)
	if gate and gate.valid
		SpawnSector = gate.subsector.sector
	end
end, MT_GATE)

addHook("TouchSpecial", function(gate, mo)
	if gate and gate.valid
		return true
	end
end, MT_GATE)

addHook("MobjThinker", function(gate)
	if PBPizzaTime == true
		gate.state = S_GATE_OPEN
	end
	if PBPizzaTime == false
		gate.state = S_GATE_CLOSED
	end
end, MT_GATE)

addHook("PlayerThink", function(player)
	if player.mo.subsector.sector == SpawnSector and PBPizzaTime == true
		P_DoPlayerFinish(player)
	end
end)

//Pizza Time Over

addHook("PlayerThink", function(player)
if NoMoveset return end
	if player.divebomb == nil
		player.divebomb = false
	end
	if (player.diving) and (player.cmd.buttons & BT_JUMP) and (player.transformation == 0) and not (player.divebomb)
		player.diving = false
		player.divebomb = true
		P_SetObjectMomZ(player.mo, 20*FRACUNIT, false)
		S_StartSound(player.mo, sfx_bs)
	end
	if P_IsObjectOnGround(player.mo) and player.divebomb or (player.mo.eflags & MFE_GOOWATER or player.powers[pw_carry] or P_PlayerInPain(player) or player.playerstate == PST_DEAD or (player.mo.eflags & MFE_SPRUNG)) and player.divebomb or player.transformation > 0 and player.divebomb
		player.normalspeed = player.speed
		S_StartSound(player.mo, sfx_bd)
		PB_LaunchEnemies(player)
		if S_SoundPlaying(player.mo, sfx_bl)
			S_StopSoundByID(player.mo, sfx_bl)
		end
		if S_SoundPlaying(player.mo, sfx_bs)
			S_StopSoundByID(player.mo, sfx_bs)
		end
		if player.mo.standingslope
			P_InstaThrust(player.mo, player.mo.angle, 40*FRACUNIT)
			player.normalspeed = 40*FRACUNIT
		end
		player.divebomb = false
		if player.mo.skin == "knuckles"
			P_NukeEnemies(player.mo, player.mo, 1000*FRACUNIT)
			S_StartSound(player.mo, 93)
			P_InstaThrust(player.mo, player.mo.angle, 0*FRACUNIT)
			player.mo.state = S_PLAY_GLIDE_LANDING
		end
	end
	if player.divebomb == true
		P_SetObjectMomZ(player.mo, -1*FRACUNIT, true)
		player.mo.state = S_PLAY_FALL
		player.drawangle = player.redrawangle
		player.redrawangle = $ + ANG20
		player.mach3 = false
		player.mach4 = false
		if player.mo.momz > 0*FRACUNIT
			player.mo.state = S_PLAY_SPRING
		elseif player.mo.momz < 0*FRACUNIT
			player.mo.state = S_PLAY_FALL
		end
		if not S_SoundPlaying(player.mo, sfx_bs)
			if not S_SoundPlaying(player.mo, sfx_bl)
				S_StartSound(player.mo, sfx_bl)
			end
		end
	end
end)

addHook("PostThinkFrame", function()
if NoMoveset return end
	for player in players.iterate()
		if player.divebomb
			player.mach3 = false
			player.mach4 = false
		end
	end
end)

//TGTLS Moment
addHook("PlayerThink", function(p)
if NoMoveset return end
	if p.mo and p.mo.valid
	and (p.cmd.buttons & BT_CUSTOM2)
	and (p.cmd.buttons & BT_JUMP)
	and not P_PlayerInPain(p)
	and not p.powers[pw_carry]
	and not (p.pflags & PF_THOKKED)
	and p.playerstate == PST_LIVE
	and (p.mo.state ~= S_PLAY_UPPERCUT1 and p.mo.state ~= S_PLAY_UPPERCUT2)
	and not p.taunting
	and not p.superjumpbuild
	and not p.superjump
	and not p.grabbing
	and not p.bash
	and not p.sliding
	and not p.redirecting
	and not p.bodyslam
	and not p.diving
	and not p.divebomb
	and not p.rolling
		if p.mo.skin ~= "tails"
			p.mo.momx = $1/2
			p.pflags = $|PF_THOKKED
			p.mo.momy = $1/2
			S_StartSound(p.mo, sfx_upper)
			if not P_IsObjectOnGround(p.mo)
				P_SetObjectMomZ(p.mo, 15*FRACUNIT, false)
			else
				P_SetObjectMomZ(p.mo, 15*FRACUNIT, false)
			end
		end
		p.mo.state = S_PLAY_UPPERCUT1
	end
end)

rawset(_G, "UpperCutAnimation", function(p)
	if (p.mo.state == S_PLAY_UPPERCUT1 or p.mo.state == S_PLAY_UPPERCUT2)
		return true
	else
		return false
	end
end)
//TGTLS Moment over

addHook("PlayerCanDamage", function(player)
	if (player.mach3) or (player.mach4) or (player.grabbing > 0) or (player.divebomb) or (player.mo.state == S_PLAY_UPPERCUT1 or player.mo.state == S_PLAY_UPPERCUT2) or (player.bodyslam) or (player.redirecting) or (player.rolling) or (player.diving) 
		return true
	end
	if (player.wallrunning)
		return false
	end
end)

//Pizza Face Stuff
//Listen man, I've overworked myself to the max, idk if this does anything, but I'm putting it in anyways
//Have a good day
-- BUGGIE THE GOAAAAT WOOOOOOO (HE HELPED ALOT WITH AI PIZZAFACE)

local function P_FlyTo(mo, fx, fy, fz, sped, addques) --A very useful command honestly.
	if mo.valid
		local flyto = P_AproxDistance(P_AproxDistance(fx - mo.x, fy - mo.y), fz - mo.z)
		if flyto < 1
			flyto = 1
		end
		
		if addques
			mo.momx = $ + FixedMul(FixedDiv(fx - mo.x, flyto), sped)
			mo.momy = $ + FixedMul(FixedDiv(fy - mo.y, flyto), sped)
			mo.momz = $ + FixedMul(FixedDiv(fz - mo.z, flyto), sped)
		else
			mo.momx = FixedMul(FixedDiv(fx - mo.x, flyto), sped)
			mo.momy = FixedMul(FixedDiv(fy - mo.y, flyto), sped)
			mo.momz = FixedMul(FixedDiv(fz - mo.z, flyto), sped)
		end	
	end	
end

-- Pizza Mask Thinker
addHook("MobjThinker", function(mobj)
	if not mobj.valid return end
	if mobj.targetplayer and mobj.targetplayer.valid and mobj.targetplayer.realmo and mobj.targetplayer.realmo.valid then
		local targetplayer = mobj.targetplayer
		P_MoveOrigin(mobj, targetplayer.realmo.x, targetplayer.realmo.y, targetplayer.realmo.z)
	else
		P_RemoveMobj(mobj)
	end
end, MT_PIZZAMASK)

addHook("MobjThinker", function(mobj) --Stuff
	if mobj and mobj.valid
		if mobj.gofor and mobj.gofor.valid
		and mobj.gofor.health
		and not pizzaboi.pizzaface_stun
			local t = mobj.gofor
			local di = P_AproxDistance(P_AproxDistance(t.x-mobj.x,t.y-mobj.y),t.z-mobj.z)
			if not pizzaboi.pizzaface_stun
				P_FlyTo(mobj,t.x,t.y,t.z-(mobj.height/2),mobj.speedToGo)
				if not pizzaboi.LaughedLol
					S_StartSound(nil, sfx_pizzah)
					pizzaboi.LaughedLol = true
				end
			end
			if (di <= P_AproxDistance(t.radius,t.height)*2)
				if t.player and t.player.valid
					if t.player.powers[pw_flashing]
						t.player.powers[pw_flashing] = 0
					end
					mobj.targname = t.player.name
				end
				mobj.flags = $&~MF_NOCLIP
			else
				mobj.flags = $|MF_NOCLIP
			end
			mobj.hadtarget = true
		elseif pizzaboi.pizzaface_stun
			mobj.momx,mobj.momy,mobj.momz = 0,0,0
			pizzaboi.pizzaface_stun = $-1
		elseif not mobj.gofor or (mobj.gofor and not mobj.gofor.valid)
			if mobj.hadtarget
				mobj.momx = 0
				mobj.momy = 0
				mobj.momz = 0
				mobj.flags = $|MF_NOCLIP
			end
			local newp = PizzaTime.functions.GetNearestPlayer(mobj)
			if newp
				mobj.gofor = getNearestPlayer(mobj).mo
				mobj.speedToGo = (skins[newp].normalspeed - (8 * FRACUNIT)) / FRACUNIT
			end
			mobj.hadtarget = false
		end
		if not mobj.bepain
			mobj.flags = $|MF_PAIN
		elseif mobj.bepain
			mobj.flags = $&~MF_PAIN
			mobj.bepain = false
		end
	end
end,MT_PIZZAFACE)

//:sad:

//Enemy Spawner by Cole207
--Escape Spawner from Pizza Tower
freeslot(
"MT_ESCAPESPAWNER",
"S_ESCAPESPAWNERIDLE",
"S_ESCAPESPAWNER1",
"S_ESCAPESPAWNER2",
"S_ESCAPESPAWNER3",
"S_ESCAPESPAWNER4",
"S_ESCAPESPAWNER5",
"S_ESCAPESPAWNER6",
"S_ESCAPESPAWNER7",
"S_ESCAPESPAWNER8",
"S_ESCAPESPAWNER9",
"S_ESCAPESPAWNER10",
"S_ESCAPESPAWNER11",
"S_ESCAPESPAWNER12",
"S_ESCAPESPAWNER13",
"S_ESCAPESPAWNER14",
"S_ESCAPESPAWNER15",
"S_ESCAPESPAWNER16",
"S_ESCAPESPAWNER17",
"S_ESCAPESPAWNER18",
"S_ESCAPESPAWNER19",
"S_ESCAPESPAWNER20",
"SPR_SPWE",
"sfx_espawn"
)

sfxinfo[sfx_espawn] = {
	flags = SF_TOTALLYSINGLE|SF_X4AWAYSOUND,
	caption = "Escape Spawner"
}

--Animation
states[S_ESCAPESPAWNERIDLE] = { sprite = SPR_NULL, frame = A, tics = -1, nextstate = S_ESCAPESPAWNERIDLE }
states[S_ESCAPESPAWNER1] = { sprite = SPR_SPWE, frame = FF_FULLBRIGHT|A, tics = 1, nextstate = S_ESCAPESPAWNER2 }
states[S_ESCAPESPAWNER2] = { sprite = SPR_SPWE, frame = FF_FULLBRIGHT|B, tics = 1, nextstate = S_ESCAPESPAWNER3 }
states[S_ESCAPESPAWNER3] = { sprite = SPR_SPWE, frame = FF_FULLBRIGHT|C, tics = 1, nextstate = S_ESCAPESPAWNER4 }
states[S_ESCAPESPAWNER4] = { sprite = SPR_SPWE, frame = FF_FULLBRIGHT|D, tics = 1, nextstate = S_ESCAPESPAWNER5 }
states[S_ESCAPESPAWNER5] = { sprite = SPR_SPWE, frame = FF_FULLBRIGHT|E, tics = 1, nextstate = S_ESCAPESPAWNER6 }
states[S_ESCAPESPAWNER6] = { sprite = SPR_SPWE, frame = FF_FULLBRIGHT|F, tics = 1, nextstate = S_ESCAPESPAWNER7 }
states[S_ESCAPESPAWNER7] = { sprite = SPR_SPWE, frame = FF_FULLBRIGHT|G, tics = 1, nextstate = S_ESCAPESPAWNER8 }
states[S_ESCAPESPAWNER8] = { sprite = SPR_SPWE, frame = FF_FULLBRIGHT|H, tics = 1, nextstate = S_ESCAPESPAWNER9 }
states[S_ESCAPESPAWNER9] = { sprite = SPR_SPWE, frame = FF_FULLBRIGHT|I, tics = 1, nextstate = S_ESCAPESPAWNER10 }
states[S_ESCAPESPAWNER10] = { sprite = SPR_SPWE, frame = FF_FULLBRIGHT|J, tics = 1, nextstate = S_ESCAPESPAWNER11 }
states[S_ESCAPESPAWNER11] = { sprite = SPR_SPWE, frame = FF_FULLBRIGHT|K, tics = 3, nextstate = S_ESCAPESPAWNER12 }
states[S_ESCAPESPAWNER12] = { sprite = SPR_SPWE, frame = FF_FULLBRIGHT|L, tics = 1, nextstate = S_ESCAPESPAWNER13 }
states[S_ESCAPESPAWNER13] = { sprite = SPR_SPWE, frame = FF_FULLBRIGHT|M, tics = 1, nextstate = S_ESCAPESPAWNER14 }
states[S_ESCAPESPAWNER14] = { sprite = SPR_SPWE, frame = FF_FULLBRIGHT|N, tics = 1, nextstate = S_ESCAPESPAWNER15 }
states[S_ESCAPESPAWNER15] = { sprite = SPR_SPWE, frame = FF_FULLBRIGHT|O, tics = 1, nextstate = S_ESCAPESPAWNER16 }
states[S_ESCAPESPAWNER16] = { sprite = SPR_SPWE, frame = FF_FULLBRIGHT|P, tics = 1, nextstate = S_ESCAPESPAWNER17 }
states[S_ESCAPESPAWNER17] = { sprite = SPR_SPWE, frame = FF_FULLBRIGHT|Q, tics = 1, nextstate = S_ESCAPESPAWNER18 }
states[S_ESCAPESPAWNER18] = { sprite = SPR_SPWE, frame = FF_FULLBRIGHT|R, tics = 1, nextstate = S_ESCAPESPAWNER19 }
states[S_ESCAPESPAWNER19] = { sprite = SPR_SPWE, frame = FF_FULLBRIGHT|S, tics = 1, nextstate = S_ESCAPESPAWNER20 }
states[S_ESCAPESPAWNER20] = { sprite = SPR_SPWE, frame = FF_FULLBRIGHT|T, tics = 1, nextstate = S_ESCAPESPAWNERIDLE }

--The Spawning Action
function A_PizzaTowerEscapeSpawn(actor, var1, var2)
	A_PlaySeeSound(actor,var1,var2)
	local z = actor.z
	if actor.eflags&MFE_VERTICALFLIP then
		z = $1+FixedMul(actor.info.height-mobjinfo[actor.health].height,actor.scale)
	end
	local enemy = P_SpawnMobj(actor.x,actor.y,z,actor.health)
	if actor.eflags&MFE_VERTICALFLIP then
		enemy.eflags = $1|MFE_VERTICALFLIP
		enemy.flags2 = $1|MF2_OBJECTFLIP
	end
	enemy.scale = actor.scale
	P_MoveOrigin(enemy,actor.x,actor.y,z)
	if P_SupermanLook4Players(enemy) then A_FaceTarget(enemy,0,0) end
	actor.target = enemy
end

states[S_ESCAPESPAWNER6].action = A_PizzaTowerEscapeSpawn

--Now Let's do The Spawner
mobjinfo[MT_ESCAPESPAWNER] = {
        doomednum = -1,
        spawnstate = S_ESCAPESPAWNERIDLE,
        spawnhealth = MT_BLUECRAWLA, --Object to Spawn in
        seestate = S_ESCAPESPAWNER1,
        seesound = sfx_espawn,
        reactiontime = 350, --Time that takes to Spawn the Enemy
        attacksound = sfx_None,
        painstate = S_NULL,
        painchance = 200,
        painsound = sfx_None,
        meleestate = S_NULL,
        missilestate = S_NULL,
        deathstate = S_NULL,
        xdeathstate = S_NULL,
        deathsound = sfx_None,
        speed = 0,
        radius = 50*FRACUNIT,
        height = 100*FRACUNIT,
        dispoffset = 0,
        mass = 100,
        damage = 0,
        activesound = sfx_None,
        flags = MF_NOGRAVITY|MF_NOCLIP|MF_NOCLIPHEIGHT|MF_NOCLIPTHING,
        raisestate = S_NULL
}

--The Pizza Tower Escape Spawning List
if not(PT_EscapeSpawnList)
	rawset(_G, "PT_EscapeSpawnList", {})
end
PT_EscapeSpawnList[MT_BLUECRAWLA] = MT_BLUECRAWLA
PT_EscapeSpawnList[MT_REDCRAWLA] = MT_REDCRAWLA
PT_EscapeSpawnList[MT_GFZFISH] = MT_JETTGUNNER
PT_EscapeSpawnList[MT_GOLDBUZZ] = MT_GOLDBUZZ
PT_EscapeSpawnList[MT_REDBUZZ] = MT_REDBUZZ
PT_EscapeSpawnList[MT_JETTBOMBER] = MT_JETTBOMBER
PT_EscapeSpawnList[MT_JETTGUNNER] = MT_JETTGUNNER
PT_EscapeSpawnList[MT_CRAWLACOMMANDER] = MT_CRAWLACOMMANDER
PT_EscapeSpawnList[MT_SKIM] = MT_SKIM
PT_EscapeSpawnList[MT_POPUPTURRET] = MT_JETTGUNNER
PT_EscapeSpawnList[MT_SPINCUSHION] = MT_SPINCUSHION
PT_EscapeSpawnList[MT_CRUSHSTACEAN] = MT_REDCRAWLA
PT_EscapeSpawnList[MT_BANPYURA] = MT_SPRINGSHELL
PT_EscapeSpawnList[MT_JETJAW] = MT_JETJAW
PT_EscapeSpawnList[MT_VULTURE] = MT_VULTURE
PT_EscapeSpawnList[MT_POINTY] = MT_JETTBOMBER
PT_EscapeSpawnList[MT_ROBOHOOD] = MT_ROBOHOOD
PT_EscapeSpawnList[MT_FACESTABBER] = MT_FACESTABBER
PT_EscapeSpawnList[MT_EGGGUARD] = MT_FACESTABBER
PT_EscapeSpawnList[MT_GSNAPPER] = MT_MINUS
PT_EscapeSpawnList[MT_MINUS] = MT_MINUS
PT_EscapeSpawnList[MT_SPRINGSHELL] = MT_SPRINGSHELL
PT_EscapeSpawnList[MT_YELLOWSHELL] = MT_SPRINGSHELL
PT_EscapeSpawnList[MT_UNIDUS] = MT_JETTBOMBER
PT_EscapeSpawnList[MT_CANARIVORE] = MT_CANARIVORE
PT_EscapeSpawnList[MT_PYREFLY] = MT_PYREFLY
PT_EscapeSpawnList[MT_PTERABYTE] = MT_PYREFLY
PT_EscapeSpawnList[MT_DRAGONBOMBER] = MT_PYREFLY
PT_EscapeSpawnList[MT_CRAWLASTATUE] = MT_REDCRAWLA
PT_EscapeSpawnList[MT_FACESTABBERSTATUE] = MT_FACESTABBER
PT_EscapeSpawnList[MT_SUSPICIOUSFACESTABBERSTATUE] = MT_FACESTABBER
PT_EscapeSpawnList[MT_ROSY] = MT_METALSONIC_BATTLE --In Sonic CD, Amy get's kidnapped by Metal Sonic!
PT_EscapeSpawnList[MT_GOOMBA] = MT_GOOMBA
PT_EscapeSpawnList[MT_BLUEGOOMBA] = MT_BLUEGOOMBA
PT_EscapeSpawnList[MT_PIAN] = MT_SHLEEP
PT_EscapeSpawnList[MT_SHLEEP] = MT_SHLEEP
PT_EscapeSpawnList[MT_PENGUINATOR] = MT_PENGUINATOR
PT_EscapeSpawnList[MT_POPHAT] = MT_POPHAT
PT_EscapeSpawnList[MT_HIVEELEMENTAL] = MT_BUMBLEBORE
PT_EscapeSpawnList[MT_BUMBLEBORE] = MT_BUMBLEBORE
PT_EscapeSpawnList[MT_BUGGLE] = MT_JETJAW
PT_EscapeSpawnList[MT_CACOLANTERN] = MT_CACOLANTERN
PT_EscapeSpawnList[MT_SPINBOBERT] = MT_CACOLANTERN
PT_EscapeSpawnList[MT_HANGSTER] = MT_HANGSTER
PT_EscapeSpawnList[MT_RING] = MT_RING

local escapespawner_bool = CV_RegisterVar({name = "pt_escapespawner", defaultvalue = "PizzaTimeOnly", flags = CV_NETVAR, PossibleValue = {Off = 0, On = 1, PizzaTimeOnly = 2}})
local escapespawner_timer = CV_RegisterVar({name = "pt_escapespawner_timetillspawn", defaultvalue = "5", flags = CV_NETVAR, PossibleValue = {MIN = 5, MAX = 60}})

addHook("MapLoad", function()
	if escapespawner_bool.value == 0 then return end
	local listofspawners = {}
	for enemy in mobjs.iterate()
		if PT_EscapeSpawnList[enemy.type] == nil then continue end --You want the Object to spawn in
		local spawnlocation = {
			x = enemy.x,
			y = enemy.y,
			z = enemy.z,
			objtype = PT_EscapeSpawnList[enemy.type],
			scale = enemy.scale,
			flip = false,
			target = enemy
		}
		if enemy.eflags&MFE_VERTICALFLIP then
			spawnlocation.flip = true
			spawnlocation.z = $1+enemy.height-FixedMul(100*FRACUNIT,enemy.scale)
		end
		table.insert(listofspawners,spawnlocation)
	end
	for _,v in ipairs(listofspawners) do
		--Add a lot of Escape Spawners
		local escapespawner = P_SpawnMobj(v.x,v.y,v.z,MT_ESCAPESPAWNER)
		escapespawner.health = v.objtype
		escapespawner.scale = v.scale
		if v.flip == true then
			escapespawner.eflags = $1|MFE_VERTICALFLIP
		end
		escapespawner.target = v.target
		escapespawner.reactiontime = escapespawner_timer.value*TICRATE
	end
end)

addHook("MobjThinker", function(spawner)
	if spawner.state ~= S_ESCAPESPAWNERIDLE then
		if mobjinfo[spawner.health].flags&MF_SPAWNCEILING then
			spawner.renderflags = RF_VERTICALFLIP|RF_FULLBRIGHT|RF_NOCOLORMAPS
		else
			spawner.renderflags = RF_FULLBRIGHT|RF_NOCOLORMAPS
		end
		return false
	end
	spawner.flags2 = $1|MF2_DONTDRAW --Make him Invisible
	local spawnrange = 600*FRACUNIT
	if mobjinfo[spawner.health].flags&MF_NOGRAVITY then spawnrange = $1+400*FRACUNIT end
	if mobjinfo[spawner.health].flags&MF_BOSS then spawnrange = FixedMul($1,0x00018000) end
	if spawner.target ~= nil and spawner.target.valid == true then --The Enemy is still there!
		spawner.reactiontime = escapespawner_timer.value*TICRATE
	elseif spawner.reactiontime > 0 then
		spawner.reactiontime = $1-1
	elseif (escapespawner_bool.value == 1 or (escapespawner_bool.value == 2 and gametype ~= nil and (
	((gametype == GT_PIZZATIME or gametype == GT_PIZZATIME1V1) and leveltime > 34*TICRATE)//PIZZA TIME
	or (PBPizzaTime == true)//PIZZA TIME JISK EDITION
	or (gametype == GT_PIZZATIME2 and PizzaTime.sync.PizzaTime)//PIZZA TIME 2.0
	))) and (P_LookForPlayers(spawner,FixedMul(spawnrange,spawner.scale),true,false) or GFL2) == true then
		--Spawn in
		spawner.state = S_ESCAPESPAWNER1
		spawner.tics = 1
		spawner.flags2 = $1&~MF2_DONTDRAW
	end
	return true
end,MT_ESCAPESPAWNER)

//K, Transformation time

addHook("PlayerThink", function(player)
if NoMoveset return end
	if player.transformation == 1 and player.mo.standingslope or player.knightslide == true
		P_InstaThrust(player.mo, player.mo.angle, 60*FRACUNIT)
		player.mach4 = true
		player.normalspeed = 60*FRACUNIT
		if P_IsObjectOnGround(player.mo)
			player.mo.state = S_PLAY_PAIN
		elseif not P_IsObjectOnGround(player.mo) and player.mo.momz > 0
			player.mo.state = S_PLAY_SPRING
		elseif not P_IsObjectOnGround(player.mo) and player.mo.momz < 0
			player.mo.state = S_PLAY_FALL
		end
		player.knightslide = true
	end
	if player.transformation == 0 and player.knightslide == true
		player.knightslide = false
	end
	if (player.mo.eflags & MFE_SPRUNG) and player.transformation == 1
		player.knightslide = false
	end
	if (player.transformation == 1) and (player.cmd.buttons & BT_CUSTOM1) and not (P_IsObjectOnGround(player.mo)) or player.knightdrop == true
		P_InstaThrust(player.mo, player.mo.angle, 0*FRACUNIT)
		P_SetObjectMomZ(player.mo, -40*FRACUNIT, false)
		player.knightslide = false
		player.knightdrop = true
		player.mo.state = S_PLAY_FALL
		player.normalspeed = 40*FRACUNIT
	end
	if (P_IsObjectOnGround(player.mo) or (player.mo.eflags & MFE_SPRUNG)) and player.knightdrop
		player.knightdrop = false
	end
end)

// Knight time done
//Lap 3 soon!?!?!?

addHook("ThinkFrame", function()
	for player in players.iterate()
		if not PBPizzaTime
		and gamemap == 28
			S_ChangeMusic("NONE")
		end
		if PBPizzaTime and S_MusicName(mapmusname) and not ((player.pflags & PF_FINISHED) or player.exitting)
			if gamemap ~= 28
				if not Lap2
					S_ChangeMusic("PIZTIM", true, i)
				elseif Lap2
					S_ChangeMusic("DEAOLI", true, i)
				end
			else
				if not Lap2
					S_ChangeMusic("BYEBYE", true, i)
				elseif Lap2
				and not Lap3
					S_ChangeMusic("DEAOLI", true, i)
				elseif Lap3
					S_ChangeMusic("MAYHEM", true, i)
				end
			end
		elseif PBPizzaTime and (S_MusicName("PIZTIM") or S_MusicName("DEAOLI") or S_MusicName("BYEBYE") or S_MusicName("MAYHEM")) and ((player.pflags & PF_FINISHED) or player.exitting)
			S_ChangeMusic(mapmusname, true, i)
		end
	end
end)

//Death PACT

addHook("PlayerThink", function(player)
local checkedrover = (player.mo.eflags & MFE_VERTICALFLIP) and "ceilingrover" or "floorrover"

	if P_IsObjectOnGround(player.mo) and not player.powers[pw_underwater] and not player.powers[pw_spacetime] and not player.liquiddamage and not player.mo[checkedrover] then
		player.prevx = player.mo.x
		player.prevy = player.mo.y
		player.prevz = player.mo.z
	end
end)

addHook("ShouldDamage", function(target, inflictor, source, damage, damagetype)
if NoMoveset return end
	if target 
	and target.valid 
	and target.player 
	and target.player.valid 
	and damagetype == DMG_DEATHPIT 
	and (ModdersBypass ~= true)
	and not LapImpossible
		if target and target.valid
		and inflictor and inflictor.valid
		and source and source.valid
		and target.type == MT_PLAYER
		and mapheaderinfo[gamemap].bonustype > 0
		and not target.player.liquiddamage
			if target.player.hp > 0
				target.player.hp = $ - 3
			elseif target.player.hp <= 3
				P_KillMobj(target, inflictor, source)
				target.player.hp = $ - 4
			end
		end
		target.player.techdifficulty = 60
		P_InstaThrust(target.player.mo, target.player.mo.angle, 0*FRACUNIT)
		P_SetOrigin(target.player.mo, target.player.prevx, target.player.prevy, target.player.prevz)
		if target.player.score >= 1000
			P_AddPlayerScore(target.player, -1000)
		end
		target.player.combo = target.player.combo - 25
		return false
	end
end)

addHook("ShouldDamage", function(target, inflictor, source, damage, damagetype)
if NoMoveset return end
	if target 
	and target.valid 
	and target.player 
	and target.player.valid 
	and damagetype == DMG_DROWNED 
	and (ModdersBypass ~= true)
	and not LapImpossible
		if target and target.valid
		and inflictor and inflictor.valid
		and source and source.valid
		and target.type == MT_PLAYER
		and mapheaderinfo[gamemap].bonustype > 0
		and not target.player.liquiddamage
			if target.player.hp > 0
				target.player.hp = $ - 3
			elseif target.player.hp <= 3
				P_KillMobj(target, inflictor, source)
				target.player.hp = $ - 4
			end
		end
		target.player.techdifficulty = 60
		P_InstaThrust(target.player.mo, target.player.mo.angle, 0*FRACUNIT)
		P_SetOrigin(target.player.mo, target.player.prevx, target.player.prevy, target.player.prevz)
		if target.player.score >= 1000
			P_AddPlayerScore(target.player, -1000)
		end
		target.player.combo = target.player.combo - 25
		return false
	end
end)

addHook("ShouldDamage", function(target, inflictor, source, damage, damagetype)
if NoMoveset return end
	if target 
	and target.valid 
	and target.player 
	and target.player.valid 
	and damagetype == DMG_CRUSHED 
	and (ModdersBypass ~= true)
	and not LapImpossible
		if target and target.valid
		and inflictor and inflictor.valid
		and source and source.valid
		and target.type == MT_PLAYER
		and mapheaderinfo[gamemap].bonustype > 0
		and not target.player.liquiddamage
			if target.player.hp > 0
				target.player.hp = $ - 3
			elseif target.player.hp <= 3
				P_KillMobj(target, inflictor, source)
				target.player.hp = $ - 4
			end
		end
		if target.player.score >= 1000
			P_AddPlayerScore(target.player, -1000)
		end
		target.player.combo = target.player.combo - 25
		return false
	end
end)

addHook("ShouldDamage", function(target, inflictor, source, damage, damagetype)
if NoMoveset return end
	if target 
	and target.valid 
	and target.player 
	and target.player.valid 
	and damagetype == DMG_SPIKE 
	and not target.player.taunting 
	and not (target.player.powers[pw_super]) 
	and (ModdersBypass ~= true)
	and not target.player.powers[pw_flashing]
	and not target.player.powers[pw_invulnerability]
	and not LapImpossible
		if target and target.valid
		and inflictor and inflictor.valid
		and source and source.valid
		and target.type == MT_PLAYER
		and mapheaderinfo[gamemap].bonustype > 0
		and not target.player.liquiddamage
			if target.player.hp > 0
				target.player.hp = $ - 1
			elseif target.player.hp <= 0
				P_KillMobj(target, inflictor, source)
				target.player.hp = $ - 1
			end
		end
		P_SetObjectMomZ(target.player.mo, 15*FRACUNIT, false)
		P_InstaThrust(target.player.mo, target.player.mo.angle, 0*FRACUNIT)
		target.player.mo.state = S_PLAY_PAIN
		S_StartSoundAtVolume(target.player.mo, L_Choose(sfx_ahh,sfx_ah,sfx_yeow,sfx_aww), 155)
		if target.player.score >= 500 and not target.player.liquiddamage
			P_AddPlayerScore(target.player, -500)
		end
		P_InstaThrust(target.player.mo, target.player.mo.angle, -20*FRACUNIT)
		if not target.player.liquiddamage
			target.player.combo = target.player.combo - 25
		end
		target.player.pflags = $ + PF_FULLSTASIS
		target.player.liquiddamage = true
		return false
	end
end)

addHook("ShouldDamage", function(target, inflictor, source, damage, damagetype)
if NoMoveset return end
	if target 
	and target.valid 
	and target.player 
	and target.player.valid 
	and damagetype == DMG_WATER 
	and not target.player.taunting 
	and not (target.player.powers[pw_super]) 
	and (ModdersBypass ~= true)
	and not target.player.powers[pw_flashing]
	and not target.player.powers[pw_invulnerability]
	and not LapImpossible
		if target and target.valid
		and inflictor and inflictor.valid
		and source and source.valid
		and target.type == MT_PLAYER
		and mapheaderinfo[gamemap].bonustype > 0
		and not target.player.liquiddamage
			if target.player.hp > 0
				target.player.hp = $ - 1
			elseif target.player.hp <= 0
				P_KillMobj(target, inflictor, source)
				target.player.hp = $ - 1
			end
		end
		P_SetObjectMomZ(target.player.mo, 15*FRACUNIT, false)
		P_InstaThrust(target.player.mo, target.player.mo.angle, 0*FRACUNIT)
		target.player.mo.state = S_PLAY_PAIN
		S_StartSound(target.player.mo, L_Choose(sfx_ahh,sfx_ah,sfx_yeow,sfx_aww))
		if target.player.score >= 500 and not target.player.liquiddamage
			P_AddPlayerScore(target.player, -500)
		end
		if not target.player.liquiddamage
			target.player.combo = target.player.combo - 25
		end
		target.player.liquiddamage = true
		return false
	end
end)

addHook("ShouldDamage", function(target, inflictor, source, damage, damagetype)
if NoMoveset return end
	if target 
	and target.valid 
	and target.player 
	and target.player.valid 
	and damagetype == DMG_FIRE 
	and not target.player.taunting 
	and not (target.player.powers[pw_super]) 
	and not (target.player.mach3 or target.player.mach4)
	and (ModdersBypass ~= true)
	and not target.player.powers[pw_flashing]
	and not target.player.powers[pw_invulnerability]
	and not LapImpossible
		if target and target.valid
		and inflictor and inflictor.valid
		and source and source.valid
		and target.type == MT_PLAYER
		and mapheaderinfo[gamemap].bonustype > 0
		and not target.player.liquiddamage
			if target.player.hp > 0
				target.player.hp = $ - 1
			elseif target.player.hp <= 0
				P_KillMobj(target, inflictor, source)
				target.player.hp = $ - 1
			end
		end
		P_SetObjectMomZ(target.player.mo, 15*FRACUNIT, false)
		P_InstaThrust(target.player.mo, target.player.mo.angle, 0*FRACUNIT)
		target.player.mo.state = S_PLAY_PAIN
		S_StartSound(target.player.mo, L_Choose(sfx_ahh,sfx_ah,sfx_yeow,sfx_aww))
		if target.player.score >= 500 and not target.player.liquiddamage
			P_AddPlayerScore(target.player, -500)
		end
		if not target.player.liquiddamage
			target.player.combo = target.player.combo - 25
		end
		target.player.liquiddamage = true
		return false
	elseif target and target.valid and target.player and target.player.valid and damagetype == DMG_FIRE and (target.player.mach3 or target.player.mach4 or target.player.powers[pw_super]) and (ModdersBypass ~= true)
		return false
	end
end)

addHook("ShouldDamage", function(target, inflictor, source, damage, damagetype)
if NoMoveset return end
	if target 
	and target.valid 
	and target.player 
	and target.player.valid 
	and damagetype == DMG_ELECTRIC
	and not target.player.taunting 
	and not (target.player.powers[pw_super]) 
	and (ModdersBypass ~= true)
	and not target.player.powers[pw_flashing]
	and not target.player.powers[pw_invulnerability]
	and not LapImpossible
		if target and target.valid
		and inflictor and inflictor.valid
		and source and source.valid
		and target.type == MT_PLAYER
		and mapheaderinfo[gamemap].bonustype > 0
		and not target.player.liquiddamage
			if target.player.hp > 0
				target.player.hp = $ - 1
			elseif target.player.hp <= 0
				P_KillMobj(target, inflictor, source)
				target.player.hp = $ - 1
			end
		end
		P_SetObjectMomZ(target.player.mo, 15*FRACUNIT, false)
		P_InstaThrust(target.player.mo, target.player.mo.angle, 0*FRACUNIT)
		target.player.mo.state = S_PLAY_PAIN
		S_StartSound(target.player.mo, L_Choose(sfx_ahh,sfx_ah,sfx_yeow,sfx_aww))
		if target.player.score >= 500 and not target.player.liquiddamage
			P_AddPlayerScore(target.player, -500)
		end
		if not target.player.liquiddamage
			target.player.combo = target.player.combo - 25
		end
		target.player.liquiddamage = true
		return false
	end
end)

addHook("ShouldDamage", function(target, inflictor, source, damage, damagetype)
if NoMoveset return end
	if target 
	and target.valid 
	and target.player 
	and target.player.valid 
	and damagetype == DMG_SPACEDROWN 
	and not target.player.taunting 
	and (ModdersBypass ~= true)
	and not LapImpossible
		if target and target.valid
		and inflictor and inflictor.valid
		and source and source.valid
		and target.type == MT_PLAYER
		and mapheaderinfo[gamemap].bonustype > 0
		and not target.player.liquiddamage
			if target.player.hp > 0
				target.player.hp = $ - 3
			elseif target.player.hp <= 3
				P_KillMobj(target, inflictor, source)
				target.player.hp = $ - 4
			end
		end
		P_SetOrigin(target.player.mo, target.player.prevx, target.player.prevy, target.player.prevz)
		P_InstaThrust(target.player.mo, target.player.mo.angle, 0*FRACUNIT)
		if target.player.score >= 500 and not target.player.liquiddamage
			P_AddPlayerScore(target.player, -1000)
		end
		target.player.combo = target.player.combo - 25
		return false
	end
end)

addHook("ShouldDamage", function(target, inflictor, source, damage, damagetype)
if NoMoveset return end
	if (target) 
	and (target.valid) 
	and (target.player) 
	and (target.player.valid) 
	and (damagetype == DMG_INSTAKILL or damagetype == DMG_DEATHMASK) 
	and not (target.player.taunting) 
	and (ModdersBypass ~= true)
	and not LapImpossible
		if target and target.valid
		and inflictor and inflictor.valid
		and source and source.valid
		and target.type == MT_PLAYER
		and mapheaderinfo[gamemap].bonustype > 0
		and not target.player.liquiddamage
			if target.player.hp > 0
				target.player.hp = $ - 1
			elseif target.player.hp <= 0
				P_KillMobj(target, inflictor, source)
				target.player.hp = $ - 1
			end
		end
		target.player.techdifficulty = 60
		P_SetObjectMomZ(target.player.mo, 15*FRACUNIT, false)
		P_InstaThrust(target.player.mo, target.player.mo.angle, -10*FRACUNIT)
		target.player.mo.state = S_PLAY_PAIN
		S_StartSound(target.player.mo, L_Choose(sfx_ahh,sfx_ah,sfx_yeow,sfx_aww))
		if target.player.score >= 500 and not target.player.liquiddamage
			P_AddPlayerScore(target.player, -500)
		end
		if not target.player.liquiddamage
			target.player.combo = target.player.combo - 25
		end
		target.player.liquiddamage = true
		return false
	end
end)

addHook("ShouldDamage", function(target, inflictor, source, damage, damagetype)
if NoMoveset return end
	if target 
	and target.valid 
	and target.player 
	and target.player.valid 
	and damagetype == 0 
	and not target.player.taunting and not (target.player.powers[pw_super]) 
	and (pizzaboi == nil or inflictor ~= pizzaboi) // Remove this inflictor for DBZ mode
	and (ModdersBypass ~= true)
	and not target.player.powers[pw_flashing]
	and not target.player.powers[pw_invulnerability]
	and not LapImpossible
		if target and target.valid
		and inflictor and inflictor.valid
		and source and source.valid
		and target.type == MT_PLAYER
		and mapheaderinfo[gamemap].bonustype > 0
		and not target.player.liquiddamage
			if target.player.hp > 0
				target.player.hp = $ - 1
			elseif target.player.hp <= 0
				P_KillMobj(target, inflictor, source)
				target.player.hp = $ - 1
			end
		end
		P_SetObjectMomZ(target.player.mo, 20*FRACUNIT, false)
		P_InstaThrust(target.player.mo, target.player.mo.angle, -20*FRACUNIT)
		S_StartSound(target.player.mo, L_Choose(sfx_ahh,sfx_ah,sfx_yeow,sfx_aww))
		if target.player.score >= 500 and not target.player.liquiddamage
			P_AddPlayerScore(target.player, -500)
		end
		if not target.player.liquiddamage
			target.player.combo = target.player.combo - 25
		end
		target.player.pflags = $ + PF_FULLSTASIS
		target.player.liquiddamage = true
		return false
	end
end)

addHook("ShouldDamage", function(target, inflictor, source, damage, damagetype)
if NoMoveset return end
	if target 
	and target.valid 
	and target.player 
	and target.player.valid 
	and damagetype == DMG_NUKE 
	and not target.player.taunting 
	and not (target.player.powers[pw_super]) 
	and (ModdersBypass ~= true)
	and not target.player.powers[pw_flashing]
	and not target.player.powers[pw_invulnerability]
	and not LapImpossible
		if target and target.valid
		and inflictor and inflictor.valid
		and source and source.valid
		and target.type == MT_PLAYER
		and mapheaderinfo[gamemap].bonustype > 0
		and not target.player.liquiddamage
			if target.player.hp > 0
				target.player.hp = $ - 1
			elseif target.player.hp <= 0
				P_KillMobj(target, inflictor, source)
				target.player.hp = $ - 1
			end
		end
		P_SetObjectMomZ(target.player.mo, 15*FRACUNIT, false)
		P_InstaThrust(target.player.mo, target.player.mo.angle, 0*FRACUNIT)
		target.player.mo.state = S_PLAY_PAIN
		S_StartSound(target.player.mo, L_Choose(sfx_ahh,sfx_ah,sfx_yeow,sfx_aww))
		if target.player.score >= 500 and not target.player.liquiddamage
			P_AddPlayerScore(target.player, -500)
		end
		P_InstaThrust(target.player.mo, target.player.mo.angle, -20*FRACUNIT)
		if not target.player.liquiddamage
			target.player.combo = target.player.combo - 25
		end
		target.player.liquiddamage = true
		return false
	end
end)

addHook("PlayerThink", function(player)
	if player.liquiddamage == true
		player.mo.state = S_PLAY_PAIN
		player.normalspeed = 15*FRACUNIT
	end
	if P_IsObjectOnGround(player.mo) and player.liquiddamage == true
		player.liquiddamage = false
		player.pflags = $  & ~PF_FULLSTASIS
	end
	if player.liquiddamage == true
		player.grabbing = 0
		player.sliding = 0
		player.uppercut = 0
		player.superjump = 0
		player.superjumpbuild = false
	end
end)

//Face man

local function face(v, player)
	if player.mo and player.mo.valid
		if (maptol & TOL_NIGHTS) then -- Prevents the code from running in a Nights special stage
			return
		end
		
		local facesprite = v.getSprite2Patch(player.skin, player.mo.sprite2, false, player.mo.frame, 2)
		local facetranssprite = v.getSprite2Patch(player.skin, player.mo.sprite2, true, player.mo.frame, 2)
		local facespritewater = v.getSprite2Patch(player.skin, SPR2_GASP, false, A, 2)
		local facetransspritewater = v.getSprite2Patch(player.skin, SPR2_GASP, true, A, 2)
		local facespritegravity = v.getSprite2Patch(player.skin, SPR2_EDGE, false, ((leveltime/11) % 2), 2, ANGLE_180)
		local facetransspritegravity = v.getSprite2Patch(player.skin, SPR2_EDGE, true, ((leveltime/11) % 2), 2, ANGLE_180)
		local facesupersprite = v.getSprite2Patch(player.skin, player.mo.sprite2, true, player.mo.frame, 2)
		local facesuperspritewater = v.getSprite2Patch(player.skin, SPR2_GASP, true, A, 2)
		local facesuperspritegravity = v.getSprite2Patch(player.skin, SPR2_EDGE, true, ((leveltime/11) % 2), 2, ANGLE_180)
		local facecolor = v.getColormap(player.skin, player.mo.color)
		
		if player.transformation == 0 and not ((player.mo.eflags & MFE_UNDERWATER) or (player.powers[pw_spacetime]) or (player.mo.eflags & MFE_VERTICALFLIP) or (player.powers[pw_super]))
			if player.squished == false
				v.drawScaled(50*FRACUNIT, 167*FRACUNIT, FRACUNIT/2, facesprite, V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_PERPLAYER|V_FLIP, facecolor)
			elseif player.squished == true
				v.drawScaled(50*FRACUNIT, 167*FRACUNIT, FRACUNIT/4, facesprite, V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_PERPLAYER|V_FLIP, facecolor)
			end
		elseif player.transformation > 0 and not ((player.mo.eflags & MFE_UNDERWATER) or (player.powers[pw_spacetime]) or (player.mo.eflags & MFE_VERTICALFLIP) or (player.powers[pw_super]))
			if not player.squished
				v.drawScaled(50*FRACUNIT, 167*FRACUNIT, FRACUNIT/2, facetranssprite,V_SNAPTOLEFT|V_SNAPTOBOTTOM| V_PERPLAYER|V_FLIP, facecolor)
			elseif player.squished
				v.drawScaled(50*FRACUNIT, 167*FRACUNIT, FRACUNIT/4, facetranssprite, V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_PERPLAYER|V_FLIP, facecolor)
			end
		elseif (player.mo.eflags & MFE_UNDERWATER) or (player.powers[pw_spacetime]) and (player.transformation == 0) and not (player.mo.eflags & MFE_VERTICALFLIP) and not (player.powers[pw_super])
			v.drawScaled(50*FRACUNIT, 167*FRACUNIT, FRACUNIT/2, facespritewater, V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_PERPLAYER|V_FLIP, facecolor)
		elseif (player.mo.eflags & MFE_UNDERWATER) or (player.powers[pw_spacetime]) and (player.transformation > 0) and not (player.mo.eflags & MFE_VERTICALFLIP) and not (player.powers[pw_super])
			v.drawScaled(50*FRACUNIT, 167*FRACUNIT, FRACUNIT/2, facetransspritewater, V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_PERPLAYER|V_FLIP, facecolor)
		elseif (player.mo.eflags & MFE_VERTICALFLIP) and (player.transformation == 0) and not (player.powers[pw_super])
			v.drawScaled(50*FRACUNIT, 167*FRACUNIT, FRACUNIT/2, facespritegravity, V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_PERPLAYER|V_FLIP, facecolor)
		elseif (player.mo.eflags & MFE_VERTICALFLIP) and (player.transformation > 0) and not (player.powers[pw_super])
			v.drawScaled(50*FRACUNIT, 167*FRACUNIT, FRACUNIT/2, facetransspritegravity, V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_PERPLAYER|V_FLIP, facecolor)
		elseif not ((player.mo.eflags & MFE_UNDERWATER) or (player.powers[pw_spacetime]) or (player.mo.eflags & MFE_VERTICALFLIP)) and (player.powers[pw_super])
		if not player.squished
			v.drawScaled(50*FRACUNIT, 167*FRACUNIT, FRACUNIT/2, facesupersprite, V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_PERPLAYER|V_FLIP, facecolor)
		end
		elseif (player.mo.eflags & MFE_UNDERWATER) or (player.powers[pw_spacetime]) and not (player.mo.eflags & MFE_VERTICALFLIP) and (player.powers[pw_super])
			v.drawScaled(50*FRACUNIT, 167*FRACUNIT, FRACUNIT/2, facesuperspritewater, V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_PERPLAYER|V_FLIP, facecolor)
		elseif (player.mo.eflags & MFE_VERTICALFLIP) and (player.powers[pw_super])
			v.drawScaled(50*FRACUNIT, 167*FRACUNIT, FRACUNIT/2, facesuperspritegravity, V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_PERPLAYER|V_FLIP, facecolor)
		end
	end
end
hud.add(face, "game")

//it's been a while since I wrote that much code, I feel proud of myself

addHook("PlayerThink", function(player)
	if PBPizzaTime == true and player.losescore == 0
		player.losescore = 26
	end
	if player.losescore > 0
		player.losescore = player.losescore - 1
	end
	if player.losescore < 0
		player.losescore = 0
	end
	if player.losescore == 25 and player.score >= 65 and not ((player.pflags & PF_FINISHED) or player.exitting)
		P_AddPlayerScore(player, -65)
	end
end)

addHook("PlayerThink", function(player)
if NoMoveset return end
	if (player.mo.ceilingz - player.mo.floorz) < skins[player.mo.skin].spinheight and player.playerstate == PST_LIVE
		player.crushed = player.crushed + 1
		player.squishedtimer = 500
		player.squished = true
		player.transformation = 2
		P_InstaThrust(player.mo, player.mo.angle, 0*FRACUNIT)
		if player.mo.spriteyscale > (FU/3)
			player.mo.spriteyscale = ((player.mo.ceilingz/player.mo.ceilingz) - player.mo.floorz)
		end
		if player.mo.spriteyscale < (FU/3)
			player.mo.spriteyscale = (FU/3)
			player.mo.spritexscale = (player.mo.spriteyscale*8)
		end
	end
	if player.squishedtimer > 0 and player.squished == true
		player.squishedtimer = player.squishedtimer - 1
	end
	if player.squishedtimer < 0
		player.squishedtimer = 0
	end
	if player.squishedtimer == 0 and player.squished == true
		player.mo.spriteyscale = 1*FRACUNIT
		player.mo.spritexscale = 1*FRACUNIT
		player.transformation = 0
		player.squished = false
	end
	if (player.mo.ceilingz - player.mo.floorz) >= skins[player.mo.skin].spinheight and player.playerstate == PST_LIVE
		player.crushed = 0
	end
	if player.crushed == 50 and player.playerstate == PST_LIVE
		P_KillMobj(player.mo, nil, nil)
		player.crushed = 0
	end
	if player.squishedtimer > 0
		player.height = 1048576
	elseif player.squishedtimer == 0 and player.squished
		player.height = 3145728
	end
	if (player.cmd.buttons & BT_ATTACK) and (player.transformation == 2) and not (player.ceilbonk) or (player.smallroll > 1)
		P_InstaThrust(player.mo, player.mo.angle, 40*FRACUNIT)
		player.mo.state = S_PLAY_ROLL
		if player.smallroll == 0
			player.smallroll = 25
		end
	end
	if player.smallroll > 0
		player.smallroll = player.smallroll - 1
	end
	if player.smallroll == 1
		if P_IsObjectOnGround(player.mo)
			player.mo.state = S_PLAY_RUN
		elseif not P_IsObjectOnGround(player.mo)
			player.mo.state = S_PLAY_ROLL
		end
	end
end)

addHook("PlayerThink", function(player)
	if not player.mo and player.mo.valid return end
	if player.playerstate == PST_DEAD return end
	if player.transformation ~= 2 return end
	if NoMoveset return end
	
	
	local mo = player.mo
	local me = player
	
	if mo and mo.valid
		me.jumping = true
	end
	
	if player.cmd.buttons & BT_JUMP > 0 then-- if p is pressing Custom2
		player.jumpdown = $1 + 1 -- increment custom2 variable
	else
		player.jumpdown = 0 -- reset custom2 variable
	end
	
	if me.jumpcount ~= 8 and player.jumping == true and player.jumpdown == 1 and not P_IsObjectOnGround(player.mo) and not player.liquiddamage
		if player.mo.momz < 0*FRACUNIT
			P_SetObjectMomZ(mo, 12*FRACUNIT, false)
		elseif player.mo.momz >= 0*FRACUNIT
			P_SetObjectMomZ(mo, 12*FRACUNIT, true)
		end
		S_StartSound(mo, sfx_jump)
		me.jumpcount = $1+1
		mo.state = S_PLAY_ROLL
		S_StartSound(mo, sfx_jump)
		return true
	end
end)

addHook("PlayerThink", function(player)
	local mo = player.mo
	local me = player
	
	if (P_IsObjectOnGround(mo) or mo.eflags & MFE_JUSTHITFLOOR or me.powers[pw_carry])
		me.jumpcount = 0
		me.jumping = false
	end
end)

local function technicaldifficulties(v, player)
	if player.mo and player.mo.valid
		if (maptol & TOL_NIGHTS) then -- Prevents the code from running in a Nights special stage
			return
		end
		
		local techd = v.cachePatch("TECHD")
		local stat1 = v.cachePatch("STAT1")
		local stat2 = v.cachePatch("STAT2")
		local stat3 = v.cachePatch("STAT3")
		local stat4 = v.cachePatch("STAT4")
		local stat5 = v.cachePatch("STAT5")
		local stat6 = v.cachePatch("STAT6")
		local stat7 = v.cachePatch("STAT7")
		local stat8 = v.cachePatch("STAT8")
		local stat9 = v.cachePatch("STAT9")
		
		if player.techdifficulty == 59
			v.drawScaled(157*FRACUNIT, 100*FRACUNIT, FRACUNIT/3, stat1, V_PERPLAYER)
		elseif player.techdifficulty == 58
			v.drawScaled(157*FRACUNIT, 100*FRACUNIT, FRACUNIT/3, stat2, V_PERPLAYER)
		elseif player.techdifficulty == 57
			v.drawScaled(157*FRACUNIT, 100*FRACUNIT, FRACUNIT/3, stat3, V_PERPLAYER)
		elseif player.techdifficulty == 56
			v.drawScaled(157*FRACUNIT, 100*FRACUNIT, FRACUNIT/3, stat4, V_PERPLAYER)
		elseif player.techdifficulty == 55
			v.drawScaled(157*FRACUNIT, 100*FRACUNIT, FRACUNIT/3, stat5, V_PERPLAYER)
		elseif player.techdifficulty == 54
			v.drawScaled(157*FRACUNIT, 100*FRACUNIT, FRACUNIT/3, stat6, V_PERPLAYER)
		elseif player.techdifficulty == 53
			v.drawScaled(157*FRACUNIT, 100*FRACUNIT, FRACUNIT/3, stat7, V_PERPLAYER)
		elseif player.techdifficulty == 52
			v.drawScaled(157*FRACUNIT, 100*FRACUNIT, FRACUNIT/3, stat8, V_PERPLAYER)
		elseif player.techdifficulty == 51
			v.drawScaled(157*FRACUNIT, 100*FRACUNIT, FRACUNIT/3, stat9, V_PERPLAYER)
		elseif player.techdifficulty > 11 and player.techdifficulty < 50
			v.drawScaled(157*FRACUNIT, 100*FRACUNIT, FRACUNIT/3, techd, V_PERPLAYER)
		elseif player.techdifficulty == 10
			v.drawScaled(157*FRACUNIT, 100*FRACUNIT, FRACUNIT/3, stat9, V_PERPLAYER)
		elseif player.techdifficulty == 9
			v.drawScaled(157*FRACUNIT, 100*FRACUNIT, FRACUNIT/3, stat8, V_PERPLAYER)
		elseif player.techdifficulty == 8
			v.drawScaled(157*FRACUNIT, 100*FRACUNIT, FRACUNIT/3, stat7, V_PERPLAYER)
		elseif player.techdifficulty == 7
			v.drawScaled(157*FRACUNIT, 100*FRACUNIT, FRACUNIT/3, stat6, V_PERPLAYER)
		elseif player.techdifficulty == 6
			v.drawScaled(157*FRACUNIT, 100*FRACUNIT, FRACUNIT/3, stat5, V_PERPLAYER)
		elseif player.techdifficulty == 5
			v.drawScaled(157*FRACUNIT, 100*FRACUNIT, FRACUNIT/3, stat4, V_PERPLAYER)
		elseif player.techdifficulty == 4
			v.drawScaled(157*FRACUNIT, 100*FRACUNIT, FRACUNIT/3, stat3, V_PERPLAYER)
		elseif player.techdifficulty == 3
			v.drawScaled(157*FRACUNIT, 100*FRACUNIT, FRACUNIT/3, stat2, V_PERPLAYER)
		elseif player.techdifficulty == 2
			v.drawScaled(157*FRACUNIT, 100*FRACUNIT, FRACUNIT/3, stat1, V_PERPLAYER)
		end
	end
end
hud.add(technicaldifficulties, "game")

addHook("PlayerThink", function(player)
	if player.techdifficulty < 0
		player.techdifficulty = 0
		player.techscreen = true
	end
	if player.techdifficulty > 0
		player.techdifficulty = player.techdifficulty - 1
		player.grabbing = 0
		player.sliding = 0
		player.superjump = 0
		player.pflags = $ + PF_FULLSTASIS
	end
	if player.techdifficulty == 0 and player.techscreen == true
		player.pflags = $  & ~PF_FULLSTASIS
		player.techscreen = false
	end
end)

local function technicalhurt(v, player)
	if player.mo and player.mo.valid
		if (maptol & TOL_NIGHTS) then -- Prevents the code from running in a Nights special stage
			return
		end
		
		local sonic = v.cachePatch("HURTS")
		local tails = v.cachePatch("HURTT")
		local knuckles = v.cachePatch("HURTK")
		local amy = v.cachePatch("HURTA")
		
		if player.techdifficulty > 11 and player.techdifficulty < 50
			if player.mo.skin == "sonic"
				v.drawScaled(30*FRACUNIT, 40*FRACUNIT, FRACUNIT/2, sonic, V_PERPLAYER)
			elseif player.mo.skin == "tails"
				v.drawScaled(30*FRACUNIT, 40*FRACUNIT, FRACUNIT/2, tails, V_PERPLAYER)
			elseif player.mo.skin == "knuckles"
				v.drawScaled(30*FRACUNIT, 40*FRACUNIT, FRACUNIT/2, knuckles, V_PERPLAYER)
			elseif player.mo.skin == "amy"
				v.drawScaled(30*FRACUNIT, 40*FRACUNIT, FRACUNIT/2, amy, V_PERPLAYER)
			end
		end
	end
end
hud.add(technicalhurt, "game")

addHook("PlayerThink", function(player)
if NoMoveset return end
	if player.mach3 or player.mach4 or player.grabbing
		player.powers[pw_strong] = STR_MACH
	elseif player.superjump > 0 or player.wallrunning
		player.powers[pw_strong] = STR_JUMP
	elseif player.bodyslam or player.divebomb or player.knightdrop
		player.powers[pw_strong] = STR_SLAM
	elseif player.transformation == 1
		player.powers[pw_strong] = STR_KNIGHT
	else
		player.powers[pw_strong] = STR_NONE
	end
end)

addHook("MobjCollide", function(special, toucher)
if NoMoveset return end
local player = toucher.player
	if special.z <= player.mo.z + player.mo.height
	and special.z + special.height >= player.mo.z
	and player and player.mo.valid and special and special.valid
		player.boost = 25
		player.boostedangle = special.angle
	end
end, MT_YELLOWBOOSTER)

addHook("MobjCollide", function(special, toucher)
if NoMoveset return end
local player = toucher.player
	if special.z <= player.mo.z + player.mo.height
	and special.z + special.height >= player.mo.z
	and player and player.mo.valid and special and special.valid
		player.superboost = 25
		player.boostedangle = special.angle
	end
end, MT_REDBOOSTER)

addHook("PlayerThink", function(player)
if NoMoveset return end
	if player.boost > 0
		player.boost = player.boost - 1
	end
	if player.superboost > 0
		player.superboost = player.superboost - 1
	end
	if player.boost > 0
		P_InstaThrust(player.mo, player.boostedangle, 60*FRACUNIT)
		player.normalspeed = 40*FRACUNIT
		player.mo.state = S_PLAY_RUN
	end
	if player.superboost > 0
		P_InstaThrust(player.mo, player.boostedangle, 100*FRACUNIT)
		player.normalspeed = 80*FRACUNIT
		player.mo.state = S_PLAY_RUN
	end
end)

addHook("PlayerThink", function(player)
if NoMoveset return end
	if (player.mo.skin == "sonic") and (player.firenormdown == 1) and not (player.homingattack) and not (P_IsObjectOnGround(player.mo)) and (player.pflags & PF_JUMPED) and (player.mach3 or player.mach4) and (P_LookForEnemies(player)) and not (player.supertaunt)
		player.homingattack = true
	end
	if (P_IsObjectOnGround(player.mo) or P_PlayerInPain(player) or player.speed == 0 or player.mo.momz == 0 or not P_LookForEnemies(player)) and player.homingattack == true 
		player.homingattack = false
	end
	if player.homingattack
		P_HomingAttack(player.mo, P_LookForEnemies(player))
	end
	if player.mo.skin == "tails" and (player.mo.state == S_PLAY_UPPERCUT1 or player.mo.state == S_PLAY_UPPERCUT2) and not player.flying
		player.flying = true
		P_SetObjectMomZ(player.mo, 40*FRACUNIT, false)
		P_NukeEnemies(player.mo, player.mo, 750*FRACUNIT)
		S_StartSound(player.mo, 16)
		player.mo.state = S_PLAY_FLY
	end
	if P_IsObjectOnGround(player.mo)
		player.flying = false
	end
	if player.flying
	and not S_SoundPlaying(player.mo, 16)
		S_StartSound(player.mo, 16)
	end
	if (player.cmd.buttons & BT_FIRENORMAL) and (player.mo.skin == "fang") and (player.guncooldown == 0) and not (player.supertaunt) and not (player.liquiddamage)
		local bullet = P_SpawnMobjFromMobj(
			player.mo,
			FixedMul(cos(player.mo.angle-ANG15)*2, player.mo.radius)
				+ (P_RandomRange(-10, 10)),
			FixedMul(sin(player.mo.angle-ANG15)*2, player.mo.radius)
				+ (P_RandomRange(-10, 10)),
			player.mo.height/2 + (P_RandomRange(-2, 2)),
			MT_CORK
		)
		local angle = player.mo.angle
		bullet.target = player.mo
		bullet.momx = (cos(angle)*500)
		bullet.momy = (sin(angle)*500)
		bullet.angle = player.mo.angle
		player.guncooldown = 5
		S_StartSound(player.mo, sfx_corkp)
	end
	
	if player.guncooldown > 0
		player.guncooldown = player.guncooldown - 1
	end
	if player.guncooldown < 0
		player.guncooldown = 0
	end
	if (player.firenormdown == 1) and (player.mo.skin == "amy") and (player.hammerjumped == false) and (P_IsObjectOnGround(player.mo)) and (player.mach3 or player.mach4)
		P_SetObjectMomZ(player.mo, 40*FRACUNIT, false)
		player.hammerjumped = true
		player.mo.state = S_PLAY_MELEE
		P_NukeEnemies(player.mo, player.mo, 950*FRACUNIT)
	elseif (player.firenormdown == 1) and (player.mo.skin == "amy") and (player.hammerjumped == true) and not (P_IsObjectOnGround(player.mo)) or player.hammerslam == true
		P_SetObjectMomZ(player.mo, -10*FRACUNIT, true)
		player.hammerslam = true
	end
	if P_IsObjectOnGround(player.mo) and player.mo.skin == "amy"
		if player.hammerslam == true
			P_NukeEnemies(player.mo, player.mo, 950*FRACUNIT)
		end
		player.hammerslam = false
		player.hammerjumped = false
	end
	if player.mo.state == S_PLAY_MELEE
		player.hammerjumped = true
	end
	if P_IsObjectOnGround(player.mo)
		player.homingattack = false
	end
	if player.mo.skin == "metalsonic" and not P_IsObjectOnGround(player.mo) and player.custom3down > 0 and player.cantrise == false and (player.mach3 or player.mach4)
		player.rised = player.rised + 1
	elseif player.custom3down == 0 and player.rised > 0
		player.rised = 0
		player.cantrise = true
		P_InstaThrust(player.mo, player.mo.angle, player.normalspeed)
		P_SetObjectMomZ(player.mo, 0*FRACUNIT, false)
		P_NukeEnemies(player.mo, player.mo, 500*FRACUNIT)
		player.mo.state = S_PLAY_DASH
	end
	if player.rised >= 50
		player.rised = 0
		player.cantrise = true
		P_InstaThrust(player.mo, player.mo.angle, player.normalspeed)
		P_SetObjectMomZ(player.mo, 0*FRACUNIT, false)
		P_NukeEnemies(player.mo, player.mo, 500*FRACUNIT)
		player.mo.state = S_PLAY_DASH
	end
	if player.rised > 0
		P_SetObjectMomZ(player.mo, 20*FRACUNIT, false)
		player.mo.state = S_PLAY_SPRING
	end
	if P_IsObjectOnGround(player.mo) and player.mo.skin == "metalsonic"
		player.cantrise = false
	end
	if player.rised > 0 and not (player.mach3 or player.mach4)
		player.cantrise = true
		player.rised = 0
		P_SetObjectMomZ(player.mo, 0*FRACUNIT, false)
	end
	if player.normalspeed > skins[player.mo.skin].actionspd
		player.actionspd = player.normalspeed
	end
end)

addHook("MobjDamage", function(target, inflictor, source, damage, damagetype)
if NoMoveset return end
	if inflictor and inflictor.valid and inflictor.player and inflictor.player.mo and inflictor.player.homingattack
		inflictor.player.homingattack = false
		P_InstaThrust(inflictor.player.mo, inflictor.player.mo.angle, (inflictor.player.normalspeed - 15*FRACUNIT))
	end
	if inflictor and inflictor.valid and inflictor.player and inflictor.player.mo and inflictor.player.diving
		inflictor.player.diving = false
	end
end)

addHook("PlayerThink", function(player)
if NoMoveset return end
	if player.breakdance and player.breakdancetimer == 0 and P_IsObjectOnGround(player.mo)
		player.mo.state = L_Choose(S_PLAY_ROLL,S_PLAY_SPRING,S_PLAY_RUN,S_PLAY_WAIT,S_PLAY_EDGE,S_PLAY_STND,S_PLAY_SPINDASH,S_PLAY_DASH)
		if PBPizzaTime
			P_AddPlayerScore(player, 100)
		end
		player.breakdancetimer = 10
	end
	if (player.speed > 20*FRACUNIT or not (player.cmd.buttons & BT_TOSSFLAG)) and player.breakdance
		player.breakdance = false
	end
	if player.breakdancetimer > 0
		player.breakdancetimer = player.breakdancetimer - 1
		player.mo.state = player.mo.state
	end
end)

//A new useless thinkframe that could easily be avoided, but I choose not to!
//Anyways this is from TG, thanks alot to him!

addHook("ThinkFrame", do
if NoMoveset return end
    for player in players.iterate
        local mo = player.mo
        if P_IsObjectOnGround(mo)
        and (player.mach3 or player.mach4)
        and leveltime%10 == 0
            for i = -1, 1, 2
                local ang = i * ANG10
                local factor = FixedMul(4*mo.scale, cos(ang))
                local x = P_ReturnThrustX(mo, player.drawangle + ANGLE_180 + ang, 24*mo.scale)
                local y = P_ReturnThrustY(mo, player.drawangle + ANGLE_180 + ang, 24*mo.scale)
                local dust = P_SpawnMobjFromMobj(mo, x, y, 0, MT_MACH3D)
				if player.mach3
					dust.scale = 2*$/3
				elseif player.mach4
					dust.scale = 2*$/2
				end
                dust.angle = R_PointToAngle2(dust.x, dust.y, mo.x, mo.y)
                dust.state = S_MACH3_DASH
                dust.momx = FixedMul(factor, cos(dust.angle - i*ANGLE_90))
                dust.momy = FixedMul(factor, sin(dust.angle - i*ANGLE_90))
            end
        end
    end
end)


//Thanks to luigi budd for this one
addHook("ThinkFrame", do
if NoMoveset return end
    for p in players.iterate
		if p.mach4  and not (p.superjump or p.wallrunning) and p.cooleffect == 0
			local x,y = cos(p.drawangle),sin(p.drawangle)
			local runmacheffect = P_SpawnMobjFromMobj(p.mo,-30*x,-30*y,0,MT_MACHE)
			runmacheffect.angle = (R_PointToAngle2(runmacheffect.x, runmacheffect.y, p.mo.x, p.mo.y) + ANGLE_90)
			p.cooleffect = 10
		end
		if (p.mach3 or p.mach4 or p.sliding) and not (p.superjump or p.wallrunning) and not ((p.mo.eflags & MFE_UNDERWATER) or p.powers[pw_spacetime]) and p.windeffect >= FRACUNIT
			local x,y = cos(p.drawangle),sin(p.drawangle)
			local wind = P_SpawnMobjFromMobj(p.mo,P_RandomRange(0, -500)*x,P_RandomRange(0, -500)*y,P_RandomRange(0, 150)*FRACUNIT,MT_SPDLINES)
			wind.angle = R_PointToAngle2(wind.x, wind.y, p.mo.x, p.mo.y)
			wind.state = S_SPEED_LINES
			p.windeffect = 0*FRACUNIT
		end
		if p.superjump or p.wallrunning
			local x,y = cos(p.drawangle),sin(p.drawangle)
			local wall = P_SpawnMobjFromMobj(p.mo, 0*x, 0*y, -40*FRACUNIT, MT_SPDLINES)
			wall.angle = (R_PointToAngle2(wall.x, wall.y, p.mo.x, p.mo.y) + ANGLE_90)
			wall.state = S_WALL_LINES
		end
		if p.cooleffect > 0
			p.cooleffect = p.cooleffect - 1
		end
		if (p.mach3 or p.mach4)
			p.windeffect = p.windeffect + FixedDiv(p.speed, 80*FRACUNIT)
		else
			p.windeffect = 0*FRACUNIT
		end
	end
end)
//K back to me stuff

addHook("PlayerThink", function(p)
if NoMoveset return end
	if (p.mach3 or p.mach4 and (p.speed >= 40*FRACUNIT)) or p.superjump or p.sliding or p.uppercut or p.divebomb or p.bash or p.wallrunning
		createafterimage(p)
	end
end)
//K TG's stuff is done

addHook("ShouldDamage", function(target, inflictor, source, damage, damagetype)
	if inflictor and inflictor.player
	and (target.flags & MF_ENEMY)
	and not (target.flags & MF_BOSS)
	and target.type ~= MT_PILLARBOI
	and target.type ~= MT_PIZZAFACE
	and P_PlayerCanDamage(inflictor.player, target)
		if target.gonnadie ~= true
			local player = inflictor.player
			P_InstaThrust(target, inflictor.player.mo.angle, inflictor.player.speed + 15*FRACUNIT)
			P_SetObjectMomZ(target, inflictor.player.speed/2, false)
			target.flags = $ & ~(MF_NOGRAVITY | MF_FLOAT | MF_NOCLIPHEIGHT | MF_NOCLIPTHING)
			if not NoMoveset and (player.mach3 or player.mach4 or player.grabbing or player.supertaunt or player.bodyslam or player.divebomb or player.transformation == 1 or player.smallroll) or NoMoveset
				target.gonnadie = true
			end
			if not NoMoveset and (player.mach3 or player.mach4 or player.grabbing or player.supertaunt or player.bodyslam or player.divebomb or player.transformation == 1 or player.smallroll) or NoMoveset
				inflictor.player.combo = 200
				inflictor.player.comboamount = inflictor.player.comboamount + 1
				inflictor.player.enemieskilled = inflictor.player.enemieskilled + 1
				inflictor.player.ones = inflictor.player.ones + 1
			else
				inflictor.player.combo = 200
			end
			if not NoMoveset and (player.mach3 or player.mach4 or player.grabbing or player.supertaunt or player.bodyslam or player.divebomb or player.transformation == 1 or player.smallroll) or NoMoveset
				P_SpawnMobjFromMobj(target, 0, 0, 0, MT_BANG)
				S_StartSound(inflictor.player.mo, sfx_kill)
			end
			table.insert(inflictor.player.gonnadie, target)
			target.true_sprite = target.sprite
			target.true_flags = target.flags
			target.state = S_KNOCKED
		end
		return false
	end
end)

addHook("PlayerThink", function(player)
	for k, mobj in ipairs(player.gonnadie) do
		if mobj == true or not mobj.valid continue end
		if mobj.gonnadie == false return end
		if mobj.valid
		and mobj.boomtime == nil
			mobj.boomtime = 0*TICRATE
		end
		if mobj.valid
		and mobj.boomtime > 0*TICRATE
			mobj.boomtime = mobj.boomtime - 4
		end
		if mobj.valid
		and mobj.newangle == nil
			mobj.newangle = mobj.angle
		end
		if mobj.valid
		and mobj.gonnadie == true
		and (P_IsObjectOnGround(mobj) or (mobj.eflags & MFE_JUSTHITFLOOR))
		and mobj.momz == 0
			mobj.gonnadie = false
			P_SpawnMobjFromMobj(mobj, 0, 0, 0, MT_BANG)
			P_SpawnMobjFromMobj(mobj, 0, 0, 0, MT_EXPLODE)
			S_StartSound(mobj, 119)
			P_RemoveMobj(mobj)
			player.scared[k] = true
		end
		if mobj.valid
		and mobj.gonnadie == true
			P_SpawnMobjFromMobj(mobj, 0, 0, 0, MT_SPINDUST)
			mobj.angle = mobj.newangle
			mobj.newangle = $ + ANG20
			mobj.flags = $ & ~(MF_NOGRAVITY | MF_FLOAT | MF_NOCLIPHEIGHT | MF_NOCLIPTHING)
			mobj.state = S_KNOCKED
		end
		if mobj.valid
		and mobj.gonnadie == true
		and mobj.boomtime == 0
			P_SpawnMobjFromMobj(mobj, 0, 0, 0, MT_BANG)
			mobj.boomtime = 1*TICRATE
		end
	end
end)

addHook("MobjMoveBlocked", function(mobj)
	for player in players.iterate()
		for k, mobj in ipairs(player.gonnadie) do
			if mobj == true or not mobj.valid continue end
			if mobj.gonnadie == true
				mobj.gonnadie = false
				P_SpawnMobjFromMobj(mobj, 0, 0, 0, MT_BANG)
				P_SpawnMobjFromMobj(mobj, 0, 0, 0, MT_EXPLODE)
				S_StartSound(mobj, 119)
				P_RemoveMobj(mobj)
				player.gonnadie[k] = true
			end
		end
	end
end)

addHook("PlayerSpawn", function(player)
	if Warned == false
		COM_BufInsertText(server,"csay " + "Epilepsy Warning, proceed with caution")
		Warned = true
	end
end)

addHook("MapThingSpawn", function(mobj, mapthing)
	if not udmf
		if ((mapthing.extrainfo == 1) or (mapthing.extrainfo == 2) or (mapthing.extrainfo == 3))
			mobj.enterablesecret = true
			mobj.enterlocation = mapthing.extrainfo
		elseif ((mapthing.extrainfo == 4) or (mapthing.extrainfo == 5) or (mapthing.extrainfo == 6))
			mobj.teleportsecret = true
			mobj.teleportnum = mapthing.extrainfo - 3
		elseif ((mapthing.extrainfo == 7) or (mapthing.extrainfo == 8) or (mapthing.extrainfo == 9))
			mobj.finishsecret = true
			mobj.finishlocation = mapthing.extrainfo - 6
		end
	elseif udmf
		if ((mapthing.args[0] == 1) or (mapthing.args[0] == 3) or (mapthing.args[0] == 3))
			mobj.enterablesecret = true
			mobj.enterlocation = mapthing.args
		elseif ((mapthing.args[0] == 4) or (mapthing.args[0] == 5) or (mapthing.args[0] == 6))
			mobj.teleportsecret = true
			mobj.teleportnum = thing.args - 3
		elseif ((mapthing.args[0] == 7) or (mapthing.args[0] == 8) or (mapthing.args[0] == 9))
			mobj.finishsecret = true
			mobj.finishlocation = thing.args - 6
		end
	end
end, MT_SECRET)

addHook("TouchSpecial", function(secret, mo)
local player = mo.player
	for mobj in mobjs.iterate(mobj)
		if mobj and mobj.valid
		and mobj.type == MT_SECRET
		and mobj.teleportsecret == true
		and secret.state == S_SECRET_OPEN
			P_SetOrigin(player.mo, mobj.x, mobj.y, mobj.z)
			mobj.state = S_SECRET_CLOSED
		end
		if secret.state == S_SECRET_OPEN
		and secret.enterablesecret == true
			SecretCount = SecretCount + 1
			secret.state = S_SECRET_CLOSED
			if player.comboamount > 0
				player.combo = 200
			end
			P_AddPlayerScore(player, 1000)
			print(player.name+" has just found a secret!")
			print ("Secret Amount: " + (SecretCount) + "/3")
		end
	end
return true
end, MT_SECRET)

addHook("PlayerThink", function(player)
local mobj = P_LookForEnemies(player)
    if P_LookForEnemies(player)
    and P_PlayerCanDamage(player, mobj)
    and (player.mach3 or player.mach4)
    and mobj.type ~= MT_PLAYER
    and mobj.type ~= MT_PILLARBOI
    and mobj.type ~= MT_PIZZAFACE
    and (mobj.flags & MF_ENEMY)
    and not (mobj.flags & MF_BOSS)
    and not mobj.scared 
	and not mobj.gonnadie then
        table.insert(player.scared, mobj)
        mobj.scared = true
        S_StartSound(mobj, sfx_scare)
		mobj.true_angle = mobj.angle
        mobj.true_sprite = mobj.sprite
        mobj.true_frame = mobj.frame
        mobj.state = S_SCARED
		mobj.true_flags = mobj.flags
		mobj.flags = $ & ~(MF_NOGRAVITY | MF_FLOAT | MF_NOCLIPHEIGHT | MF_NOCLIPTHING)
    end
    for k, mobj in ipairs(player.scared) do
        if mobj == true or not mobj.valid then continue end
        if not P_LookForPlayers(mobj, 512*FRACUNIT, true)
			mobj.flags = mobj.true_flags
            mobj.scared = false
            mobj.jumped = false
			mobj.state = mobj.info.spawnstate
            player.scared[k] = true
        end
        if not mobj.gonnadie
        and mobj.momz == 0
        and P_IsObjectOnGround(mobj)
            if not mobj.jumped
                P_SetObjectMomZ(mobj, 5*FRACUNIT, false)
                mobj.jumped = true
            end
        end
    end
	for k, mobj in ipairs(player.gonnadie) do
		 if mobj == true or not mobj.valid then continue end
		 if not P_LookForPlayers(mobj, 512*FRACUNIT, true)
		 and not mobj.gonnadie
			mobj.flags = mobj.true_flags
            mobj.gonnadie = false
			mobj.state = mobj.info.spawnstate
            player.gonnadie[k] = true
        end
	end
end)

local function livez(v, player)
	if (maptol & TOL_NIGHTS) then
		return
	end
	if player.mo and player.mo.valid and mapheaderinfo[gamemap].bonustype > 0 then
		
		local hatanim = ((leveltime/2) % 19) + 1
		local hat = v.cachePatch( 'PEP_HAT' .. hatanim )
		local xpatch = v.cachePatch( 'PEP_LIVESX' )
		
		v.drawScaled(10*FRACUNIT, 195*FRACUNIT, FRACUNIT/2, hat, V_PERPLAYER|V_SNAPTOLEFT|V_SNAPTOBOTTOM)
		v.drawScaled(30*FRACUNIT, 195*FRACUNIT, FRACUNIT/2, xpatch, V_PERPLAYER|V_SNAPTOLEFT|V_SNAPTOBOTTOM)
		local x = 40*FRACUNIT
		local str = tostring(player.hp + 1)
		for i=1,#str do
			v.drawScaled(x, 195*FRACUNIT, FRACUNIT/2, v.cachePatch( 'PEP_NUM' .. str:sub(i,i) ), V_PERPLAYER|V_SNAPTOLEFT|V_SNAPTOBOTTOM)
			x = $ + FRACUNIT*7
		end
	end
end
hud.add(livez, "game")

addHook("MobjDeath", function(target, inflictor, source, damagetype)
if NoMoveset return end
	if target.player and target.player.valid
	and target and target.valid
	and inflictor and inflictor.valid
	and not (damagetype & DMG_INSTAKILL)
	and not (damagetype & DMG_CRUSHED)
		target.flags = $ & ~MF_NOGRAVITY
		P_SetObjectMomZ(target, 16*FRACUNIT)
	end
end)

addHook("PlayerThink", function(player)
if NoMoveset return end
	if player.playerstate == PST_DEAD
		player.mo.flags = $ & ~MF_NOCLIPHEIGHT
		player.mo.flags = $ & ~MF_NOGRAVITY
		player.mo.flags2 = $ & ~MF2_DONTDRAW
		if not P_IsObjectOnGround(player.mo)
			player.mo.state = S_PLAY_PAIN
		elseif P_IsObjectOnGround(player.mo)
			player.mo.state = S_PLAY_DEAD
		end
	end
end)


addHook("PlayerThink", function(player)
if NoMoveset return end
	if player.mo.standingslope
	and player.previousz > player.mo.z
	and player.machrun
		player.normalspeed = player.normalspeed + 1*FRACUNIT
	elseif player.mo.standingslope
	and player.previousz < player.mo.z
	and player.machrun
		if not player.uncappedspeed
			player.normalspeed = player.normalspeed - (FRACUNIT/3)
		elseif player.uncappedspeed
			player.normalspeed = player.normalspeed - 1*FRACUNIT
		end
	end
	if player.previousz ~= player.mo.z
	and not player.mo.standingslope
	and leveltime%5 == 0
		player.previousz = player.mo.z
	end
end)

local function SceneryCollide(mo, mobj)
	if mobj and mobj.valid
	and mo and mo.valid
	and mo.player and mo.player.valid
	local player = mo.player
		if mobj.z <= player.mo.z + player.mo.height
		and mobj.z + mobj.height >= player.mo.z
		and (mobj.flags & MF_SCENERY)
		and (player.mach3 or player.mach4)
			P_InstaThrust(mobj, player.mo.angle, player.speed + 15*FRACUNIT)
			P_SetObjectMomZ(mobj, player.speed/2, false)
			mobj.flags = $ & ~(MF_NOGRAVITY | MF_FLOAT | MF_NOCLIPHEIGHT | MF_NOCLIPTHING)
			player.combo = 200
			player.comboamount = player.comboamount + 1
			player.enemieskilled = player.enemieskilled + 1
			player.ones = player.ones + 1
			P_SpawnMobjFromMobj(mobj, 0, 0, 0, MT_BANG)
			S_StartSound(player.mo, sfx_kill)
			P_InstaThrust(player.mo, player.mo.angle, player.normalspeed)
		end
	end
end

addHook("MobjMoveCollide", SceneryCollide)

addHook("MobjDeath", function(target, inflictor, source, damagetype)
if NoMoveset return end
	if target and target.valid
	and source and source.valid
	and source.player and source.player.valid
	and source.type == MT_PLAYER
	and (target.flags & MF_BOSS)
	and mapheaderinfo[gamemap].bonustype > 0
		local player = source.player
		if player.hp == 5
			player.score = 35000
		elseif player.hp == 4
			player.score = 30000
		elseif player.hp == 3
			player.score = 25000
		elseif player.hp == 2
			player.score = 15000
		elseif player.hp == 1
			player.score = 500
		elseif player.hp == 0
			player.score = 0
		elseif player.hp == -1
			print "Bro how are you even alive"
		end
		DefeatedBoss = true
	end
end)

addHook("PostThinkFrame", function(player)
if NoMoveset return end
	for player in players.iterate()
		if mapheaderinfo[gamemap].bonustype > 0
		and player.hp == 5
			player.combo = 200
			PRank = true
		elseif player.hp < 5
		and mapheaderinfo[gamemap].bonustype > 0
			player.combo = 0
		elseif player.hp == 0
		and mapheaderinfo[gamemap].bonustype > 0
			player.score = 0
		end
		if mapheaderinfo[gamemap].bonustype > 0
		and DefeatedBoss
			if player.hp == 5
				player.score = 35000
			elseif player.hp == 4
				player.score = 30000
			elseif player.hp == 3
				player.score = 25000
			elseif player.hp == 2
				player.score = 15000
			elseif player.hp == 1
				player.score = 500
			elseif player.hp == 0
				player.score = 0
			elseif player.hp == -1
				print "Bro how are you even alive"
			end
		end
	end
end)

//The forgotten Super Taunt effect

addHook("PlayerThink", function(player)
if NoMoveset return end
    if player.supertaunt
        local steffect = P_SpawnMobjFromMobj(player.realmo, P_RandomRange(-20, 20) * FRACUNIT, P_RandomRange(-20, 20) * FRACUNIT, P_RandomRange(0, 50) * FRACUNIT, MT_STE)
        steffect.color = SKINCOLOR_WHITE
        steffect.colorized = true
    end
end)

//Springy Fun

local function PB_SpringCheck(special)
	if special and special.valid
		if (special.type == MT_BLUEHORIZ or special.type == MT_YELLOWHORIZ or special.type == MT_REDHORIZ)
			return true
		else
			return false
		end
	end
end

addHook("MobjCollide", function(special, toucher)
if NoMoveset return end
	if special and special.valid
	and toucher and toucher.valid
	and toucher.player and toucher.player.valid
	and toucher.type == MT_PLAYER
	and PB_SpringCheck(special)
	and special.z <= toucher.z + toucher.height
	and special.z + special.height >= toucher.z
		local player = toucher.player
		if special.type == MT_BLUEHORIZ
			player.normalspeed = $ + 10*FRACUNIT
		elseif special.type == MT_YELLOWHORIZ
			player.normalspeed = $ + 20*FRACUNIT
		else
			player.normalspeed = $ + 40*FRACUNIT
		end
	end
end)

//Final Stretch

addHook("MobjLineCollide", function(mobj, line)
	if line and line.valid
	and mobj and mobj.valid
	and mobj.player and mobj.player.valid
	and line.special == 345
		if not PBPizzaTime
			PBPizzaTime = true
			TimeTilPF = 1*TICRATE
			return nil
		end
	end
end, MT_PLAYER)

//Now that I know I can do that

addHook("MobjLineCollide", function(mobj, line)
	if line and line.valid
	and mobj and mobj.valid
	and line.special == 346
		if not PBPizzaTime
			return true
		else
			return nil
		end
	end
end)

addHook("MobjLineCollide", function(mobj, line)
	if line and line.valid
	and mobj and mobj.valid
	and line.special == 347
		if PBPizzaTime
			return true
		else
			return nil
		end
	end
end)

addHook("MobjMoveBlocked", function(mobj)
if NoMoveset return end
	if mobj and mobj.valid
	and mobj.player and mobj.player.valid
		local player = mobj.player
		if player.mo.standingslope 
		and player.mo.z > player.prevz
		and player.transformation == 0 
		and not player.divebomb 
		and not player.diving 
		and not player.bodyslam
		and not player.thenoise
			player.wallrunning = true
		end
	end
end, MT_PLAYER)

//NTTOP or NTOPP 3dish thing
addHook("PostThinkFrame", function()
	for player in players.iterate()
		if player.dish3
			player.mo.frame = $|FF_PAPERSPRITE
		end
	end
end)

addHook("PlayerThink", function(player)
if NoMoveset return end
	searchBlockmap("objects", function(refmobj, foundmobj)
		if foundmobj and foundmobj.valid
		and foundmobj.type == MT_ROSY
		and player.taunting
			foundmobj.dead = true
			foundmobj.state = S_ROSY_UNHAPPY
			foundmobj.momz = 20*FRACUNIT
			foundmobj.momx = 0
			foundmobj.momy = 0
			player.taunting = false
			player.tauntingtimer = 0
			S_StartSound(player.mo, sfx_poww)
			P_InstaThrust(player.mo, player.mo.angle, -7*FRACUNIT)
			player.mo.state = L_Choose(S_PLAY_SUPER_TRANS1, S_PLAY_ROLL, S_PLAY_STND)
		end
	end, player.mo, player.mo.x - 64*FRACUNIT, player.mo.x + 64*FRACUNIT, player.mo.y - 64*FRACUNIT, player.mo.y + 64*FRACUNIT)
end)

addHook("MobjThinker", function(mobj)
	if mobj and mobj.valid
	and mobj.dead
		mobj.state = S_ROSY_UNHAPPY
		mobj.flags = $ | MF_FLOAT | MF_NOCLIPHEIGHT | MF_NOCLIPTHING
	end
end, MT_ROSY)

addHook("PostThinkFrame", function(player)
if NoMoveset return end
	for player in players.iterate()
		if not player.thenoise return end
		if player.nredrawangle == nil
			player.nredrawangle = player.drawangle
		end
		if player.walllaunch or player.diving
			player.nredrawangle = player.drawangle + ANG20
			player.drawangle = player.nredrawangle
			if player.walllaunch
				if P_IsObjectOnGround(player.mo)
					player.walllaunch = false
				end
				if player.mo.momz > 0
					player.mo.state = S_PLAY_SPRING
				elseif player.mo.momz < 0
					player.mo.state = S_PLAY_FALL
				end
			end
			if player.diving
				player.mo.state = S_PLAY_FALL
			end
		end
	end
end)

addHook("JumpSpecial", function(player)
if NoMoveset return end
	if player.thenoise == false return end
	if player.walllaunch
		if not player.powers[pw_pushing]
		and not P_IsObjectOnGround(player.mo)
			P_DoJump(player, true)
			player.walllaunch = false
		end
	end
end)

addHook("PostThinkFrame", function()
if NoMoveset return end
	for player in players.iterate()
		if (player.powers[pw_shield] & SH_ARMAGEDDON)
			player.powers[pw_shield] = $ & ~SH_ARMAGEDDON
			player.supertaunt = true
		end
	end
end)

/*WARNING! IF YOU WANT NO SPOILERS, DONT GO PAST THIS POINT!











































*/
//Snick Behavior
addHook("MobjCollide", function(SNICK)
	for player in players.iterate
		if (SNICK.state == S_SNICK1) 
		or (SNICK.state == S_SNICK2)
			if (player.mo.state == S_PLAY_PAIN) 
			and (damaged == 0)
			or (player.powers[pw_flashing])
			and (damaged == 0)
				SNICK.state = S_SNICK
				S_StartSound(SNICK, sfx_ghosty)
				damaged = 1
			end
		end
	end
end, MT_SNICK)

addHook("MobjThinker", function(mo)
	for player in players.iterate
		if mo.valid
			if mo.state != S_SNICK
				if player.speed <= 15*FRACUNIT
					mo.state = S_SNICK2
				elseif player.speed > 15*FRACUNIT
					states[S_SNICK1].var1 = (player.speed - player.mo.momz/2) + 2*FRACUNIT
					mo.state = S_SNICK1
				end
			end
			if (player.pflags & PF_FINISHED)
				S_StartSound(nil, sfx_bedie2)
				P_RemoveMobj(mo)
				COM_BufInsertText(player, "tunes \"-default\"")
			end
			if player.playerstate == PST_DEAD
			and player.mo.state == S_PLAY_DEAD
				P_RemoveMobj(mo)
			end
			if mo.valid
				if mo.state == S_SNICK
					P_BossTargetPlayer(mo, true)
				end
			end
		end
	end
end, MT_SNICK)

//War Timer behavior

addHook("ThinkFrame", function()
	if not Lap3
		if wartimer
			if wartimer.isused
				wartimer.hide = true
				wartimer.isused = false
			end
		end
	else
		if wartimer
			if not wartimer.isused
				wartimer.hide = false
				wartimer.isused = true
				if mapheaderinfo[gamemap].warstarttime then
				wartimer.time = tonumber(mapheaderinfo[gamemap].warstarttime)*TICRATE
				else wartimer.time = 30*TICRATE end
			end
		end
	end
end)

//Keep combo

addHook("MobjLineCollide", function(mobj, line)
	if line and line.valid
	and mobj and mobj.valid
	and line.special == 348
		mobj.player.combo = 200
	end
end, MT_PLAYER)

//Welp, you made it to the end of here
//Hey uh, incase you didn't look in INIT yet, in there is a secret
//Make sure to uncomment it and use the command to find out more