//Pupnote: HOLY FUCK THIS SHIT IS OLD
//the og file, last edited 10/11/2020 (DD/MM/YYYY bih), was legit a proto build that wasn't supposed to be, seen
//But now it HAS been seen uhm, forget that file it was old and: old
//Anyways is was also: ass
//mood
//anyways
//I made this from half of that and half of brand new lua knowledge

rawset(_G, "cv_rocket_netgameampup", CV_RegisterVar({
	name = 'mp_29_allowrocketampup',
	defaultvalue = 0,
    flags = CV_NETVAR|CV_CHEAT,
    PossibleValue = {MIN = 0, MAX = 2},
}))

rawset(_G, "cv_rocket_groundbeamforce", CV_RegisterVar({
	name = 'mp_29_c3force',
	defaultvalue = 0,
    flags = CV_NETVAR,
    PossibleValue = {MIN = 0, MAX = 2},
}))

COM_AddCommand("mp_29_beam", function(p, zorua)
	if zorua == nil
		CONS_Printf(p, "This command allows you to change Rocket's grounded Custom 3 ability. It will toggle from V1's RocketBeam and V2's Uplink Command.")
		local val = p.rocketmetal_oldc3 and "RocketBeam" or "Uplink Command"
		if cv_rocket_groundbeamforce.value then val = ($.." (Server Forced)") end
		
		CONS_Printf(p, "Currently, yours is set to "..val)
		
	else
		if cv_rocket_groundbeamforce.value
			local val = p.rocketmetal_oldc3 and "RocketBeam" or "Uplink Command"
			
			CONS_Printf(p, "The server currently has Rocket's grounded Custom 3 set to "..val)
		else
			p.rocketmetal_oldc3 = not $ and true or false
			
			local val = p.rocketmetal_oldc3 and "RocketBeam" or "Uplink Command"
			
			CONS_Printf(p, "Rocket's grounded Custom 3 is now "..val)
		end
	end
end)

//Alright. Firstly I know, this WILL error if you swap it mid use. Eh but I'll allow it, I just won't be responsible for if it breaks by doing that lmao

addHook("PlayerThink", function(player)
	if player
		if player.rocketspin == nil then player.rocketspin = 0 end
		if player.rocketspinheld == nil then player.rocketspinheld = 0 end
		if (player.cmd.buttons & BT_SPIN) then player.rocketspinheld = true
		else 
			player.rocketspinheld = 0 
			player.sdashx = 0
			player.sdashy = 0
		end
		if player.rocket3held == nil then player.rocket3held = 0 end
		if player.rocket3cooldown == 0 then
		if (player.cmd.buttons & BT_CUSTOM3) then player.rocket3held = $1+1
		else player.rocket3held = 0 end
		else player.rocket3held = 0 end
		
		if player.rocket3cooldown == nil then player.rocket3cooldown = 0 end
		if player.rocket3cooldown > 0 then player.rocket3cooldown = $1-1 end
		if player.rocketzthrustready == nil then player.rocketzthrustready = 1 end
		if P_IsObjectOnGround(player.mo) and player.powers[pw_super] then player.rocketzthrustready = 2 end
		if P_IsObjectOnGround(player.mo) and not player.powers[pw_super] then player.rocketzthrustready = 1 end
		if player.diedlol == nil then player.diedlol = 0 end
		/* I was so dumb
			if player.mo.state == S_PLAY_DEAD then player.diedlol = 1 
			elseif player.mo.state == S_PLAY_DRWN then player.diedlol = 1
			else player.diedlol = 0 end
		*/
		if player.playerstate == PST_LIVE
			player.diedlol = 0
		else
			player.diedlol = 1
		end
		if player.rockertboostercooldown == nil then player.rockertboostercooldown = 0 end
		if player.rockertboostercooldown > 0 then player.rockertboostercooldown = $1-1 end
		if player.rockertboostercoolfail == nil then player.rockertboostercoolfail = 0 end
		if player.rockertboostercoolfail > 0 then player.rockertboostercoolfail = $1-1 end
		if player.rocketshootcharge == nil then player.rocketshootcharge = 0 end
		if player.rocketshootcharge > 0 then player.rocketshootcharge = $1-1 end
		if player.rocketshootfail == nil then player.rocketshootfail = 0 end
		if player.rocketshootfail > 0 then player.rocketshootfail = $1-1 end
		if player.rocketdrownmusic == nil then player.rocketdrownmusic = 0 end
		if player.rockettossheld == nil then player.rockettossheld = 0 end
		if not (player.cmd.buttons & BT_CUSTOM3) and player.mo.momx == 0 and player.mo.momy == 0 and not (player.cmd.buttons & BT_CUSTOM2) and not (player.cmd.buttons & BT_CUSTOM1) and not (player.cmd.buttons & BT_USE) and (player.cmd.buttons & BT_TOSSFLAG) then player.rockettossheld = $1+1
		else player.rockettossheld = 0 end
		
		if cv_rocket_groundbeamforce.value
			if cv_rocket_groundbeamforce.value == 1
				player.rocketmetal_oldc3 = false
			else
				player.rocketmetal_oldc3 = true
			end
		end
	end
end)//half of this sucks but i don#t wanna touch: it

//Unique Stuff

addHook("AbilitySpecial", function(player)
	//ZFlip
	if player.mo and player.mo.skin == "rocketmetal" and player.mo.valid and not player.exiting and player.diedlol == 0 //Never have things run on exit
		if not P_PlayerInPain(player) and not player.powers[pw_carry] and (player.pflags & PF_JUMPED) and not (player.pflags & PF_THOKKED) and not player.powers[pw_super]
			player.pflags = ($|PF_THOKKED & ~PF_SPINNING)
			S_StartSound(player.mo,sfx_s3k72)
			player.mo.momz = -$
			
			for i = 1,36
				local mo = player.mo
				local h = mo.height/2 * P_MobjFlip(mo)
				local fs = P_SpawnMobj(mo.x,mo.y,mo.z + h,MT_BOXSPARKLE)
				fs.colorized = true
				fs.angle = player.drawangle + (i*ANG10)
				fs.color = player.skincolor
				P_InstaThrust(fs,fs.angle,player.speed)
				//fs.momz = ?? dunno maybe i will, maybe i wont
			end
			P_SpawnThokMobj(player)
		end
	end
end)

addHook("SpinSpecial", function(player)
	//Thruster Charge
	if player.mo and player.mo.skin == "rocketmetal" and player.mo.valid and not player.exiting and player.diedlol == 0 //Never have things run on exit
		if not P_PlayerInPain(player) and not player.powers[pw_carry] and P_IsObjectOnGround(player.mo)//Yea you gotta check this
			//here we go.. ee
			if player.dashmode < 105
				if player.rocketspin
					if player.charability2 == CA2_SPINDASH //make sure we CAN spindash
						player.mo.state = S_PLAY_DASH
						player.rocketspin = min($+1,36)
						player.pflags = $|PF_STASIS|PF_STARTDASH & !PF_SPINNING
						player.drawangle = player.mo.angle
						return true 
					end
				else
					if player.charability2 == CA2_SPINDASH //make sure we CAN spindash
						player.mo.state = S_PLAY_DASH
						player.rocketspin = 1
						player.pflags = $|PF_STASIS|PF_STARTDASH & !PF_SPINNING
						player.drawangle = player.mo.angle
						S_StartSound(player.mo,sfx_buzz2)
						return true 
					end
				end
				player.dashmode = 0
			else
				if (player.pflags & PF_SPINNING) and not player.rocketspinheld
					player.pflags = ($ & !PF_SPINNING)
					player.mo.state = S_PLAY_DASH
					if player.speed < player.runspeed
						P_InstaThrust(player.mo,player.drawangle,player.runspeed)
					end
					S_StartSound(player.mo,sfx_s3k8c)
					return true
				end
			end
		end
	end
end)



addHook("JumpSpinSpecial", function(player)
	//ZThruster
	if player.mo and player.mo.skin == "rocketmetal" and player.mo.valid and not player.exiting and player.diedlol == 0 and not player.powers[pw_nocontrol] and not P_PlayerInPain(player) and not player.powers[pw_carry] //Never have things run on exit 
		if not (player.cmd.buttons & BT_CUSTOM1)//Hold C1 to allow shield usage
			if player.rocketzthrustready > 0
				//player.mo.momz = (player.mo.momz*2) Nu uh, no way! Let's make this different..
				
				if P_MobjFlip(player.mo)*player.mo.momz < player.mo.scale*5
					player.mo.momz = $*2 //Low upward momentum, or falling. Full ZThrust!
				elseif P_MobjFlip(player.mo)*player.mo.momz < player.mo.scale*10
					player.mo.momz = ($*3)/2 //Hey, we're rising alot, let's cut it out a bit.
				elseif P_MobjFlip(player.mo)*player.mo.momz < player.mo.scale*15
					player.mo.momz = ($*4)/3 //We're, really going up.. Kinda don't need this much, at all
				elseif P_MobjFlip(player.mo)*player.mo.momz < player.mo.scale*20
					player.mo.momz = ($*5)/4 //Starting to get diminishing returns...
				else
					player.mo.momz = ($*6)/5 //Alright, +20% is the cap...
				end
				
				
				player.rocketzthrustready = $1-1
				//Make superspark burst inverted of current momz
				for s = 1,20
					local rx = player.mo.x + (P_RandomRange(-48,48) * player.mo.scale)
					local ry = player.mo.y + (P_RandomRange(-48,48) * player.mo.scale)
					local h = player.mo.height/2 * P_MobjFlip(player.mo)
					local spk = P_SpawnMobj(rx,ry,player.mo.z + h,MT_SUPERSPARK)
					spk.colorized = true
					spk.momz = -(player.mo.momz)
					spk.momx = player.mo.momx + (P_RandomRange(-8,8) * player.mo.scale)
					spk.momy = player.mo.momy + (P_RandomRange(-8,8) * player.mo.scale)
					spk.color = player.skincolor
				end
				S_StartSound(player.mo,sfx_s3k45)
			end
		end
	end
end)

addHook("PlayerThink", function(player)
//Set Use Conditions
	if player.mo and player.mo.skin == "rocketmetal" and player.mo.valid and not player.exiting and player.diedlol == 0 //Never have things run on exit
	//RocketEngine
		if not P_IsObjectOnGround(player.mo) and not P_PlayerInPain(player) and not player.powers[pw_nocontrol]
			if not player.powers[pw_carry] and player.rocket3held and not player.rocket3cooldown	
			and not player.rocketlockon
				if player.rocket3held == 1
					if player.rings < 10 
						S_StartSound(nil,sfx_lose,player)
						player.rocket3cooldown = 30
					else
						if not player.powers[pw_super]
							player.rings = $1-10
							S_StartSound(nil,sfx_antiri,player)
						end
						S_StartSound(player.mo,sfx_drill1)
						player.mo.momz = 0
						player.mo.state = S_PLAY_DASH
					end
				elseif player.rocket3held == 32
					if player.rings >= 1
						player.rocket3held = 2
						if not player.powers[pw_super]
							player.rings = $1-1
							S_StartSoundAtVolume(nil,sfx_antiri,70,player)
						end
						player.mo.state = S_PLAY_DASH
					else
						S_StartSound(nil,sfx_lose,player)
						player.rocket3cooldown = 30
						player.mo.state = S_PLAY_PAIN
					end
				elseif player.rocket3held > 1 
					player.mo.momz = 0
					player.mo.state = S_PLAY_DASH
					if not (leveltime%4)
						S_StartSound(player.mo,sfx_drill2)
					end
					P_SpawnSkidDust(player,FRACUNIT*48)
					P_SpawnSkidDust(player,FRACUNIT*24)
					P_SpawnSkidDust(player,FRACUNIT*12)
				end
			end
		end
	//Rocketroll
		if player.rocketspin and (player.cmd.buttons & BT_SPIN)
			if player.rocketspin < 36
				local mo = player.mo
				local h = mo.height/4 * P_MobjFlip(mo)
				local drawura = P_SpawnMobj(mo.x,mo.y,mo.z + h, MT_THOK)
				drawura.state = S_FACESTABBERSPEAR
				drawura.sprite = SPR_STAB
				drawura.frame = A|FF_FULLBRIGHT
				drawura.scale = (FRACUNIT*2) - ((FRACUNIT*2/35)*player.rocketspin)
				drawura.tics = 2
				drawura.fuse = -1
				drawura.angle = player.drawangle + ANGLE_90
				drawura.colorized = true
				drawura.color = player.skincolor
				
				if player.rocketspin < 35
					if not player.sdashx
						player.sdashx = player.mo.momx
					else
						player.mo.momx = player.sdashx/player.rocketspin
					end
					if not player.sdashy
						player.sdashy = player.mo.momy
					else
						player.mo.momy = player.sdashy/player.rocketspin
					end
				end
			elseif player.rocketspin >= 35
				for zap = 1,5
					local rad = (player.mo.radius/FRACUNIT)
					local thok = P_SpawnMobj(player.mo.x + P_RandomRange(-rad, rad) * player.mo.scale, player.mo.y + P_RandomRange(-rad, rad) * player.mo.scale, player.mo.z + P_RandomRange(8,32) * player.mo.scale, MT_THOK)
					thok.flags = MF_NOBLOCKMAP|MF_NOGRAVITY|MF_NOCLIPHEIGHT
					thok.colorized = true
					if (leveltime%6)
						thok.color = player.skincolor
					else
						thok.color = ColorOpposite(player.skincolor)
					end
					thok.state = S_WATERZAP
					thok.scale = player.mo.scale/2
				end
				for i = 1,5
					local mo = player.mo
					local h = mo.height/2 * P_MobjFlip(mo)
					local cx = mo.x + (i*192)*cos(player.drawangle)
					local cy = mo.y + (i*192)*sin(player.drawangle)
					local drawura = P_SpawnMobj(cx,cy,mo.z, MT_THOK)//LMAO I used MT_DUMMY in testing, could you tell what game my focus is on
					drawura.state = S_FACESTABBERSPEAR
					drawura.sprite = SPR_STAB
					drawura.frame = A|FF_PAPERSPRITE|FF_FULLBRIGHT|FF_TRANS80
					if (displayplayer == player//Spying they cam
					or consoleplayer == player//Or, they're just me
					or (CBW_Battle and not CBW_Chaos))//Battle mode, it's a good idea if we can see this
						drawura.frame = A|FF_PAPERSPRITE|FF_FULLBRIGHT|FF_TRANS40
					end
					drawura.scale = mo.scale
					drawura.tics = 2
					drawura.fuse = -1
					drawura.angle = player.drawangle + ANGLE_90
					drawura.colorized = true
					drawura.color = player.skincolor
					
					
				end
				player.mo.momx = 0
				player.mo.momy = 0
			end
			if player.rocketspin == 35// and player.rocketspinheld i mean why tf would i even need to call to this how dumb can i get
				S_StartSound(player.mo,sfx_buzz1)
				player.rocketspin = 36 //To be safe
			end
		end
			//Release thinker
			
		if player.rocketspin 
			if player.powers[pw_nocontrol]
			or player.powers[pw_carry]
			or P_PlayerInPain(player)
				player.rocketspin = 0
				player.pflags = $ & !PF_STARTDASH
				S_StartSound(player.mo,sfx_cdfm35)
			end
		end
		
		if player.rocketspin and not (player.cmd.buttons & BT_SPIN)
			if P_IsObjectOnGround(player.mo) and not P_PlayerInPain(player) and not player.powers[pw_nocontrol] and not player.powers[pw_carry]
				if player.rocketspin < 35
					player.mo.state = S_PLAY_ROLL
					P_InstaThrust(player.mo,player.mo.angle,(player.rocketspin + 35) * FRACUNIT)
					player.rocketspin = 0
					player.pflags = $|PF_SPINNING & !PF_STARTDASH
					S_StartSound(player.mo,sfx_s3k79)
				end
			end
			if not P_PlayerInPain(player) and not player.powers[pw_nocontrol] and not player.powers[pw_carry] //Allow this in the air too - Jump to store charge
				if player.rocketspin >= 35
					player.mo.state = S_PLAY_DASH
					P_InstaThrust(player.mo,player.drawangle,80*FRACUNIT)
					player.rocketspin = 0
					player.pflags = $ & !PF_STARTDASH
					player.dashmode = 105
					player.mo.momz = 0
					S_StartSound(player.mo,sfx_s3k78)
				elseif not P_IsObjectOnGround(player.mo)
					player.rocketspin = 0
					player.pflags = $ & !PF_STARTDASH
					S_StartSound(player.mo,sfx_cdfm35)
				end
			end
		end
	//RocketZip
		if (player.cmd.buttons & BT_CUSTOM2) and not player.powers[pw_carry] and not player.rockertboostercooldown and not player.rockertboostercoolfail and not P_PlayerInPain(player) and not player.powers[pw_nocontrol]
			if player.rings < 15
				S_StartSound(nil,sfx_lose,player)
				player.rockertboostercoolfail = 30
			else
				player.rings = $1-15
				P_InstaThrust(player.mo,player.mo.angle,90*FRACUNIT)
				S_StartSound(player.mo,sfx_rail1)
				S_StartSound(player.mo,sfx_rail2)
				S_StartSoundAtVolume(nil,sfx_antiri,85,player)
				//Spawn 5 big dashrings
				if player.dashmode < 105
					player.dashmode = 105
					player.mo.state = S_PLAY_DASH
				end
				if not player.powers[pw_super]
					player.rockertboostercooldown = 70
				else 
					player.rockertboostercooldown = 15
				end
				player.pflags = ($ & ~PF_SPINNING & ~PF_JUMPED & ~PF_THOKKED)
			end
		end
		
		if player.rocketmetal_oldc3
		//RocketBeam CMD	
			if (player.cmd.buttons & BT_CUSTOM3) and not player.powers[pw_carry] and not player.rocketshootcharge and not player.rocketshootfail and not P_PlayerInPain(player) and P_IsObjectOnGround(player.mo) and not player.weapondelay and not player.powers[pw_nocontrol]
				if player.rings < 5
					S_StartSound(nil,sfx_lose,player)
					player.rocketshootfail = 30
				else
					player.rings = $1-5
					player.rocketanglock = player.mo.angle
					
					S_StartSound(player.mo,sfx_s3ka8)
					if not player.powers[pw_super]
						player.rocketshootcharge = 25
						player.weapondelay = 130
					else
						player.weapondelay = 35
						player.rocketshootcharge = 10
					end
				end
			end
		//RocketBeam Function
			if player.rocketshootcharge > 1
				player.drawangle = player.rocketanglock
				player.mo.momx = $/2
				player.mo.momy = $/2
				player.mo.state = S_PLAY_MELEE_LANDING
				for i = 1,5
					local rad = player.mo.radius/FRACUNIT
					local thok = P_SpawnMobj(player.mo.x + P_RandomRange(-rad, rad) * player.mo.scale, player.mo.y + P_RandomRange(-rad, rad) * player.mo.scale, player.mo.z, MT_THOK)
					thok.flags = MF_NOBLOCKMAP|MF_NOGRAVITY|MF_NOCLIPHEIGHT
					thok.colorized = true
					thok.color = player.skincolor
					thok.state = S_WATERZAP
					thok.scale = player.mo.scale
					thok.momz = (P_RandomRange(18, 35)) * player.mo.scale
				end
				for i = 1,10
					local mo = player.mo
					local h = mo.height/4 * P_MobjFlip(mo)
					local cx = mo.x + (i*128)*cos(player.drawangle)
					local cy = mo.y + (i*128)*sin(player.drawangle)
					local drawura = P_SpawnMobj(cx,cy,mo.z + h, MT_THOK)
					drawura.state = S_FACESTABBERSPEAR
					drawura.sprite = SPR_STAB
					drawura.frame = A|FF_PAPERSPRITE|FF_FULLBRIGHT|FF_TRANS40
					drawura.scale = (FRACUNIT/2)
					drawura.tics = 2
					drawura.angle = player.drawangle + ANGLE_90
					drawura.colorized = true
					drawura.color = player.skincolor
				end
				//shoot hoops for aiming
			end
			if player.rocketshootcharge == 1
				//Do stuff based on drawangle
				player.drawangle = player.rocketanglock
				player.mo.state = S_PLAY_FIRE
				for boostfactor = 95,105 //11 beams
					local mo = player.mo
					local h = mo.height/2 * P_MobjFlip(mo)
					local beam = P_SPMAngle(mo,MT_ROCKET,player.drawangle,0,MF2_SUPERFIRE|MF2_SCATTER)//why tf is it called a rocket it's a mf'n laser
					if beam and beam.valid //BTW SPM??? wHY is ALLOWAIM MEANT TO BE AN INTEGER??? ITS A TRUE FALSE CHECK BUT LOOKS FOR NUMBERS INSTEAD????? bruh
						//beam.target = mo SPM does this for us
						beam.colorized = true
						beam.fuse = 10*TICRATE
						//beam.angle = mo.angle SPM does this too
						beam.color = player.skincolor
						beam.scale = mo.scale
						beam.momx = ($*200)/boostfactor
						beam.momy = ($*200)/boostfactor
						
					end
				end
				S_StartSound(player.mo,sfx_s3k54)
			end
		else
		//Uplink Command	
			if (player.cmd.buttons & BT_CUSTOM3) and not player.powers[pw_carry] and not player.rocketlockon and not player.rocketshootfail and not P_PlayerInPain(player) and P_IsObjectOnGround(player.mo) and not player.weapondelay and not player.powers[pw_nocontrol]
				
				if player.rings < 5
					S_StartSound(nil,sfx_lose,player)
					player.rocketshootfail = 30
				else
					S_StartSound(player.mo,sfx_antiri)
					player.rings = max($-5, 0)
					player.rocketlockon = {}//Prepare
				end
				
			end
			
		//Uplink Command Function
		
			if player.rocketshootfail == 1
				S_StartSound(player.mo,sfx_addfil)
			end
			
			//CANCEL
				
			if player.rocketlockon
			and (player.powers[pw_nocontrol]
			or P_PlayerInPain(player)
			or player.powers[pw_carry])
				S_StartSound(player.mo,sfx_adderr)
				player.rocketshootfail = 35
				player.weapondelay = $ and $+10 or 10
				player.rocketlockon = nil
			end
			
			
			if player.rocketlockon
				
				
				//AIM
				
				local nearest = P_LookForEnemies(player,false,true)
				
				if nearest and nearest.valid and nearest.health
				
					if #player.rocketlockon
						local addthing = true
						
						
						for k, t in ipairs(player.rocketlockon)
							if t == nearest//We have them locked already
							or (CBW_Battle and nearest.type == MT_TARGETDUMMY and CBW_Chaos and not (gametyperules & GTR_RINGSLINGER))//At this point this is just for my own entertainment - though so is the whole of 29 here so I'm not too ashamed
								addthing = false
								break
							end
						end
						
						if addthing//We can add
							S_StartSound(player.mo,sfx_s3k89)
							table.insert(player.rocketlockon,nearest)
						end
					else//its. empty.      okay!
						if not (CBW_Battle and nearest.type == MT_TARGETDUMMY and CBW_Chaos and not (gametyperules & GTR_RINGSLINGER))
							S_StartSound(player.mo,sfx_s3k89)
							table.insert(player.rocketlockon,nearest)
						end
					end
					
				end
				
				
				//SHOW
				
				for k, t in ipairs(player.rocketlockon)
					if t and t.valid and t.health
						if t.player//Wait, I'm a player... LET ME KNOW
						or (CBW_Battle and t.type == MT_TARGETDUMMY)//i think this is how Battle allows plyrs to be targetable
							local mo = player.mo
							
							
							if not (leveltime%3)//Yeah this is my orbital deton code
								local targetspark = P_SpawnMobj(mo.x,mo.y,mo.z+(mo.height/2),MT_THUNDERCOIN_SPARK)
								targetspark.colorized = true
								targetspark.color = player.skincolor
								targetspark.momx = (t.x - mo.x)/10
								targetspark.momy = (t.y - mo.y)/10
								targetspark.momz = ((t.z + (t.height/2)) - targetspark.z)/10
								targetspark.fuse = 10
								targetspark.flags = $|MF_NOCLIP
							end
							
							local targetspark = P_SpawnMobj(t.x,t.y,t.z+(t.height/2),MT_THOK)
							targetspark.colorized = true
							targetspark.color = player.skincolor
							targetspark.momx = (mo.x - t.x)/15
							targetspark.momy = (mo.y - t.y)/15
							targetspark.momz = ((mo.z + (mo.height/2)) - targetspark.z)/15
							targetspark.tics = 3
							targetspark.flags = $|MF_NOCLIP
							targetspark.scale = FRACUNIT/4
							
							local warn = P_SpawnMobj(t.x,t.y,((t.z+t.height)+(FRACUNIT*16)),MT_THOK)
							warn.sprite = SPR_WHAT
							warn.frame = ((leveltime%2)+2)|FF_FULLBRIGHT
							warn.colorized = true
							warn.color = t.color
							warn.momx = t.momx
							warn.momy = t.momy
							warn.momz = t.momz
							warn.tics = 2
							warn.flags = $|MF_NOCLIP
							warn.scale = FRACUNIT/2
						
							
						end
						
						P_SpawnLockOn(player,t,S_LOCKON3)
						
					end
				end
				
				local mo = player.mo//so many calls to this, all so messy too
				local ang = mo.angle + ANGLE_315
				local dist = ((mo.radius*2)/3)/FRACUNIT
				
				local cx = mo.x + dist*cos(ang)//I've used this so many times for SRB2P anims, time to full circle it
				local cy = mo.y + dist*sin(ang)
				local cz = mo.z + (mo.height*5)/4
				
				local ini = P_SpawnMobj(cx,cy,cz,MT_THOK)//no not the file format
				ini.tics = 2
				ini.fuse = -1
				ini.sprite = SPR_TARG
				ini.momx = mo.momx
				ini.momy = mo.momy
				ini.momz = mo.momz
				ini.frame = (leveltime%12)/2|FF_FULLBRIGHT
				ini.colorized = true
				ini.color = player.skincolor
				ini.scale = mo.scale/3
				
				//FIRE
				
				if not (player.cmd.buttons & BT_CUSTOM3)//We already paid the fee, now pay the... fire.....yyyyyeah
					local mo = player.mo
					local aimreal = false
					for k, t in ipairs(player.rocketlockon)
						if t and t.valid and t.health
							
							aimreal = true
						
							//local sightline = P_SpawnMobj(t.x,t.y,t.subsector.sector.ceilingheight - FRACUNIT*10,MT_NULL)
							//sightline.fuse = 2
							
							if player.powers[pw_super]//just explode them
							
							else
								if (t.subsector.sector.ceilingpic == "F_SKY1"
								and t.subsector.sector.ceilingheight == t.ceilingz)//We can call down an orbital attack
								and not (R_PointToDist2(mo.x,mo.y,t.x,t.y) <= mo.scale*256
								and P_CheckSight(mo,t))//And uh they're far enough away from us with line of sight
								
									
									local beam = P_SpawnPointMissile(mo,t.x,t.y,t.subsector.sector.ceilingheight - FRACUNIT*64,MT_JETTBULLET,t.x,t.y,t.subsector.sector.ceilingheight - FRACUNIT*32)
									if beam
									and beam.valid
										beam.scale = FRACUNIT
										beam.colorized = true
										beam.sprite = SPR_ENRG
										beam.height = 30*FRACUNIT
										beam.frame = FF_FULLBRIGHT
										beam.spritexscale = FRACUNIT/2
										beam.spriteyscale = FRACUNIT
										P_ColorTeamMissile(beam,player)
										beam.color = $ or player.skincolor
										beam.momz = (t.z - beam.z)/30
										if not ((CBW_Battle and not CBW_Chaos)//Battle, without chaos loaded because    if you know you know
										or (gametyperules & GTR_RINGSLINGER))//Or we're just playing with shooty
											beam.momz = (t.z - beam.z)/5
										end
										beam.momx = 0
										beam.momy = 0
									end
										
								else//LOCAL
									
									
									local beam = P_SpawnMissile(mo,t,MT_ROCKET)//why even is it called MT_ROCKET its a laser
									if beam//i forgot i said that already lol
									and beam.valid
										beam.scale = mo.scale
										beam.colorized = true
										P_ColorTeamMissile(beam,player)
										beam.color = $ or player.skincolor
										if not ((CBW_Battle and not CBW_Chaos)
										or (gametyperules & GTR_RINGSLINGER))
											beam.momx = ($*5)/2
											beam.momy = ($*5)/2
											beam.momz = ($*5)/2
										end
									end
								end
							end
						end
					end
					
					if aimreal
						local delay = 350
						
						if (CBW_Battle and not CBW_Chaos)
							delay = $*3
						elseif not (gametyperules & GTR_RINGSLINGER)
							delay = $/2 
						end
						
						player.weapondelay = $ and $+70 or 70
						player.rocketshootfail = delay//Allow some weapon usage but delay this one specifically, since this should keep after death
						
						S_StartSound(player.mo,sfx_s3ka8)
						
					else//ehh let cooldown cool down
						player.weapondelay = $ and $+10 or 10
						player.rocketshootfail = 30
						S_StartSound(player.mo,sfx_notadd)
					end
					
					player.rocketlockon = nil
				end
			end
		end	
		
	//AmpUp
		if not player.powers[pw_carry] and player.rockettossheld and not P_PlayerInPain(player) and P_IsObjectOnGround(player.mo) and not player.powers[pw_flashing] and not player.powers[pw_nocontrol]
			if not netgame
			or (netgame and cv_rocket_netgameampup.value == 1 and player == server)
			or (netgame and cv_rocket_netgameampup.value == 2)
					if not player.mo.momz == 0
						player.rockettossheld = 0
					else
						if player.rockettossheld == 1
							S_StartSound(player.mo,sfx_3db16)
						end
						if player.powers[pw_super]
							if player.rockettossheld == 36
								S_StartSound(player.mo,sfx_bkpoof,everyone)
								player.rockettossheld = 1
								P_NukeEnemies(player.mo,player.mo,1024*FRACUNIT)
							end
						else
							if player.rockettossheld == 16
								if player.rings < 9999
									player.rings = $1+1
									S_StartSoundAtVolume(nil,sfx_itemup,90,player)
								end
								S_StartSound(player.mo,sfx_s3kcas)
								player.rockettossheld = 1
							end
						end
						player.mo.state = S_PLAY_SPRING
						for i = 1,5
							local rndval1 = -48
							local rndval2 = 48
							local rndval3 = -48
							local rndval4 = 48
							//why the fuck did i do this
							local thok = P_SpawnMobj(player.mo.x + P_RandomRange(rndval1, rndval2) * player.mo.scale, player.mo.y + P_RandomRange(rndval3, rndval4) * player.mo.scale, player.mo.z, MT_THOK)
							thok.flags = MF_NOBLOCKMAP|MF_NOGRAVITY|MF_NOCLIPHEIGHT
							thok.colorized = true
							thok.color = SKINCOLOR_TEAL
							thok.state = S_WATERZAP
							thok.scale = player.mo.scale
							thok.momz = (P_RandomRange(18, 35)) * player.mo.scale
						end
						player.mo.momx = 0
						player.mo.momy = 0
					end
			end
		end
		//Turbine Engine
		if player.powers[pw_super] and player.dashmode < 105
			player.normalspeed = skins.rocketmetal.normalspeed*2
			player.acceleration = skins.rocketmetal.acceleration*3/2
			player.accelstart = skins.rocketmetal.accelstart*2
		elseif player.dashmode < 105
			player.normalspeed = skins.rocketmetal.normalspeed
			player.acceleration = skins.rocketmetal.acceleration
			player.accelstart = skins.rocketmetal.accelstart
		end
		//Rocket Turbine
		if player.dashmode > 105 and not (player.pflags & PF_STARTDASH)
			if player.mo.state == S_PLAY_DASH
				for zap = 1,10
					local thok = P_SpawnMobj(player.mo.x + P_RandomRange(-64, 64) * player.mo.scale, player.mo.y + P_RandomRange(-64, 64) * player.mo.scale, player.mo.z + P_RandomRange(8, 48) * player.mo.scale, MT_THOK)
					thok.flags = MF_NOBLOCKMAP|MF_NOGRAVITY|MF_NOCLIPHEIGHT
					thok.colorized = true
					if (leveltime%3)
						thok.color = player.skincolor
					else
						thok.color = ColorOpposite(player.skincolor)
					end
					thok.state = S_WATERZAP
					thok.scale = player.mo.scale 
				end
			end
			
		local trans = {FF_TRANS90,FF_TRANS80,FF_TRANS70,FF_TRANS60,FF_TRANS60,FF_TRANS40,FF_TRANS30,FF_TRANS20,FF_TRANS10,FF_FULLBRIGHT}
		local cx = player.mo.x + ((player.speed * 3)/FRACUNIT)*cos(player.drawangle)
		local cy = player.mo.y + ((player.speed * 3)/FRACUNIT)*sin(player.drawangle)
			if not player.rocketspin
				local mo = player.mo
				local h = mo.height/2 * P_MobjFlip(mo)
				local drawura = P_SpawnMobj(cx,cy,mo.z + h, MT_GHOST)
				drawura.state = S_FACESTABBERSPEAR
				drawura.sprite = SPR_STAB
				drawura.frame = A
				drawura.scale = 1
				drawura.destscale = FRACUNIT*3
				drawura.scalespeed = (FRACUNIT*3)/25
				drawura.tics = -1
				drawura.fuse = player.powers[pw_super] and 25 or 10
				drawura.angle = player.drawangle + ANGLE_90
				drawura.colorized = true
				drawura.color = player.powers[pw_super] and mo.color or player.skincolor
			end
		end
		
		//Kinetic Crash
		if player.dashmode > 105
		or player.powers[pw_super]
			player.charflags = $|SF_CANBUSTWALLS
		else
			player.charflags = ($ & !SF_CANBUSTWALLS)
		end
		
		//Shield on/off
		if not (player.cmd.buttons & BT_CUSTOM1)
		or player.powers[pw_super]
			player.charflags = $|SF_NOSHIELDABILITY
		else
			player.charflags = ($ & !SF_NOSHIELDABILITY)
		end
		
		//DSZ2 moment
			
		if not P_PlayerInPain(player) and not player.powers[pw_carry] and not player.powers[pw_nocontrol] and P_IsObjectOnGround(player.mo) and (G_BuildMapName(mapnum) == "MAP08")
			local mo = player.mo
			if (mo.x >= 20352*FRACUNIT and mo.x <= 20416*FRACUNIT
			and mo.y >= -4016*FRACUNIT and mo.y <= -3920 * FRACUNIT)
			
			or (mo.x >= 15904*FRACUNIT and mo.x <= 15968*FRACUNIT
			and mo.y >= 5008*FRACUNIT and mo.y <= 5104 * FRACUNIT)
			
				if (player.cmd.buttons & BT_SPIN)
					player.pflags = $|PF_STARTDASH
				end
			
			end
		end
		
//Super Run
		if player.superrunmusic and player.superrunmusic ~= 0
			CONS_Printf(player, "")
			CONS_Printf(player, "Rocket cannot change musics for Super Run! (Setting is now 0)")
			CONS_Printf(player, "")
			player.superrunmusic = 0
		end
		if player.multitype and player.multitype ~= 0
			CONS_Printf(player, "")
			CONS_Printf(player, "Rocket has a different main ability when Super! (Setting is now 0)")
			CONS_Printf(player, "")
			player.multitype = 0
		end
		if player.boosttype and player.boosttype ~= 0
			CONS_Printf(player, "")
			CONS_Printf(player, "Rocket has a different main ability when Super! (Setting is now 0)")
			CONS_Printf(player, "")
			player.boosttype = 0
		end
//EndHook		
	end
end)

//Dash DMG nullification
addHook("ShouldDamage", function(target, inflictor, source, damage, damagetype)
	if target.skin == "rocketmetal" and target.player.dashmode > 105 and not (target.player.pflags & PF_STARTDASH) and target.state == S_PLAY_DASH
		if not (damagetype & DMG_DEATHMASK)
			return false
		end
	end
end, MT_PLAYER)