//If you want to disable the use of HMS, there's an app for everything!
//Also creating some variables for use with the anti-HMS-to-super switch system.

//This lets you become HMS anytime by pressing Custom 3, which will be our dedicated transformation button.

addHook("MobjThinker", function(s)
if not s.player
return end
local p = s.player
		local wind = s.hmstor
		local wind2 = s.hmstor2
			while (wind and wind.valid)
				P_TeleportMove(wind, wind.x+40*FixedMul(s.scale, cos(wind.angle)), wind.y+40*FixedMul(s.scale, sin(wind.angle)), wind.z)
				wind.angle = $+(ANG1*5)
				wind.frame = $|FF_FULLBRIGHT
				wind = wind.tracer
			end
			while (wind2 and wind2.valid)
				P_TeleportMove(wind2, wind2.x-40*FixedMul(s.scale, cos(wind2.angle)), wind2.y-40*FixedMul(s.scale, sin(wind2.angle)), wind2.z)
				wind2.angle = $-(ANG1*5)
				wind2.frame = $|FF_FULLBRIGHT
				wind2 = wind2.tracer
			end
		if (p.cmd.buttons & BT_CUSTOM3)
			p.transformdown = $+1
		elseif p.transformdown
			p.transformdown = 0
		end
		if p.superinvulnerable
			if not p.mysticsuper
				p.superinvulnerable = nil
				if (p.powers[pw_invulnerability] > 7771 and p.powers[pw_invulnerability] < 7799)
				p.powers[pw_invulnerability] = 1
				end
			end
		end
		if p.hms_gravburstcd
		p.hms_gravburstcd = $-1
		end
		if p.hms_explosion
			p.hms_explosion = $-1
		end
		if p.hms_instamovew
		p.hms_instamovew = $-1
		end
		if s 
			if s.eyesareuponyou
			s.eyesareuponyou = $-1
			end
			if s.hmsfearmessage
			s.hmsfearmessage = $-1
			end
		end
		if p.hfear and not p.hypermysticsonic
			for sector in sectors.iterate
				sector.lightlevel = ($+31)
			end
			for z in players.iterate
				z.hmshascome = nil
				P_FlashPal(z, PAL_MIXUP, 3)
				if not z.nohmstheme
					COM_BufInsertText(z, "tunes -default")
					P_RestoreMusic(z)
				end
			end
			S_StartSound(nil, sfx_s3k66)
			P_SetupLevelSky(p.hfear)
			p.hfear = nil
		end
		if G_GametypeHasSpectators() and s
			if not (s.skin == "sms")
				if not p.notsms
				p.notsms = true
				end
			elseif p.notsms
				p.notsms = false
				if (p.rings > 100)
				p.rings = 100
				end
			end
		end
		if (s and s.skin == "sms")
			if G_GametypeHasSpectators()
				if p.hmswarn
					if not (p.hmswarn == 1)
						p.hmswarn = $-1
					end
					if (p.hmswarn == 1) and (p.rings < 200)
						p.hmswarn = 0
					end
				elseif (p.rings > 199) and not p.hypermysticsonic
				S_StartSound(nil, sfx_litng4)
				print("\x85 -"+p.ctfnamecolor+"\x85 has collected 200 rings! Be careful!")
				p.hmswarn = 825
				end
				if p.hypermysticsonic
					if p.gotflag //No flag for you.
					P_PlayerFlagBurst(p)
					end
					s.hmgodmticket = true
				end
			end		
			if (gametype == GT_RACE) or G_TagGametype()
				if (p.smsnoracegame and p.smsnoracegame == 1)
				p.powers[pw_carry] = CR_BRAKGOOP 
				end
				if ((p.smsnoracegame and p.smsnoracegame == 2) or (p.pflags & PF_GAMETYPEOVER))
				and p.mysticsuper and not G_TagGametype() //Mystic super cancel
				p.rings = 0
				end
				
			end
			if (p.cmd.buttons & BT_CUSTOM3)
			and not (p.cmd.buttons & BT_JUMP)
				and ((p.pflags & PF_JUMPED) or p.hometrickanim)
				and ( (((p.rings > 49) and G_PlatformGametype()) and not s.battlemodsms) or ((p.rings > 299) and (s.battlemodsms or G_GametypeHasSpectators())) )
				and not p.powers[pw_super] and not p.hypermysticsonic
				and not (p.transformdown > 1) //Custom 3 wasn't held, right?
				and not p.sms_ringburstfly
				and not p.sms_stompanim
				and not P_IsObjectOnGround(s)
				and not p.exiting //This would glitch out
				and not p.homing
				and not p.powers[pw_carry]
				and not (p.pflags & (PF_GAMETYPEOVER|PF_STASIS))
					A_TOGOEVENFURTHERBEYOND(s) //Become Hyper Mystic Sonic!
			end
			if ((s.state >= S_HMSTRANSFORM1) and (s.state <= S_HMSTRANSFORM9))
				p.powers[pw_nocontrol] = 2
				s.momx = 0
				s.momy = 0
				s.momz = 0
				if not p.powers[pw_carry]
				p.pflags = $|PF_JUMPED & ~PF_SPINNING & ~PF_NOJUMPDAMAGE
				end
			end
			if (s.state == S_HMSTRANSFORM8)
			and (s.tics == 1)
				P_FlashPal(p, PAL_MIXUP, 6)
				A_SMSquake(s, 40*FRACUNIT, 24, 6922)
				P_SpawnMobj(s.x+FixedMul(-2*FRACUNIT, cos(s.angle)), s.y+FixedMul(-2*FRACUNIT, sin(s.angle)), s.z-5*FRACUNIT, MT_BURSTWAVE)
				p.burstlightspawn = P_SpawnMobj(s.x, s.y, s.z-12*FRACUNIT, MT_BURSTLIGHT)
				p.burstlightspawn.color = SKINCOLOR_YELLOW
			end

			//Untransform from HMS at anytime by pressing Custom 3 on the ground.
			//Also, automaticly untransform when time's over in any contest.

			if (p.cmd.buttons & BT_CUSTOM3)
			and (p.cmd.buttons & BT_USE)
			and (p.cmd.forwardmove < 0)
			and (p.speed < 3*FRACUNIT)
			and P_IsObjectOnGround(s)
			and not p.hmsrushactive and not (s.player.dashspeed > 499*FRACUNIT)
				if (p.hypermysticsonic and not (s.state >= S_HMSTRANSFORM1 and s.state <= S_HMSTRANSFORM9))
				or p.sms_transformstate
				A_TOGOBACKTOTHEWAYYOUWERE(s, nil)
				end
			end
		end

		//This transforms you straight from HMS down to Sonic.
		//The ONLY reason this works is because of the order, so don't mess with it.

			if p.sms_transformstate
			and p.hypermysticsonictstate
			and not p.hypermysticsonic
				P_SpawnGhostMobj(s)
				s.state = S_PLAY_FALL
					if p.presmsskin
					R_SetPlayerSkin(p, p.presmsskin)
					s.skin = p.presmsskin					
					else
					R_SetPlayerSkin(p, "sonic")
					s.skin = "sonic"
					end
				s.color = p.sms_originalcolor
				p.skincolor = p.sms_originalcolor
				p.hypermysticsonic = 0
				p.sms_transformstate = 0
					if not (p.powers[pw_shield] & SH_FIREFLOWER)
					and not ((mariomode) and p.powers[pw_invulnerability])
						s.color = p.sms_originalcolor
					else
						s.color = SKINCOLOR_WHITE
					end
					p.skincolor = p.sms_originalcolor
					
					if not p.nohmstheme
					COM_BufInsertText(p, "tunes -default")
					end
			end
			if p.hypermysticsonictstate
				if not p.hypermysticsonic
				or not (p.sms_transformstate)
				p.hypermysticsonictstate = false
				end
			end
			if (s and s.skin == "sms")
			and p.hypermysticsonic
			p.hypermysticsonic = $+1
					if s.hmsidleanim == nil or (s.hmsidleanim > 23) //HMS idle animation timer.
					s.hmsidleanim = 0
					else
					s.hmsidleanim = $+1
						if (p.speed > FixedMul(6*FRACUNIT, s.scale)) or s.momz < -5*FRACUNIT or s.momz > 5*FRACUNIT
						s.hmsidleanim = $+1
						end
						if (p.speed > FixedMul(18*FRACUNIT, s.scale)) or s.momz < -18*FRACUNIT or s.momz > 18*FRACUNIT
						s.hmsidleanim = $+1
							if (s.hmsidleanim > 23)
							s.hmsidleanim = 0
							end
						end
					end
					if s.beingsucked
						for z in players.iterate
							if z.mo and z.mo.skin == "kirby" and z.kvars.suckstate
							and ((FixedHypot(FixedHypot(z.mo.x-s.x, z.mo.y-s.y), z.mo.z-s.z)) <= 500*FRACUNIT)
							P_FlashPal(z, PAL_MIXUP, 5)
							A_SMSquake(z.mo, 62*FRACUNIT, 14, 2)
							P_SpawnMobj(z.mo.x, z.mo.y, z.mo.z, MT_BURSTWAVE)
							S_StartSound(z.mo, sfx_nerf)
							z.powers[pw_nocontrol] = 5
							P_DoPlayerPain(z)
							z.kvars.suckstate = 0
							P_KillMobj(z.mo)
								if s.oldflags and not (s.oldflags & MF_NOCLIPHEIGHT)
								s.flags = s.oldflags
								end
							end
						end
					end
					if s.silv_grabbed
					  if s.silv_grabbed.valid and s.silv_grabbed.mo and (s.silv_grabbed.mo.type == MT_PLAYER)
						s.silv_grabbedhms = s.silv_grabbed //You just made....a big mistake.
						s.silv_grabbedhms.powers[pw_nocontrol] = 30 
						if s.silv_grabbedhms.powers[pw_invulnerability]
						s.silv_grabbedhms.powers[pw_invulnerability] = 0 
						P_RestoreMusic(s.silv_grabbedhms)
						end
						P_RemoveShield(s.silv_grabbedhms)
						s.silv_grabbedhms.losstime = 2000
						P_FlashPal(s.silv_grabbedhms, PAL_MIXUP, 5)
						P_DamageMobj(s.silv_grabbedhms.mo, s, s)
						P_SpawnMobj(s.silv_grabbedhms.mo.x, s.silv_grabbedhms.mo.y, s.silv_grabbedhms.mo.z, MT_BURSTWAVE)
						P_InstaThrust(s.silv_grabbedhms.mo, s.angle, 125*FRACUNIT)
						S_StartSound(s.silv_grabbedhms.mo, sfx_nerf)
						if s.silv_grabbedhms.mo.health
							P_SetObjectMomZ(s.silv_grabbedhms.mo, 12*FRACUNIT)
							s.silv_grabbedhms.mo.state = S_PLAY_PAIN
							s.silv_grabbedhms.hmsbpunch = true
						end
						if s.silv_grabbedhms.mo.skin == "silver" //How often is this NOT going to be Silver...?
						S_StartSound(s, sfx_silrip)
						S_StartSound(s.silv_grabbedhms.mo, sfx_silrip)
						end
					  end
					end
					if not s.hmslivesc or (s.hmslivesc >= SKINCOLOR_SUPERTAN1)
					s.hmslivesc = SKINCOLOR_SUPERSILVER2
					else
					s.hmslivesc = $+5
					end
					//Shiny HUD section
					if s.tniy == nil or (s.tniy < -7*FRACUNIT) s.tnix = (P_RandomRange(0,30)*FRACUNIT) s.tniy = (P_RandomRange(2,12)*FRACUNIT)
					else s.tniy = $-15355
					end
					if s.tniy2 == nil or (s.tniy2 < -7*FRACUNIT) s.tnix2 = (P_RandomRange(0,30)*FRACUNIT) s.tniy2 = (P_RandomRange(2,12)*FRACUNIT)
					else s.tniy2 = $-15800
					end
					if s.tniy3 == nil or (s.tniy3 < -7*FRACUNIT) s.tnix3 = (P_RandomRange(0,30)*FRACUNIT) s.tniy3 = (P_RandomRange(2,12)*FRACUNIT)
					else s.tniy3 = $-16300
					end
					if s.tniy4 == nil or (s.tniy4 < -7*FRACUNIT) s.tnix4 = (P_RandomRange(0,30)*FRACUNIT) s.tniy4 = (P_RandomRange(2,12)*FRACUNIT)
					else s.tniy4 = $-15900
					end
					if s.tniy5 == nil or (s.tniy5 < -7*FRACUNIT) s.tnix5 = (P_RandomRange(0,30)*FRACUNIT) s.tniy5 = (P_RandomRange(2,12)*FRACUNIT)
					else s.tniy5 = $-15470
					end
					if s.tniy6 == nil or (s.tniy6 < -7*FRACUNIT) s.tnix6 = (P_RandomRange(0,30)*FRACUNIT) s.tniy6 = (P_RandomRange(2,12)*FRACUNIT)
					else s.tniy6 = $-15470
					end
					if s.hmsmpos
					s.hmsmpos = $+30
						if (s.hmsmpos > 107700) //89000 for old song.
						s.hmsmpos = 1
						end
					end
					if p.powers[pw_shield] //HMS consumes shields to gain 5 rings
						if not (p.powers[pw_shield] == SH_PINK or p.powers[pw_shield] == SH_PITY)
						P_GivePlayerRings(p, 5)
						s.hmsshieldconsume = 18
						end
						P_RemoveShield(p)
						p.powers[pw_shield] = 0
					end
					if not p.rings or p.exiting or (p.powers[pw_carry] == CR_NIGHTSMODE) //No Hyper Mystic NiGHTS
					A_TOGOBACKTOTHEWAYYOUWERE(s, true, true)
					end
				if (p.sms_transformstate)
				p.hypermysticsonictstate = true
				else
				p.hypermysticsonictstate = false
				end
			end

			//Disables switching from HMS to "super" characters.
			//Don't switch the order of this, it won't work.

			if (p.hypermysticsonic or p.hypermysticsonictstate) //No longer Hyper Mystic? Then turn off immortality.
				if not (s and s.skin == "sms")
				p.pflags = $ & ~PF_GODMODE
				s.flags = $|MF_SHOOTABLE
				p.hypermysticsonic = 0
				p.ffdelaycs = 3 
					if not p.nohmstheme
					COM_BufInsertText(p, "tunes -default")
					end
				end
			end

//This gives HMS a godly aura, makes him truely invincible, deletes point combos, and drains double rings in the
//final version. Also changes stats. All of these have in common that they're always in effect as long as you're HMS.

	if (s and s.skin == "sms")
		if p.hypermysticsonic
			//Most of this hook is dedicated to Hyper Mystic Sonic, who plays almost entirely differently from SMS.
				p.hms_drain = $+1		
				if not s.sqaang or (s.sqaang >= 359)
				s.sqaang = 1
				else
				s.sqaang = $+1
				end
				if (p.speed < FRACUNIT) or (s.eflags & MFE_UNDERWATER)
				p.thrustfactor = 9 //Tweak accel a little.
				end
				if s.battlemodsms
					if p.hms_drain == 1
					and CBW_Battle and CBW_Battle.ControlPoint and (CBW_Battle.ControlPoint.LeadCapAmt or CBW_Battle.ControlPoint.LeadCapPlr)
					S_StartSound(s, sfx_antiri, p)
					P_GivePlayerRings(p, -1) //Drain MORE rings when control points are being captured!
					end
					if p.captureamount
						if s.lastcaptureamounthms and (s.lastcaptureamounthms < p.captureamount)
						p.captureamount = $-1 //Half the speed of capture as HMS, on top of the SMS slowdown.
						end			
					s.lastcaptureamounthms = p.captureamount
					end
				end

				if (leveltime % (TICRATE/7) == 0)
				s.hmsis = P_SpawnMobj(s.x, s.y, s.z, MT_IVSP)
					s.hmsis.eflags = s.eflags
					if (s.eflags & MFE_VERTICALFLIP)
					s.hmsis.z = $-FixedMul(36*FRACUNIT, s.scale) 
					end
					if (p.speed < 2*FRACUNIT)
					s.hmsis.scale = s.scale*3/2
					else
					s.hmsis.scale = s.scale
					end
				end
			/*	if not P_RandomRange(0,20) --Ahh, it was worth experimenting
					for d = 0,15
					P_SpawnParaloop(s.x, s.y, s.z+s.height/2, P_RandomRange(40,130)*FRACUNIT, 4, MT_NIGHTSPARKLE, d**ANGLE_22h, S_SMSTSPARK1, true)
					end
				end */
				P_ResetScore(p) //Needed to prevent infinite lives
				p.maxdash = 500*FRACUNIT
				p.jumpfactor = 133469 //Back in my day, we didn't have fancy "*FRACUNIT" variables.
				p.accelstart = 140

				if p.timestop
				p.timestop = false
				end

				if not (p.pflags & (PF_GODMODE|PF_GAMETYPEOVER))
				p.pflags = $|PF_GODMODE //Though already unkillable without godmode, it's still added to HMS to negate some weird effects
				p.hmsgodmode = true
				end		

				if s.hypermysticdash and not p.dashspeed -- When you charged up a full HMS spindash, get 3 seconds of ridiculous speed potentially ignoring colissions
					if not (p.pflags & (PF_JUMPED|PF_STARTDASH)) and not p.powers[pw_carry] and not p.cmd.buttons
					and ((p.speed > FixedMul(4*FRACUNIT, s.scale)) or p.cmd.angleturn or p.cmd.sidemove)
					and not ((p.cmd.forwardmove < 0) and not (p.pflags & PF_ANALOGMODE)) and not p.skidtime
						if p.cmd.angleturn or p.cmd.sidemove
							P_InstaThrust(s, s.angle, 500*FRACUNIT)
							if P_IsObjectOnGround(s)
							p.pflags = $|PF_SPINNING
							end
						end
						s.hypermysticdash = $-1
					else
						if ((p.cmd.forwardmove < 0) and not (p.pflags & PF_ANALOGMODE))
						p.pflags = $ & ~PF_SPINNING
						s.momx = $/3
						s.momy = $/3
						end
					s.hypermysticdash = 0
					end
				end

				if not (p.pflags & PF_SPINNING) //He gets cooler stuff when he's spinning.
				and not (s.state == S_HMSCOMETHAYMAKER1 or s.state == S_HMSCOMETHAYMAKER2)
				and not p.sms_comethaymaker and not p.starthmscombo
				P_RadiusAttack(s, s, 192*FRACUNIT)
				end
				
			//Add a little extra flair to the transformation!
				
				if (s.state >= S_HMSTRANSFORM1 and s.state <= S_HMSTRANSFORM9)
				s.boostpass = 0
					if (p.hypermysticsonic > 2) and (p.hypermysticsonic % 5 == 0)
						if (s.z < s.floorz+400*FRACUNIT) and not (p.smsgraphix and p.smsgraphix == 2)
						s.wvspwn = P_SpawnMobj(s.x, s.y, s.z, MT_THOK)
						s.wvspwn.z = s.floorz+1
						s.wvspwn.fuse = 1
						s.wvspwn.color = s.color
						s.wvspwn.sprite = SPR_NULL
						A_SMSSTOMPQUAKE(s.wvspwn, 45, P_RandomRange(5,10), p.hypermysticsonic*FRACUNIT, 0, s.sqaang*ANG1, 0, 20, SKINCOLOR_SUPERRED4)
						A_SMSSTOMPQUAKE(s.wvspwn, 85, P_RandomRange(7,12), p.hypermysticsonic*FRACUNIT, 0, ANG10+s.sqaang*ANG1, 0, 20)
						A_SMSSTOMPQUAKE(s.wvspwn, 125, P_RandomRange(8,14), (p.hypermysticsonic*2)*FRACUNIT, 0, ANG20+s.sqaang*ANG1, 0, 20)
						A_SMSSTOMPQUAKE(s.wvspwn, 165, P_RandomRange(10,16), (p.hypermysticsonic*3)*FRACUNIT, FRACUNIT*2, ANG30+s.sqaang*ANG1, 0, 20, SKINCOLOR_SUPERSILVER4)
						end
						if (s.state > S_HMSTRANSFORM7)
						/*	for f = 0,24 --SRB2 can't handle this...yet.
								P_SpawnParaloop(s.x, s.y, s.z, 80*FRACUNIT, 8, MT_NIGHTSPARKLE, d*(ANG20*2), S_SMSTSPARK1, true)
								if (s.z < s.floorz+400*FRACUNIT)						
								s.elofc = P_SpawnMobj(s.x+P_RandomRange(-250, 250)*FRACUNIT, s.y+P_RandomRange(-250, 250)*FRACUNIT, s.z, MT_HMSWAVEAURA)
									if s.elofc and s.elofc.valid
									s.elofc.eflags = s.eflags
									s.elofc.state = S_HMSWAVEAURAG
									s.elofc.target = s
										if (s.eflags & MFE_VERTICALFLIP)
											s.elofc.z = s.elofc.ceilingz
										else
											s.elofc.z = s.elofc.floorz						
										end
									end
								end
							end */
						
						
						A_SMSSTOMPQUAKE(s, P_RandomRange(40,90), P_RandomRange(7,12), P_RandomRange(-8,8)*FRACUNIT, 13*FRACUNIT, s.sqaang*ANG1, P_RandomRange(-25, 15)*FRACUNIT, 14)
						A_SMSSTOMPQUAKE(s, P_RandomRange(30,85), P_RandomRange(7,12), -3*FRACUNIT, P_RandomRange(5, 35)*FRACUNIT, s.sqaang*-ANG1, P_RandomRange(-10,30)*FRACUNIT, 26)
						A_SMSSTOMPQUAKE(s, P_RandomRange(50, 110), P_RandomRange(8,14), 0, 6*FRACUNIT, ANG20+s.sqaang*ANG1, P_RandomRange(-44, 2)*FRACUNIT, 14)
								if (s.state == S_HMSTRANSFORM9) and s.tics == 1
								s.nbar = P_SpawnMobj(s.x, s.y, s.z+s.height/2, MT_THOK)
								s.nbar.sprite = SPR_AURA
								s.nbar.frame = S|TR_TRANS80|FF_FULLBRIGHT
								s.nbar.color = SKINCOLOR_SUPERGOLD3
								s.nbar.scale = s.scale*2
								s.nbar.momz = 24*FRACUNIT
								s.nbar.scalespeed = $*10				  
								s.nbar.destscale = $*40
									for d = 0,7
									P_SpawnParaloop(s.x, s.y, s.z, 80*FRACUNIT, 8, MT_NIGHTSPARKLE, d*(ANG20*2), S_SMSTSPARK1, true)
									end
								end
						end
					end
				elseif not p.smsgraphix and (p.speed >= FixedMul(140*FRACUNIT, s.scale)) and (s.z < s.floorz+200*FRACUNIT) and not (p.pflags & PF_SPINNING)
				and not p.novafire
					s.wvqs = s.wvqs and $+8 or 1
					if s.wvqs > 220
					s.wvqs = 220
					end
					for d = -1,1
						if d != 0
						s.sqwave = P_SpawnMobj(s.x+FixedMul(P_RandomRange(10,24)*FRACUNIT, cos(s.angle+(ANGLE_90*d))), s.y+FixedMul(P_RandomRange(10,24)*FRACUNIT, sin(s.angle+ANGLE_90*d)), s.floorz+1, MT_HMSWAVEAURA)
						s.sqwave.sprite = SPR_SMMK
						s.sqwave.dustwave2 = 1
						s.sqwave.frame = 8
						s.sqwave.fuse = 30
						s.sqwave.target = s
						s.sqwave.momx = s.momx*60/P_RandomRange(55,65)
						s.sqwave.momy = s.momy*60/P_RandomRange(55,65)
						s.sqwave.scale = (s.scale*4)/P_RandomRange(1, 10)
						s.sqwave.scalespeed = $*8/P_RandomRange(8, 20)
						s.sqwave.destscale = s.scale*4
						s.sqwave.angle = s.angle+ANGLE_90*d
						P_SetObjectMomZ(s.sqwave, -2*FRACUNIT)
						P_Thrust(s.sqwave, s.angle+ANGLE_90*d, P_RandomRange(-20,-50)*FRACUNIT)
						P_Thrust(s.sqwave, s.angle, (s.wvqs*-FRACUNIT)+P_RandomRange(0, 10)*FRACUNIT)
						s.sqwave.eflags = s.eflags
						/*	if d == -1
								if (s.sqwave.eflags & MFE_VERTICALFLIP)
								s.sqwave.eflags = $ & ~MFE_VERTICALFLIP
								s.sqwave.rollangle = 0
								else
								s.sqwave.eflags = $|MFE_VERTICALFLIP
								s.sqwave.rollangle = ANGLE_180
								end
							end */
						end
					end
				elseif not p.smsgraphix and (((p.speed < 44*FRACUNIT) and (s.z < s.floorz+350*FRACUNIT)) or (p.novafire and (s.z < s.floorz+600*FRACUNIT))) //Add dustclouds to make the power feel a bit more dynamic
					s.wvqs = 0
					if s.wvspwncd and not (s.eflags & MFE_JUSTHITFLOOR)
					s.wvspwncd = $-1
					else
							if not p.speed 
							and ((p.cmd.buttons & BT_CUSTOM1) or ((p.cmd.buttons & BT_CUSTOM3) and P_IsObjectOnGround(s)) or (p.pflags & PF_STARTDASH))
							s.hmsstompr = P_SpawnMobj(s.x+s.momx+P_RandomRange(-100,100)*FRACUNIT, s.y+s.momy+P_RandomRange(-100,100)*FRACUNIT, s.z+P_RandomRange(-20,10)*FRACUNIT, MT_HMSSTOMPAURA)
							s.hmsstompr.scale = (s.scale*2)*10/P_RandomRange(3,12)
							s.hmsstompr.eflags = s.eflags
							s.hmsstompr.tics = 10
							P_SetObjectMomZ(s.hmsstompr, P_RandomRange(10, 30)*FRACUNIT)
								if (s.eflags & MFE_VERTICALFLIP)
								s.hmsstompr.z = $-FixedMul(20*FRACUNIT, s.scale)
								end
							s.hmsstompr.target = s
							s.hmsstompr.color = P_RandomRange(SKINCOLOR_SUPERRED1, SKINCOLOR_SUPERGOLD5)
							s.hmsstompr.frame = T|FF_FULLBRIGHT|TR_TRANS50
							s.hmsstompr.scalespeed = $*10/P_RandomRange(10,20)
							s.hmsstompr.destscale = s.hmsstompr.scalespeed+1
							end
							
						if not (P_IsObjectOnGround(s) and not ((s.eflags & MFE_JUSTHITFLOOR) or (p.cmd.buttons & BT_CUSTOM1) or (p.cmd.buttons & BT_CUSTOM3) or (p.pflags & PF_STARTDASH)) )
						and not ((p.pflags & PF_STARTJUMP) and s.momz*P_MobjFlip(s) > 0)
						
						s.wvspwn = P_SpawnMobj(s.x, s.y, s.z, MT_THOK)
						s.wvspwn.z = s.floorz+1
						s.wvspwn.fuse = 1
						s.wvspwn.color = s.color
						s.wvspwn.sprite = SPR_NULL
						A_SMSSTOMPQUAKE(s.wvspwn, P_RandomRange(30, 50), P_RandomRange(12,18), P_RandomRange(8,30)*FRACUNIT, 0, s.sqaang*ANG1*P_RandomRange(1,3), 0, 30, 0, MT_HMSWAVEAURA)
						A_SMSSTOMPQUAKE(s.wvspwn, P_RandomRange(40, 70), P_RandomRange(12,18), P_RandomRange(15,25)*FRACUNIT, 0, s.sqaang*ANG1*P_RandomRange(-1,-3), 0, 30, 0, MT_HMSWAVEAURA)
							if p.novafire or p.dashspeed > 499*FRACUNIT
							A_SMSSTOMPQUAKE(s.wvspwn, P_RandomRange(100, 300), P_RandomRange(6,11), P_RandomRange(40,90)*FRACUNIT, 0, s.sqaang*ANG1*45, 0, 30, 0, MT_HMSWAVEAURA)
							end
							if (p.dashspeed >= 300*FRACUNIT)
							s.wvspwncd = 3			
							else
							s.wvspwncd = 5
							end
						end
					end
				elseif s.wvspwncd
				s.wvqs = 0
				s.wvspwncd = $-1
				end

				//Take away PF_SLIDING every tic to let you fight against the currents.

				if (p.pflags & PF_SLIDING)
					if P_IsObjectOnGround(s)
					p.pflags = $ & ~PF_SLIDING
					p.hmssrecover = true
					p.novafire = 5
					else
					p.pflags = $ & ~PF_SLIDING
					p.hmssrecover = true
					p.novafire = 5
					end
				end

				//Give HMS infinite time in space and water

				p.powers[pw_spacetime] = 0
				p.powers[pw_underwater] = 0
				
				if p.powers[pw_sneakers]
				p.powers[pw_sneakers] = 0
				P_RestoreMusic(p)
				end
				if p.powers[pw_invulnerability]
				p.powers[pw_invulnerability] = 0
				P_RestoreMusic(p)
				end	

				if (p.cmd.buttons & BT_FIRENORMAL)
				p.hms_flamehold = $+1
           		else
				p.hms_flamehold = 0
           		end

			if (p.pflags & PF_STARTDASH) //HMS' spreading flames
				if (p.cmd.buttons & BT_FIRENORMAL)
				and not (p.hms_flamehold > 1)
					S_StartSound(s, sfx_bkpoof)
					P_FlashPal(p, 4, 10)
					A_SMSquake(s, 56*FRACUNIT, 6, 2922)
					P_NukeEnemies(s, s, FixedMul(1500*FRACUNIT, s.scale))
						p.mng = P_SPMAngle(s, MT_HMSFIREBLAST, s.angle+ANG210 - 210, 1, MF2_RAILRING)
						if p.mng p.mng.color = 5 end
						p.mng = P_SPMAngle(s, MT_HMSFIREBLAST, s.angle-ANG210 - 210, 1, MF2_RAILRING)
						if p.mng p.mng.color = 5 end
						p.mng = P_SPMAngle(s, MT_HMSFIREBLAST, s.angle+ANG255 - 255, 1, MF2_RAILRING)
						if p.mng p.mng.color = 5 end
						p.mng = P_SPMAngle(s, MT_HMSFIREBLAST, s.angle-ANG255 - 255, 1, MF2_RAILRING)
						if p.mng p.mng.color = 5 end
						p.mng = P_SPMAngle(s, MT_HMSFIREBLAST, s.angle+ANG350 - 350, 1, MF2_RAILRING)
						if p.mng p.mng.color = 5 end
						p.mng = P_SPMAngle(s, MT_HMSFIREBLAST, s.angle-ANG350 - 350, 1, MF2_RAILRING)
						if p.mng p.mng.color = 5 end
						if G_GametypeHasSpectators()
							for z in players.iterate
								if z.mo and z.health
								and ((FixedHypot(FixedHypot(z.mo.x-s.x, z.mo.y-s.y), z.mo.z-s.z)) <= 1500*FRACUNIT)
								and not (p.ctfteam and (p.ctfteam == z.ctfteam))
									P_FlashPal(z, 4, 10)
									P_DamageMobj(z.mo, s, s)
									P_InstaThrust(z.mo, z.mo.angle, -45*FRACUNIT)
								end
							end
						end
				end
			end
			   if s.hmsgalaxystorm //Actually doing the Galaxy Storm
			   	s.hmsgalaxystorm = $-1
					
					if s.hmsgalaxystorm == 135
					s.momx = 0 s.momy = 0 s.momz = 0
					p.aiming = 0
					P_NukeEnemies(s, s, 160*FRACUNIT)
					s.hmsgaxf = P_SpawnPlayerMissile(s, MT_HMSGAX, MF2_RAILRING)
					s.hmsgaxf.color = SKINCOLOR_JET
					s.hmsgaxf.scale = s.scale/2
					s.state = S_HMSGAXANIM
					p.powers[pw_nocontrol] = 15
					p.drawangle = s.hmsspinang
					P_FlashPal(p, 4, 12)
					
					elseif (s.hmsgalaxystorm > 135)
					s.flags2 = $|MF2_DONTDRAW
					P_SetObjectMomZ(s, 5*FRACUNIT, false)
					P_InstaThrust(s, s.angle, -60*FRACUNIT)
					p.powers[pw_nocontrol] = 2
					
					elseif (s.hmsgalaxystorm > 105)
						if (s.hmsgalaxystorm > 120)
							if (s.hmsgalaxystorm > 129)
							s.frame = A|FF_FULLBRIGHT
							else
							s.frame = B|FF_FULLBRIGHT
							end
						P_SetObjectMomZ(s, 0, false)
						P_InstaThrust(s, s.angle, 0)				
						else
						P_SetObjectMomZ(s, 4*FRACUNIT, false)
						P_InstaThrust(s, s.angle, -20*FRACUNIT)
						s.hmsspinpass = 6
						s.hmsforcedspin = 6
						end
					elseif (s.hmsgalaxystorm == 105)
					p.powers[pw_nocontrol] = 0
					s.rollangle = 0
					p.pflags = $|PF_JUMPED & ~PF_THOKKED & ~PF_SPINNING
					end
			   else
				if (p.cmd.buttons & BT_ATTACK) and P_IsObjectOnGround(s) //Gravity Burst, shortened to gravbu. Also, hmsgalaxystorm.
				and not (p.sms_flamebuttonhold > 1)
					if (p.pflags & PF_STARTDASH) and not s.hmsgalaxystorm //Or alternatively, use the Galaxy Storm when charging a spindash!
					S_StartSound(s, sfx_hmsgax)
					P_FlashPal(p, 3, 3)
					s.hmsgalaxystorm = 145
					p.novafire = 45 p.hmsblackhole = 45 p.sms_flamedelay = 50
					A_SMSquake(s, 24*FRACUNIT, 31, 5000)
					s.bhlcamtimer = 15
					p.camerascale = FRACUNIT*3
					s.hmsspinpass = 12
					s.hmsforcedspin = 12
					s.novawave = P_SpawnMobj(s.x, s.y, s.z+s.height/2, MT_HMSNOVAWAVE)
						if s.novawave and s.novawave.valid
						s.novawave.scale = $*P_RandomRange(2,4)
					//	s.novawave.rollerwave = 14*FRACUNIT
						s.novawave.color = P_RandomRange(SKINCOLOR_SUPERSILVER1, SKINCOLOR_SUPERGOLD5)
						end
					
						s.hjg1 = P_SpawnMobj(s.x, s.y, s.z-20*FRACUNIT, MT_HMSWAVEAURA)
						s.hjg1.dustwave = 1
						s.hjg1.sprite = SPR_SMMK
						s.hjg1.frame = 3
						s.hjg1.target = s
						s.hjg1.fuse = 15
						s.hjg1.scale = s.scale
						s.hjg1.destscale = $*2
						A_SMSSTOMPSMOKE(s, 60, MT_SPINDUST, nil, nil, 2*FRACUNIT)
						A_SMSSTOMPQUAKE(s, 45, 14, FRACUNIT, 0, 0, 0, 0, SKINCOLOR_SUPERGOLD3)
						A_SMSSTOMPQUAKE(s, 80, 18, 2*FRACUNIT, 0, ANG20, 0, 0, SKINCOLOR_SUPERSILVER4)
						s.hjg = P_SpawnGhostMobj(s)
						s.hjg.sprite = SPR_HMSO //Use the spring frame specifically for this.
						s.hjg.frame = H|FF_FULLBRIGHT|TR_TRANS50
					
					p.pflags = $ & ~(PF_STARTDASH|PF_SPINNING)
					P_SetObjectMomZ(s, 50*FRACUNIT, false)
					P_InstaThrust(s, s.angle, -200*FRACUNIT)
		
		
		
					elseif not p.hms_gravburstcd and not p.smspickup //Rev up the gravity burst!
					
					
					
					p.pilblast = P_SpawnMobj(s.x+FixedMul(-2*FRACUNIT, cos(s.angle)), s.y+FixedMul (-2*FRACUNIT, sin (s.angle)), s.z, MT_HMSLIPILLAR)
					p.pilblast.color = SKINCOLOR_SKY
					S_StartSound(s, sfx_s3k4b)
					S_StartSound(s, sfx_telept)
					S_StartSound(s, sfx_bexpld)
					A_SMSSTOMPSMOKE(s, 90, MT_SPINDUST, nil, nil, 3*FRACUNIT)
						if not (p.smsgraphix)
						A_SMSSTOMPSMOKE(s, 30, MT_HMSLIGHTNING1, nil, nil, nil, SKINCOLOR_SKY)
						A_SMSSTOMPSMOKE(s, 70, MT_HMSLIGHTNING2, nil, nil, nil, SKINCOLOR_JET)
						end
					P_SetObjectMomZ(s, 9*FRACUNIT)
					s.hmsspinpass = 12
					s.hmsforcedspin = 12
					s.momx = $/2 
					s.momy = $/2
					s.bhlcamtimer = 15
					p.camerascale = FRACUNIT*3
					p.hms_gravburstcd = 100
					P_FlashPal(p, 3, 10)
					P_NukeEnemies(s, s, FixedMul(800*FRACUNIT, s.scale))
					A_SMSquake(s, 12*FRACUNIT, 11, 10922)
					p.pflags = $ & ~(PF_STARTDASH|PF_SPINNING)
					s.novawave = P_SpawnMobj(s.x, s.y, s.z, MT_HMSNOVAWAVE)
					s.novawave.color = SKINCOLOR_BLUE
					s.novawave.followmenoz = s
					s.novawave.scale = s.scale
						for m in mobjs.iterate(mobjs)
							if m and m.health and ((m.flags & MF_ENEMY) or (m.flags & MF_BOSS) or (m.type == MT_MINUS)
							or (m.player and G_GametypeHasSpectators() and not m.player.hypermysticsonic and not (p.ctfteam and (p.ctfteam == m.player.ctfteam))) )
								if ((FixedHypot(FixedHypot(m.x-s.x, m.y-s.y), m.z-s.z)) <= 5100*FRACUNIT)
									if (m.type == MT_MINUS)
									m.z = $+20*FRACUNIT
									m.state = S_MINUS_AERIAL2
									m.flags = $|MF_SHOOTABLE|MF_SPECIAL & ~MF_NOCLIPTHING
									end
								m.momx = $/3
								m.momy = $/3
								S_StartSound(m, sfx_mswing)
								m.gravbu = 24
								m.whshu = P_SpawnMobj(m.x, m.y, m.z, MT_CMPHTRACKER)
								m.whshu.target = m
									if m.player
									m.state = S_PLAY_STUN
									P_FlashPal(m.player, 2, 6)
										if P_PlayerInPain(m.player) and not p.powers[pw_carry]
										m.player.pflags = $|PF_JUMPED
										end
									end
								end
							end
						end
					end
				end
			   end

//When going really fast, blow up shit uuuup!

			if P_IsObjectOnGround(s)
				if s.nohmswarpforawhile and not (p.pflags & PF_SPINNING)
				s.nohmswarpforawhile = false
				end
				if (p.pflags & PF_STARTDASH) and not (p.dashspeed >= p.maxdash)
					if (leveltime % 6 == 0) and (p.dashspeed > 200*FRACUNIT and p.dashspeed < 300*FRACUNIT)
						A_SMSSTOMPQUAKE(s, 45, 14, FRACUNIT, 0, 0, 0, 0)
						A_SMSSTOMPQUAKE(s, 65, 18, 2*FRACUNIT, 0, ANG20, 0, 0, SKINCOLOR_SUPERSILVER4)
					end
					if (leveltime % 5 == 0)				
						if (p.dashspeed > 300*FRACUNIT and p.dashspeed < 400*FRACUNIT)
							A_SMSSTOMPQUAKE(s, 45, 14, FRACUNIT, 0, (ANG1*s.sqaang), 0, 0, P_RandomRange(70, 100))
							A_SMSSTOMPQUAKE(s, 65, 16, 2*FRACUNIT, 0, (ANG1*s.sqaang)*-1, P_RandomRange(70, 100))
							A_SMSSTOMPQUAKE(s, 85, 18, 3*FRACUNIT, 0, (ANG1*s.sqaang), 0, 0, P_RandomRange(70, 100))
						elseif (p.dashspeed > 400*FRACUNIT and p.dashspeed < 499*FRACUNIT)
							s.hmsstompr = P_SpawnMobj(s.x+s.momx+P_RandomRange(-100,100)*FRACUNIT, s.y+s.momy+P_RandomRange(-100,100)*FRACUNIT, s.z+P_RandomRange(-20,10)*FRACUNIT, MT_HMSSTOMPAURA)
							s.hmsstompr.scale = (s.scale*2)*10/P_RandomRange(3,12)
							s.hmsstompr.eflags = s.eflags
							s.hmsstompr.tics = 10
							P_SetObjectMomZ(s.hmsstompr, P_RandomRange(10, 30)*FRACUNIT)
								if (s.eflags & MFE_VERTICALFLIP)
								s.hmsstompr.z = $-FixedMul(20*FRACUNIT, s.scale)
								end
							s.hmsstompr.target = s
							s.hmsstompr.color = P_RandomRange(SKINCOLOR_SUPERRED1, SKINCOLOR_SUPERGOLD5)
							s.hmsstompr.frame = T|FF_FULLBRIGHT|TR_TRANS60
							s.hmsstompr.scalespeed = $*10/P_RandomRange(10,20)
							s.hmsstompr.destscale = s.hmsstompr.scalespeed+1
						
							A_SMSSTOMPQUAKE(s, 45, 6, 8*FRACUNIT, 0, (ANG1*s.sqaang), 0, 20, SKINCOLOR_SUPERRED4)
							A_SMSSTOMPQUAKE(s, 85, 8, 15*FRACUNIT, 0, (ANG1*s.sqaang)*-1, 0, 20)
							A_SMSSTOMPQUAKE(s, 125, 10, 25*FRACUNIT, 0, (ANG1*s.sqaang), 0, 20, P_RandomRange(70, 100))
							A_SMSSTOMPQUAKE(s, 165, 14, 35*FRACUNIT, FRACUNIT*2, (ANG1*s.sqaang)*-1, 0, 20, SKINCOLOR_SUPERSILVER4)
						end
					end
					if p.dashspeed == 300*FRACUNIT
					A_SMSquake(s, 4*FRACUNIT, 50, 300, true)
					elseif p.dashspeed == 350*FRACUNIT
					A_SMSquake(s, 12*FRACUNIT, 35, 300)
					elseif p.dashspeed == 385*FRACUNIT
					A_SMSquake(s, 64*FRACUNIT, 114, 300)
					S_StartSound(s, sfx_s3ka3)
					S_StartSound(s, sfx_s3k53)
					S_StartSound(s, sfx_bejet1)
					elseif p.dashspeed == 499*FRACUNIT
						A_SMSSTOMPQUAKE(s, 85, 1, 16*FRACUNIT, 0, ANG10, 0, 22, SKINCOLOR_RED)
						A_SMSSTOMPQUAKE(s, 95, 4, 70*FRACUNIT, 0, ANG30, 0, 19, SKINCOLOR_SUPERSILVER4)
						A_SMSSTOMPQUAKE(s, 75, 1, 32*FRACUNIT, 0, (ANG10*5), 0, 22)
						A_SMSSTOMPQUAKE(s, 105, 3, 78*FRACUNIT, 0, (ANG30*2), 0, 19, SKINCOLOR_SILVER)
					P_FlashPal(p, PAL_MIXUP, 3)
					s.hudboost = 1
					if not p.smsgraphix
					A_SMSSTOMPSMOKE(s, 40, MT_HMSLIGHTNING1, nil, nil, nil, SKINCOLOR_SUPERGOLD5)
					A_SMSSTOMPSMOKE(s, 20, MT_HMSLIGHTNING2, nil, nil, nil, SKINCOLOR_RED)
					end
					A_SMSquake(s, 94*FRACUNIT, 3, 3522)
					S_StartSound(s, sfx_s3ka0)
					S_StartSound(s, sfx_s3k9c)
					s.hmselcharge = 100
					end
					if (leveltime % 12 == 0)
					S_StartSound(s, sfx_spndsh)
					end
				elseif (p.dashspeed == p.maxdash) and (p.pflags & PF_STARTDASH)
						s.hypermysticdash = 105
						if (leveltime % 70 == 0)
						s.tormobj = P_SpawnMobj(s.x, s.y, s.z+80*FRACUNIT, MT_THOK)
						s.tormobj.flags2 = $|MF2_DONTDRAW
						s.tormobj.tics = 72
						s.tormobj.fuse = 72
						S_StartSound(s.tormobj, sfx_s3kcel)
						end
						if (p.cmd.forwardmove > 25)
						P_InstaThrust(s, s.angle, 313708) //Move just below the SRB2 spindash police threshold
						end
						s.eymon = P_SpawnMobj(s.x, s.y, s.z-9000*FRACUNIT, MT_SMSECHECK)
						if (leveltime % 5 == 0)
							if s.eymon and s.eymon.valid
								s.eymon.hmstornado = true
								s.eymon.target = s
								s.eymon.height = 99900*FRACUNIT
								s.eymon.radius = 1800*FRACUNIT
							end
						end
						if (leveltime % 12 == 0) //Fancy DNA tornado!
						//We set the local wind variables at the top of the script!
						wind = P_SpawnMobj(s.x+560*FixedMul(s.scale, cos(ANGLE_90)), s.y+560*FixedMul(s.scale, sin(ANGLE_90)), s.z-(s.scale*80), MT_DUSTLAYER)
						wind.angle = ANGLE_180 //Remember that it's a papersprite!
						wind.flags = $|MF_NOCLIPHEIGHT
						wind.momz = (40*P_MobjFlip(s))*s.scale
						wind.scale = s.scale*8
						wind.momx = s.momx
						wind.momy = s.momy
						wind.tracer = s.hmstor
						s.hmstor = wind
						
						wind2 = P_SpawnMobj(s.x-560*FixedMul(s.scale, cos(ANGLE_90)), s.y-560*FixedMul(s.scale, sin(ANGLE_90)), s.z-(s.scale*80), MT_DUSTLAYER)
						wind2.angle = 0
						wind2.flags = $|MF_NOCLIPHEIGHT
						wind2.momz = (40*P_MobjFlip(s))*s.scale
						wind2.scale = s.scale*8
						wind2.momx = s.momx
						wind2.momy = s.momy
						wind2.tracer = s.hmstor2
						s.hmstor2 = wind2
						end
				
						for d = 1,2
							s.hmsstompr = P_SpawnMobj(s.x+s.momx+P_RandomRange(-100,100)*FRACUNIT, s.y+s.momy+P_RandomRange(-100,100)*FRACUNIT, s.z+P_RandomRange(-20,10)*FRACUNIT, MT_HMSSTOMPAURA)
							s.hmsstompr.scale = (s.scale*2)*10/P_RandomRange(3,12)
							s.hmsstompr.eflags = s.eflags
							s.hmsstompr.tics = 10
							P_SetObjectMomZ(s.hmsstompr, P_RandomRange(10, 30)*FRACUNIT)
								if (s.eflags & MFE_VERTICALFLIP)
								s.hmsstompr.z = $-FixedMul(20*FRACUNIT, s.scale)
								end
							s.hmsstompr.target = s
							s.hmsstompr.color = P_RandomRange(SKINCOLOR_SUPERRED1, SKINCOLOR_SUPERGOLD5)
							s.hmsstompr.frame = T|FF_FULLBRIGHT|TR_TRANS70
							s.hmsstompr.scalespeed = $*10/P_RandomRange(10,20)
							s.hmsstompr.destscale = s.hmsstompr.scalespeed+1
						end
						if leveltime % 2 == 0
							if (s.eflags & MFE_VERTICALFLIP)
							s.hmsstompr = P_SpawnMobj(s.x+P_RandomRange(-700,700)*FRACUNIT, s.y+P_RandomRange(-700,700)*FRACUNIT, s.ceilingz, MT_THOK)
							else
							s.hmsstompr = P_SpawnMobj(s.x+P_RandomRange(-700,700)*FRACUNIT, s.y+P_RandomRange(-700,700)*FRACUNIT, s.floorz, MT_THOK)
							end
							s.hmsstompr.scale = s.scale*10/P_RandomRange(5,50)
							s.hmsstompr.eflags = s.eflags
							s.hmsstompr.fuse = 70
							P_SetObjectMomZ(s.hmsstompr, P_RandomRange(5, 15)*FRACUNIT)
							s.hmsstompr.target = s
							if s.hmsstompr.floorz == s.hmsstompr.ceilingz
							s.hmsstompr.state = S_NULL
							else
							s.hmsstompr.state = S_ROCKCRUMBLEA
							end
						end
				end
				if p.skidtime
					if p.skidtime == 16 
					S_StartSound(s, sfx_ngskid)
						if not s.hmselcharge
						s.hmselcharge = 70
						end
						if (p.speed > FixedMul(40*FRACUNIT, s.scale)) and not p.smsgraphix
						S_StartSound(s, sfx_kc4d)
						A_SMSSTOMPSMOKE(s, 40, MT_HMSLIGHTNING1, nil, nil, nil, SKINCOLOR_SUPERGOLD5)
						end
					end
					if (p.speed > FixedMul(15*FRACUNIT, s.scale))
					A_SMSSpinFire(s, MT_SMSSPINFIRE, 65357)
					A_SMSSpinFire(s, MT_SMSSPINFIRE, 65357, 5*FRACUNIT)
					end
				end
				if s.hmsstompsfx
				s.hmsstompsfx = false
				end
				if (p.pflags & PF_SPINNING) and (p.pflags & PF_JUMPED)
				p.pflags = $ & ~PF_JUMPED
				end
				p.hmsdash = 0
				
				//This makes HMS leave sparks and firetrails wherever he goes			
				if (leveltime % 3 == 0) //P_CheckDeathPitCollide(s)
				and not (p.smsgraphix and p.smsgraphix == 2)
				and not A_HMSCheckDeathPit(s)
					s.elofc = P_SpawnMobj(s.x+P_RandomRange(-250, 250)*FRACUNIT, s.y+P_RandomRange(-250, 250)*FRACUNIT, s.z, MT_HMSWAVEAURA)
						if s.elofc and s.elofc.valid
						s.elofc.eflags = s.eflags
						s.elofc.state = S_HMSWAVEAURAG
						s.elofc.target = s
				//		s.elofc.frame = $+P_RandomRange(0,4)
							if (s.eflags & MFE_VERTICALFLIP)
							s.elofc.z = s.elofc.ceilingz
							else
							s.elofc.z = s.elofc.floorz						
							end
						end
				end
				if (p.speed > FixedMul(6*FRACUNIT, s.scale)) //Don't spawn them when standing still, the flames will act weird & lag
				and not (s.eflags & (MFE_UNDERWATER|MFE_TOUCHWATER)) //No flames when underwater, ofcourse.
				and not A_HMSCheckDeathPit(s) //Not when on a death pit.
				//	A_SMSquake(s, p.speed/3, 1, (p.speed/65355)*700, true)
					if (p.speed > FixedMul(138*FRACUNIT, s.scale))
					s.hmsmwh = 1
						if (p.pflags & PF_SPINNING)
						s.hmsfsfx = false
						A_SMSSpinFire(s, MT_SMSSPINFIRE, 65357)
						A_SMSSpinFire(s, MT_SMSSPINFIRE, 65357, 5*FRACUNIT)
						else
							if not s.hmsfsfx
							s.hmsfsfx = true
							S_StartSound(s, sfx_s3k43) //S_StartSound(s, sfx_s3k48)
							end
						A_HMSfiretrail(s)
						end
						if s.maxtimex == nil
						s.maxtimex = 0
						s.maxtimey = 0
						s.maxtimers = 0
						end
						if s.x == s.maxtimex and s.y == s.maxtimey
							if s.maxtimers == nil
							s.maxtimers = 1							
							else
							s.maxtimers = $+1
								if (s.maxtimers > 31)
								s.z = s.floorz+5*FRACUNIT
								P_DoJump(p, false) //SRB2's colission is screwing you. Stop this madness.
								s.momx = 0
								s.momy = 0
								s.momz = 0
								end
							end
						else
							s.maxtimers = 0				
						end
					s.maxtimex = s.x
					s.maxtimey = s.y
					else
						if not s.hmsfsfx
						s.hmsfsfx = true
						S_StartSound(s, sfx_s3k43) //S_StartSound(s, sfx_s3k48)
						end
					  	if not (p.smsgraphix and p.smsgraphix == 2)
							if (s.eflags & MFE_JUSTHITFLOOR) or (leveltime % 2 == 0) or (p.speed > FixedMul(56*FRACUNIT, s.scale))
							A_HMSfiretrail(s)
							end
				     	end
					end
				elseif s.hmsfsfx
				s.hmsfsfx = false
				end

				if (p.speed >= FixedMul(137*FRACUNIT, s.scale))
				s.hmsmwh = 1
				s.hmslastspeedn = p.speed
				    if (leveltime % 2 == 0)
                    P_NukeEnemies(s, s, 650*FRACUNIT)
				    end
					p.smsgrboost = P_SpawnMobj(s.x, s.y, s.z, MT_SMSGROUNDBOOST)
					p.smsgrboost.tracer = s
					A_SMSquake(s, 14*FRACUNIT, 1, 4122, true)
					s.hmsrunquake = 1
                end
				if (p.pflags & PF_CANCARRY)
				p.pflags = $ & ~PF_CANCARRY
				s.hmscarryset = false
				end
			else
				if s.nohmswarpforawhile
				s.nohmswarpforawhile = false
				end
				if s.hmsfsfx
				s.hmsfsfx = false
				end
				if p.powers[pw_carry] and (p.pflags & PF_JUMPED)
					p.pflags = $ & ~PF_JUMPED
				end
				if not (p.pflags & PF_CANCARRY)		
				p.pflags = $|PF_CANCARRY
				s.hmscarryset = true
				end
				//Midair version is less powerfull, but works too.

				if (p.speed >= FixedMul(165*FRACUNIT, s.scale)) // Check here later, and P_RandomRange(0,1)
					s.hmsmwh = 1
					if (leveltime % 2 == 0)
						P_NukeEnemies(s, s, 325*FRACUNIT)
					elseif not (p.smsgraphix and p.smsgraphix == 2)
						if P_RandomRange(0,1)
						A_SMSSTOMPSMOKE(s, P_RandomRange(8, 35), MT_NIGHTSPARKLE, (P_RandomRange(1, 50)*FRACUNIT))
						else
						A_SMSSTOMPSMOKE(s, P_RandomRange(8, 25), MT_IVSP, (P_RandomRange(1, 50)*FRACUNIT))
						end
					end
				end
			end

//Spindashing? Then doom awaits all those around you!

				if (p.pflags & PF_SPINNING)
				and not (p.pflags & (PF_STARTDASH|PF_JUMPED|PF_GAMETYPEOVER))
				and not p.hms_explosion
				and not p.powers[pw_carry]
					if (p.speed > FixedMul(49*FRACUNIT, s.scale))
					A_SMSquake(s, 14*FRACUNIT, 1, 2122, true)
					if P_IsObjectOnGround(s)
					s.hmsrunquake = 1
					
						if (leveltime % 5 == 0) and (p.speed < FixedMul(136*FRACUNIT, s.scale))
						A_SMSSTOMPSMOKE(s, 30, MT_HMSLIGHTNING1, nil, nil, nil, SKINCOLOR_SUPERGOLD5)
						S_StartSound(s, sfx_s3k7c) 
						elseif (p.speed >= FixedMul(136*FRACUNIT, s.scale)) and (leveltime % 2 == 0)
						A_SMSSTOMPSMOKE(s, 35, MT_HMSLIGHTNING1, nil, nil, nil, P_RandomRange(70, 102))
						S_StartSound(s, sfx_s3k7c) 
						end
					
					end
					p.smsgrboost = P_SpawnMobj(s.x, s.y, s.z, MT_SMSGROUNDBOOST)
					p.smsgrboost.tracer = s
						if (s.state == S_PLAY_STND)
						or (s.state == S_PLAY_WALK)
						s.state = S_PLAY_RUN
						end
						if p.smsgrboost and (p.speed > FixedMul(136*FRACUNIT, s.scale))
						A_SMSquake(s, 55*FRACUNIT, 1, 3522)
						s.hmsrunquake = 1
						p.smsgrboost.prism = true
						end
					end
					
					if (p.lddiscount and (p.lddiscount == (1 or 3) ))				
						if (p.speed < FixedMul(27*FRACUNIT, s.scale))
							s.eymon = P_SpawnMobj(s.x+FixedMul(150*FRACUNIT,cos(s.angle)), s.y+FixedMul(150*FRACUNIT,sin(s.angle)), s.z-400*FRACUNIT, MT_SMSECHECK)
							if s.eymon and s.eymon.valid
							s.eymon.hmsspincheck = true
							s.eymon.target = s
							s.eymon.height = 800*FRACUNIT
							s.eymon.radius = 350*FRACUNIT
							end
						elseif (p.speed >= FixedMul(27*FRACUNIT, s.scale) and p.speed < FixedMul(52*FRACUNIT, s.scale))
						//	A_SMSFindTarget(s, FixedMul(876*FRACUNIT, s.scale), 20)
							s.eymon = P_SpawnMobj(s.x+FixedMul(400*FRACUNIT,cos(s.angle)), s.y+FixedMul(200*FRACUNIT,sin(s.angle)), s.z-475*FRACUNIT, MT_SMSECHECK)
							if s.eymon and s.eymon.valid
							s.eymon.hmsspincheck = true
							s.eymon.target = s
							s.eymon.height = 950*FRACUNIT
							s.eymon.radius = 550*FRACUNIT
							end
						else
						//	A_SMSFindTarget(s, FixedMul(1400*FRACUNIT, s.scale), 20)
							s.eymon = P_SpawnMobj(s.x+FixedMul(700*FRACUNIT,cos(s.angle)), s.y+FixedMul(700*FRACUNIT,sin(s.angle)), s.z-600*FRACUNIT, MT_SMSECHECK)
							if s.eymon and s.eymon.valid
							s.eymon.hmsspincheck = true
							s.eymon.target = s
							s.eymon.height = 1200*FRACUNIT
							s.eymon.radius = 800*FRACUNIT
							end
						end
					end

						if s.hmsspint and s.hmsspint.valid
						local t = s.hmsspint
							if (t.health or t.flags & MF_BOSS)  //Leaving in a fun bug on purpose.
							and ((t.flags & MF_ENEMY) or (t.flags & MF_BOSS) or (t.flags & MF_MONITOR) 
							or (t.player and G_GametypeHasSpectators() and not t.player.powers[pw_flashing] and not (p.ctfteam and (p.ctfteam == t.player.ctfteam))) )
							and not (t.z > s.z+1000*FRACUNIT)
							and not (t.z < s.z-1000*FRACUNIT)
						 		if (t.type == MT_EGGGUARD) and t.tracer and t.tracer.health and (t.tracer.type == MT_EGGSHIELD)
								 t.tracer.state = S_NULL
						 		 t.flags = $|MF_SHOOTABLE|MF_ENEMY
						 		end

							P_SpawnMobj(t.x, t.y, t.z, MT_CYBRAKDEMON_VILE_EXPLOSION)
							if not p.smsgraphix
								for d = 1,12
									s.ghs = P_SpawnMobj(t.x+P_RandomRange(-250, 250)*FRACUNIT, t.y+P_RandomRange(-250, 250)*FRACUNIT, t.z+P_RandomRange(-99, 250)*FRACUNIT, MT_THOK)
									s.ghs.sprite = SPR_HMSO
									if P_RandomRange(0,1)
									s.ghs.frame = G|TR_TRANS20
									
									elseif not P_RandomRange(0,3)
									s.ghs.frame = B|TR_TRANS30
										if P_RandomRange(0,1)
										s.ghs.destscale = s.ghs.scale*9
										end
									else
									s.ghs.frame = s.frame|TR_TRANS50
									end
									P_HomingAttack(s.ghs, t)
									s.ghs.color = s.color
									s.ghs.tics = P_RandomRange(3,18)
									s.ghs.angle = R_PointToAngle2(s.ghs.x, s.ghs.y, t.x, t.y)
								end
							end
							S_StartSound(t, sfx_brakrx)
							P_SetObjectMomZ(t, 10*FRACUNIT, true)
							P_DamageMobj(t, s, s)
							p.hms_explosion = 2
								if t.valid and t.health
									if t.player
									P_FlashPal(t.player, 4, 4)
									P_DoPlayerPain(t.player)
									P_SetObjectMomZ(t, 14*FRACUNIT, true)
										if t.player.powers[pw_invulnerability]
										t.player.powers[pw_invulnerability] = 2
										end
									end
									if (t.health > 1)
									and not (t.info.mass == 2006) and not t.player
									P_KillMobj(t, nil, s) //Still alive? Die already!
									end
								end
							end
							s.hmsspint = nil
						elseif s.hmsspint and not s.hmsspint.valid
						s.hmsspint = nil
						end
				end

//Want overkill? Here it is, in all it's DBZ-like glory.
//HMS finds you, knocks you around, stops time, and blows you to hell in a blazing light.
//This turned out to be one humongous script for a "simple" combo attack...

		     if (p.cmd.buttons & BT_TOSSFLAG)
		     and (p.cmd.buttons & BT_CUSTOM2)
		     and not (p.smsmeleebutton > 1)
		     and not (p.pflags & (PF_STASIS))
			 and not p.powers[pw_carry]
		     and not p.knucklewaving
		     and not (s.state == S_HMSBLACKHOLE)
		     and not p.starthmscombo
		//	A_SMSFindTarget(s, 500*FRACUNIT, 7)
			s.eymon = P_SpawnMobj(s.x+FixedMul(250*FRACUNIT,cos(s.angle)), s.y+FixedMul(250*FRACUNIT,sin(s.angle)), s.z-500*FRACUNIT, MT_SMSECHECK)
				if s.eymon and s.eymon.valid
				s.eymon.hmsspincheck = true
				s.eymon.hmsspincheck2 = true
				s.eymon.target = s
				s.eymon.height = 1000*FRACUNIT
				s.eymon.radius = 300*FRACUNIT
				end
			if s.hmsspint2 and s.hmsspint2.valid and s.hmsspint2.health and ( (s.hmsspint2.type != MT_PLAYER) or (((G_RingSlingerGametype() or s.battlemodsms) and (s.hmsspint2.player)))
			and not s.hmsspint2.hmscombod and not (s.hmsspint2.player and s.hmsspint2.player.ctfteam and (s.hmsspint2.player.ctfteam == p.ctfteam)) )
		//	and ((FixedHypot(s.hmsspint2.x-s.x, s.hmsspint2.y-s.y)) < 555*FRACUNIT)
				p.starthmscombo = 160
				s.hmsspint2.hmscombod = true

					if (s.hmsspint2.type == MT_EGGMOBILE4)
					s.hmsspint2.flags2 = $|MF2_BOSSNOTRAP
					P_TeleportMove(s, s.x, s.y, s.z+450*FRACUNIT)
					else
					//	if (s.hmsspint2.type == MT_CYBRAKDEMON)
					//	s.hmsspint2.flags = $|MF_SHOOTABLE|MF_NOTHINK & ~MF_NOCLIPTHING
					//	end
						if s.hmsspint2.target and s.hmsspint2.target.player
						s.hmsspint2.target = nil //Forget your target. Think about yourself!
						end
						if s.hmsspint2.tracer and s.hmsspint2.tracer.player
						s.hmsspint2.tracer = s
						end
					end
					if s.hmsspint2 and not s.hmsspint2.player
					s.hmsspint2.hmscombopreflags = s.hmsspint2.flags
						if s.hmsspint2.type == MT_METALSONIC_BATTLE 
						s.hmsspint2.flags = $|MF_NOCLIPTHING & ~MF_NOGRAVITY|MF_SHOOTABLE|MF_FLOAT
						elseif not (s.hmsspint2.type == MT_FANG)
						s.hmsspint2.flags = $|MF_NOCLIPTHING & ~MF_NOGRAVITY|MF_SHOOTABLE|MF_FLOAT
						end
					end
				elseif s.hmsspint2	
					if not s.hmsspint2.valid
					s.hmsspint2	= nil
					p.starthmscombo = 0
					s.state = S_PLAY_WALK
					s.flags = $ & ~MF_NOCLIPTHING & ~MF_BOUNCE
					elseif not s.hmsspint2.health
					s.hmsspint2	= nil
					p.starthmscombo = 0
					s.flags = $ & ~MF_NOCLIPTHING
					s.state = S_PLAY_WALK
					s.flags = $ & ~MF_NOCLIPTHING & ~MF_BOUNCE
					end
				end
		    end
		    if p.starthmscombo //Something about the conversion from XWE to SLADE misalligned these terribly.
		   	and s.hmsspint2 and s.hmsspint2.valid and s.hmsspint2.health and s.hmsspint2.hmscombod
		    p.powers[pw_nocontrol] = 2
		    s.flags = $|MF_NOCLIPTHING
		    local t = s.hmsspint2
				if t.player
				P_FlashPal(t.player, PAL_MIXUP, 10)
				t.player.powers[pw_nocontrol] = 2
				t.player.powers[pw_flashing] = -1
				t.player.powers[pw_tailsfly] = 0
				t.player.secondjump = 0
				t.player.fly1 = 0
				t.player.viewrollangle = t.rollangle
				t.hmscchange = true
				t.player.pflags = $ & ~PF_JUMPED & ~PF_SLIDING & ~PF_SPINNING
				t.sprite = SPR_PLAY
				t.sprite2 = SPR2_PAIN
				t.tics = 500
				t.anim_duration = 500
				t.frame = A
				t.nuuuuuuuuu = true
				end

			if (p.starthmscombo <= 160 and p.starthmscombo > 1)
			
				if (t.health <= 1)
				t.health = 3
				end
				t.anim_duration = 5
				t.godbreakervictim = true
				if t.fuse
				t.fuse = $+1 //Extend their fuse.
				end
				if (t.z+t.height > t.ceilingz)
				t.z = t.ceilingz-t.height
				end
				if not p.smsgraphix //Lag Prevention.
					if (p.starthmscombo > 80)
					t.rollangle = $+FixedAngle(55*FRACUNIT)
					elseif (p.starthmscombo > 30)
					t.rollangle = $-FixedAngle(40*FRACUNIT)
					else
					t.rollangle = $-FixedAngle(16*FRACUNIT)
					end
				end
				if t.player
				t.player.rings = 2
				P_PlayerFlagBurst(t.player)
				end
			end
			if (p.starthmscombo <= 160 and p.starthmscombo > 105)
				if (p.starthmscombo < 160)
					if (t.type == MT_MINUS)
						t.state = S_MINUS_AERIAL2
						t.flags = $|MF_SHOOTABLE|MF_SPECIAL
					elseif (t.info.painstate == S_NULL)
						P_SetMobjStateNF(t, t.info.spawnstate)
					//	t.state = t.info.spawnstate
					else
						P_SetMobjStateNF(t, t.info.painstate)
					//	t.state = t.info.painstate
					end
				end
				if (t.type == MT_GOLDBUZZ) or (t.type == MT_REDBUZZ)
				P_TryMove(t, t.x+FixedMul(44*FRACUNIT, cos(s.angle)), t.y+FixedMul(44*FRACUNIT, sin(s.angle)) , true)
				P_TryMove(s, s.x+FixedMul(44*FRACUNIT, cos(s.angle)), s.y+FixedMul(44*FRACUNIT, sin(s.angle)) , true)
				end
				t.angle = t.angle+ANGLE_45
				t.tics = 106
				t.reactiontime = 106 //Set these so nothing'll change
				s.momx = t.momx
				s.momy = t.momy
				s.momz = t.momz
				s.state = S_PLAY_HMSCOMBO1
					if t.player
					t.target = nil //Forget your target. Think about yourself!
					end
					if t.tracer and t.tracer.player //Trace HMS, not any other player
					t.tracer = s
					elseif t.tracer and t.tracer.valid and t.type == MT_GSNAPPER
					t.tracer.momx = t.momx
					t.tracer.momy = t.momy
					t.tracer.momz = t.momz
						if not p.smsgraphix
						t.tracer.rollangle = t.rollangle
						end
					end

			elseif (p.starthmscombo <= 105 and p.starthmscombo > 80)
				if (t.type == MT_MINUS)
					t.state = S_MINUS_AERIAL2
					t.flags = $|MF_SHOOTABLE|MF_SPECIAL
				elseif ((t.info.deathstate != S_NULL) and (t.player or t.flags & MF_BOSS) and (t.skin != "sms"))
				P_SetMobjStateNF(t, t.info.deathstate)
			//	t.state = t.info.deathstate
				elseif ((t.info.painstate != S_NULL) and (t.player or t.flags & MF_BOSS))
				P_SetMobjStateNF(t, t.info.painstate)
			//	t.state = t.info.painstate
				else
				P_SetMobjStateNF(t, t.info.spawnstate)
			//	t.state = t.info.spawnstate
				end

				P_SpawnMobj(t.x+((P_RandomRange(FixedMul(-56, t.scale), FixedMul(56, t.scale)))*FRACUNIT), 
				t.y+((P_RandomRange(FixedMul(-56, t.scale), FixedMul(56, t.scale)))*FRACUNIT), 
				t.z+((P_RandomRange(FixedMul(1, t.scale), FixedMul(65, t.scale)))*FRACUNIT), MT_BOSSEXPLODE)

			//	t.target = nil //It's all over.
				t.angle = s.angle+ANGLE_180
				s.momx = 0
				s.momy = 0
				s.momz = 1
			elseif (p.starthmscombo <= 80 and p.starthmscombo > 15)
				if (t.type == MT_MINUS)
					t.state = S_MINUS_AERIAL2
				elseif (t.info.painstate == S_NULL)
				P_SetMobjStateNF(t, t.info.spawnstate)
				else
				P_SetMobjStateNF(t, t.info.painstate)
				end
			//	t.target = nil //It's all over.
				t.angle = t.angle-(ANGLE_11hh/2)
				s.hmgodticket = true
				s.state = S_PLAY_HMSCOMBO2
				s.momx = 0
				s.momy = 0
				if (t.z+190*FRACUNIT < s.z) and ((p.starthmscombo < 45) or (t.flags & MF_BOSS))
				s.momz = -50*FRACUNIT
				t.momz = $/2
				elseif (t.z-190*FRACUNIT > s.z) and ((p.starthmscombo < 45) or (t.flags & MF_BOSS))
				s.momz = 50*FRACUNIT
				t.momz = $/2
				else
				s.momz = 1
				end
				if (t.momz < 2*FRACUNIT)
					if (p.starthmscombo >= 63)
						P_SetObjectMomZ(t, -6*FRACUNIT)
						P_InstaThrust(t, s.angle, 7*FRACUNIT)
					elseif (p.starthmscombo < 63 and p.starthmscombo > 45)
						P_SetObjectMomZ(t, -4*FRACUNIT)
						P_InstaThrust(t, s.angle, 3*FRACUNIT)
					else
						P_SetObjectMomZ(t, -105355)
						P_InstaThrust(t, s.angle, 0)
						P_FlashPal(p, PAL_MIXUP, 2)
						if t.player
						P_FlashPal(t.player, PAL_MIXUP, 2)
						end
					end
				end
			elseif (p.starthmscombo <= 15 and p.starthmscombo > 1)
				if (t.type == MT_MINUS)
					t.state = S_MINUS_AERIAL2
				elseif (t.info.painstate == S_NULL)
				P_SetMobjStateNF(t, t.info.spawnstate)
				else
				P_SetMobjStateNF(t, t.info.painstate)
				end

				P_SpawnMobj(t.x+((P_RandomRange(FixedMul(-150, t.scale), FixedMul(150, t.scale)))*FRACUNIT), 
				t.y+((P_RandomRange(FixedMul(-150, t.scale), FixedMul(150, t.scale)))*FRACUNIT), 
				t.z+((P_RandomRange(FixedMul(-20, t.scale), FixedMul(130, t.scale)))*FRACUNIT), MT_BOSSEXPLODE)

			//	t.target = nil //It's all over.
				t.angle = t.angle-(ANGLE_11hh/4)
				s.momx = 0
				s.momy = 0
				s.momz = 1
				t.momz = 0
				s.hmgodticket = true
				s.state = S_PLAY_HMSCOMBO3
			end

			if p.starthmscombo == 159
				A_SMSSTOMPSMOKE(s, 70, MT_HMSLIGHTNING2, nil, -5*FRACUNIT, nil, SKINCOLOR_SUPERGOLD5)
				S_StartSound(s, sfx_bkpoof)
				S_StartSound(s, sfx_nerf)
				P_FlashPal(p, PAL_NUKE, 10)
			//	P_FlashPal(p, PAL_MIXUP, 6)
				A_SMSquake(s, 60*FRACUNIT, 6, 6022)
				P_InstaThrust(t, s.angle, 40*FRACUNIT)
				P_SpawnMobj(t.x, t.y, t.z, MT_BURSTWAVE)
				P_SpawnMobj(t.x, t.y, t.z, MT_BURSTLIGHT)
				P_SetObjectMomZ(t, 10*FRACUNIT)
				s.state = S_PLAY_RUN
				s.finalburstwave = P_SpawnMobj(s.x, s.y, s.z, MT_RADIALBOOST)
				s.finalburstwave.color = SKINCOLOR_YELLOW
				s.z = t.z
				P_TryMove(s, t.x, t.y, true)
			//	P_TeleportMove(s, t.x, t.y, t.z)

			elseif p.starthmscombo == 149
			//	A_SMSSTOMPSMOKE(s, 55, MT_HMSLIGHTNING2, nil, nil, nil, SKINCOLOR_JET) Sometimes less is more, I think.
				S_StartSound(s, sfx_nerf)
				A_SMSquake(s, 54*FRACUNIT, 5, 6022)
			//	P_FlashPal(p, PAL_NUKE, 10)
				P_InstaThrust(t, s.angle-ANGLE_22h, 55*FRACUNIT)
				P_SpawnMobj(t.x, t.y, t.z, MT_BURSTWAVE)
				P_SetObjectMomZ(t, 1*FRACUNIT)

			elseif p.starthmscombo == 141
			//	A_SMSSTOMPSMOKE(s, 95, MT_HMSLIGHTNING2, nil, 5*FRACUNIT, nil, SKINCOLOR_SUPERGOLD5)
				S_StartSound(s, sfx_nerf)
				P_InstaThrust(t, s.angle+ANGLE_22h, 40*FRACUNIT)
			//	P_FlashPal(p, PAL_MIXUP, 4)
				A_SMSquake(s, 52*FRACUNIT, 8, 6022)
				P_SetObjectMomZ(t, 16*FRACUNIT)
				P_SpawnMobj(t.x, t.y, t.z, MT_BURSTWAVE)
				P_SpawnMobj(t.x-175*FRACUNIT, t.y+150*FRACUNIT, t.z+100*FRACUNIT, MT_BURSTLIGHT)
				P_SpawnMobj(t.x+175*FRACUNIT, t.y-160*FRACUNIT, t.z-10*FRACUNIT, MT_BURSTLIGHT)
			elseif (p.starthmscombo == 137 or p.starthmscombo == 114 or p.starthmscombo == 154)
					S_StartSound(t, sfx_nerf)
					P_SpawnMobj(t.x+80*FRACUNIT, t.y-70*FRACUNIT, t.z+25*FRACUNIT, MT_BURSTWAVE)
					P_SpawnMobj(t.x+120*FRACUNIT, t.y-150*FRACUNIT, t.z+50*FRACUNIT, MT_BOSSEXPLODE)
					P_SpawnMobj(t.x-140*FRACUNIT, t.y+170*FRACUNIT, t.z-5*FRACUNIT, MT_BOSSEXPLODE)
					P_SpawnMobj(t.x+300*FRACUNIT, t.y+290*FRACUNIT, t.z+77*FRACUNIT, MT_BURSTLIGHT)
					P_SpawnMobj(t.x-280*FRACUNIT, t.y-277*FRACUNIT, t.z-33*FRACUNIT, MT_BURSTLIGHT)


			elseif p.starthmscombo == 132
				S_StartSound(s, sfx_nerf)
				P_InstaThrust(t, s.angle-ANGLE_11hh, 47*FRACUNIT)
				A_SMSquake(s, 80*FRACUNIT, 10, 6022)
				P_SpawnMobj(t.x, t.y, t.z, MT_BURSTWAVE)
				P_SpawnMobj(t.x-150*FRACUNIT, t.y-200*FRACUNIT, t.z+70*FRACUNIT, MT_BURSTWAVE)
				P_SpawnMobj(t.x+240*FRACUNIT, t.y+190*FRACUNIT, t.z+50*FRACUNIT, MT_BURSTWAVE)
				P_SetObjectMomZ(t, -10*FRACUNIT)
			elseif p.starthmscombo == 120
				S_StartSound(s, sfx_nerf)
				A_SMSquake(s, 64*FRACUNIT, 6, 6022)
				P_InstaThrust(t, s.angle+ANGLE_11hh, 43*FRACUNIT)
				P_SpawnMobj(t.x, t.y, t.z, MT_BURSTWAVE)
				P_SpawnMobj(t.x+195*FRACUNIT, t.y-180*FRACUNIT, t.z+80*FRACUNIT, MT_BURSTLIGHT)
				P_SpawnMobj(t.x-186*FRACUNIT, t.y+177*FRACUNIT, t.z-20*FRACUNIT, MT_BURSTLIGHT)
				P_SetObjectMomZ(t, 14*FRACUNIT)
			elseif p.starthmscombo == 105
				S_StartSound(s, sfx_nerf)
				A_SMSquake(s, 93*FRACUNIT, 5, 10022)
				P_InstaThrust(t, s.angle+ANGLE_11hh, 56*FRACUNIT)
				P_SpawnMobj(t.x, t.y, t.z, MT_BURSTWAVE)
				P_SetObjectMomZ(t, 0)
				s.state = S_PLAY_RUN
			elseif p.starthmscombo == 100
				S_StartSound(t, sfx_s3k4b)
				S_StartSound(s, sfx_s3kbcs)
				P_InstaThrust(t, s.angle, 0)
				P_SpawnMobj(t.x, t.y, t.z, MT_BURSTLIGHT)
				P_SetObjectMomZ(t, 16*FRACUNIT)
			elseif p.starthmscombo == 80
				/*	s.hmsl2d = P_SpawnMobj(s.x, s.y, s.z, MT_HMSLIGHTNING2)
					s.hmsl2d.followsms = s
					s.hmsl2d.ltimershort = true 
					s.hmsl2d.color = SKINCOLOR_CRIMSON */
				s.z = t.z-140*FRACUNIT
				P_TryMove(s, t.x, t.y, true)
			//	P_TeleportMove(s, t.x, t.y, t.z-140*FRACUNIT)
				S_StartSound(t, sfx_s3k7c)
				S_StartSound(t, sfx_s3k83)
				P_FlashPal(p, PAL_MIXUP, 4)
				P_InstaThrust(s, s.angle, 0)
				P_SpawnMobj(s.x, s.y, s.z, MT_BURSTLIGHT)
				s.state = S_PLAY_HMSCOMBO2
			elseif p.starthmscombo == 63
				s.bhlcamtimer = 130
				S_StartSound(s, sfx_s3ka0)
				P_FlashPal(p, 3, 3)
				s.finalburstwave = P_SpawnMobj(s.x, s.y, s.z-5*FRACUNIT, MT_BURSTWAVE)
				s.finalburstwave.color = SKINCOLOR_RED
			elseif p.starthmscombo == 45
				s.bhlcamtimer = 30
				p.camerascale = FRACUNIT*4
				S_StartSound(t, sfx_s3k9c)
				S_StartSound(s, sfx_beeyow)
			 end
			    if p.starthmscombo == 15
				p.camerascale = FRACUNIT
				s.bhlcamtimer = 0
				A_SMSquake(s, 25*FRACUNIT, 7, 21022)
				S_StartSound(t, sfx_s3k81)
				P_FlashPal(p, 4, 4)
				S_StartSound(s, sfx_pwbmb)
				S_StartSound(t, sfx_s3k54)

				p.pillarblast7 = P_SpawnMobj(s.x+FixedMul(-5*FRACUNIT, cos(s.angle)), s.y+FixedMul(-5*FRACUNIT, sin(s.angle)), s.z, MT_HMSLIPILLAR)
				p.pillarblast7.scalespeed = 30000
				p.pillarblast7.fuse = 90
				p.pillarblast7.target = s
				A_ChangeColorAbsolute(p.pillarblast7, 0, SKINCOLOR_SUPERGOLD3)
	    	 		for m in mobjs.iterate(mobjs)
						if ((m.flags & MF_ENEMY) or (m.flags & MF_BOSS))
						and m.health
						and not m.hmscombod
						and not (m == t)
							if ((FixedHypot(m.x-p.pillarblast7.x, m.y-p.pillarblast7.y)) < 3200*FRACUNIT)
							P_KillMobj(m, p.pillarblast7, s)
							end
						end
						if G_GametypeHasSpectators()
						and m.player and m.health
						and not m.hmscombod
						and not m.player.hypermysticsonic
						and not (m.player.ctfteam and (m.player.ctfteam == p.ctfteam))
							if ((FixedHypot(m.x-p.pillarblast7.x, m.y-p.pillarblast7.y)) < 2800*FRACUNIT)
							P_DamageMobj(m, p.pillarblast7, s)
							P_InstaThrust(m, m.angle, -10*FRACUNIT)
							P_SetObjectMomZ(m, 24*FRACUNIT)
							end
						end
	    	 		end

				p.pillarblast = P_SpawnMobj(s.x+400*FRACUNIT, s.y+400*FRACUNIT, s.z-100*FRACUNIT, MT_HMSLIPILLAR)
				A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_BONE)
				p.pillarblast = P_SpawnMobj(s.x-400*FRACUNIT, s.y-400*FRACUNIT, s.z-100*FRACUNIT, MT_HMSLIPILLAR)
				A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_BONE)

				p.pillarblast = P_SpawnMobj(s.x-400*FRACUNIT, s.y+400*FRACUNIT, s.z-100*FRACUNIT, MT_HMSLIPILLAR)
				A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_BONE)
				p.pillarblast = P_SpawnMobj(s.x+400*FRACUNIT, s.y-400*FRACUNIT, s.z-100*FRACUNIT, MT_HMSLIPILLAR)
				A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_BONE)

				p.pillarblast = P_SpawnMobj(s.x, s.y+400*FRACUNIT,s.z-100*FRACUNIT, MT_HMSLIPILLAR)
				A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_SUPERGOLD3)
				p.pillarblast = P_SpawnMobj(s.x, s.y-400*FRACUNIT, s.z-100*FRACUNIT, MT_HMSLIPILLAR)
				A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_SUPERGOLD3)

				p.pillarblast = P_SpawnMobj(s.x+400*FRACUNIT, s.y, s.z-100*FRACUNIT, MT_HMSLIPILLAR)
				A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_SUPERGOLD3)
				p.pillarblast = P_SpawnMobj(s.x-400*FRACUNIT, s.y, s.z-100*FRACUNIT, MT_HMSLIPILLAR)
				A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_SUPERGOLD3)

				t.finalburstwave = P_SpawnMobj(t.x, t.y, t.z-10*FRACUNIT, MT_BURSTWAVE)
				t.finalburstwave.color = SKINCOLOR_RED

			    elseif p.starthmscombo == 7
				S_StartSound(s, sfx_s3k54)

				p.pillarblast = P_SpawnMobj(s.x+1250*FRACUNIT, s.y+1250*FRACUNIT, s.z-1000*FRACUNIT, MT_HMSLIPILLAR)
				A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_BONE)
				p.pillarblast = P_SpawnMobj(s.x-1250*FRACUNIT, s.y-1250*FRACUNIT, s.z-1000*FRACUNIT, MT_HMSLIPILLAR)
				A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_BONE)

				p.pillarblast = P_SpawnMobj(s.x-1250*FRACUNIT, s.y+1250*FRACUNIT, s.z-1000*FRACUNIT, MT_HMSLIPILLAR)
				A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_BONE)
				p.pillarblast = P_SpawnMobj(s.x+1250*FRACUNIT, s.y-1250*FRACUNIT, s.z-1000*FRACUNIT, MT_HMSLIPILLAR)
				A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_BONE)

				p.pillarblast = P_SpawnMobj(s.x, s.y+1250*FRACUNIT, s.z-1000*FRACUNIT, MT_HMSLIPILLAR)
				A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_SUPERGOLD3)
				p.pillarblast = P_SpawnMobj(s.x, s.y-1250*FRACUNIT, s.z-1000*FRACUNIT, MT_HMSLIPILLAR)
				A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_SUPERGOLD3)

				p.pillarblast = P_SpawnMobj(s.x+1250*FRACUNIT, s.y, s.z-1000*FRACUNIT, MT_HMSLIPILLAR)
				A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_SUPERGOLD3)
				p.pillarblast = P_SpawnMobj(s.x-1250*FRACUNIT, s.y, s.z-1000*FRACUNIT, MT_HMSLIPILLAR)
				A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_SUPERGOLD3)

			    elseif p.starthmscombo == 2
					if not t.hmscombopreflags == nil
					t.flags = t.hmscombopreflags
					t.rollangle = 0
 					t.flags = $|MF_NOCLIPTHING
					end
		//		if (t.type == MT_METALSONIC_BATTLE) and t.health
		//		print("He's still here, boys")
		//		end
				t.finalburstwave = P_SpawnMobj(t.x, t.y, t.z-5*FRACUNIT, MT_BURSTWAVE)
				t.finalburstwave.color = SKINCOLOR_RED

				S_StartSound(t, sfx_s3k54)

				p.pillarblast = P_SpawnMobj(s.x+2600*FRACUNIT, s.y+2600*FRACUNIT, s.z, MT_HMSLIPILLAR)
				A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_BONE)
				p.pillarblast = P_SpawnMobj(s.x-2600*FRACUNIT, s.y-2600*FRACUNIT, s.z, MT_HMSLIPILLAR)
				A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_BONE)

				p.pillarblast = P_SpawnMobj(s.x-2600*FRACUNIT, s.y+2600*FRACUNIT, s.z, MT_HMSLIPILLAR)
				A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_BONE)
				p.pillarblast = P_SpawnMobj(s.x+2600*FRACUNIT, s.y-2600*FRACUNIT, s.z, MT_HMSLIPILLAR)
				A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_BONE)

				p.pillarblast = P_SpawnMobj(s.x, s.y+2600*FRACUNIT, s.z, MT_HMSLIPILLAR)
				A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_SUPERGOLD4)
				p.pillarblast = P_SpawnMobj(s.x, s.y-2600*FRACUNIT, s.z, MT_HMSLIPILLAR)
				A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_SUPERGOLD3)

				p.pillarblast = P_SpawnMobj(s.x+2600*FRACUNIT, s.y, s.z, MT_HMSLIPILLAR)
				A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_SUPERGOLD4)
				p.pillarblast = P_SpawnMobj(s.x-2600*FRACUNIT, s.y, s.z, MT_HMSLIPILLAR)
				A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_SUPERGOLD3)

			    end
				if (p.starthmscombo == 1 or (p.rings <= 1))
				s.state = S_PLAY_WALK
				s.flags = $ & ~MF_NOCLIPTHING & ~MF_BOUNCE
				P_SpawnMobj(s.x, s.y, s.z, MT_SMSGROUNDBOOST)
				P_SetObjectMomZ(s, 8*FRACUNIT)
				P_AddPlayerScore(p, 100)
					if s.hmsspint2 and s.hmsspint2.health and not (s.hmsspint2.info.mass == 2006) and not (s.hmsspint2.player and s.hmsspint2.player.hypermysticsonic)
					and not (s.hmsspint2.type == MT_CRUSHSTACEAN) and not (s.hmsspint2.type == MT_BANPYURA) //These two crash the game for some reason.
					s.hmsspint2.rollangle = 0
							if (s.hmsspint2.player and s.hmsspint2.player.ctfnamecolor and p.ctfnamecolor)
							P_PlayerFlagBurst(s.hmsspint2.player)
							print("RIP: "+s.hmsspint2.player.ctfnamecolor+". You will be missed. But not by "+p.ctfnamecolor+", who clearly hates you.")
							end
							if G_PlatformGametype()
								P_KillMobj(s.hmsspint2, nil, s)
							else
								P_KillMobj(s.hmsspint2)
							end
					end
					if (p.rings <= 1)
					P_GivePlayerRings(p, -2)
					end
				end
		     end
			 if s.hmsspinclosest
			 s.hmsspinclosest = nil
			 end
			 if p.spectator
			 p.hypermysticsonic = 0
			 end

		else
				if s.hmscarryset
				s.hmscarryset = false
				p.pflags = $ & ~PF_CANCARRY
				end
				if (p.accelstart > 138)
				p.accelstart = 114
				end
				if (p.pflags & PF_GODMODE) and p.hmsgodmode
				p.pflags = $ & ~PF_GODMODE
				p.hmsgodmode = false
				end
				if not (p.maxdash == 147*FRACUNIT)
				and not p.gotflag
				p.maxdash = 147*FRACUNIT
				end
				if not (p.powers[pw_sneakers] and (G_PlatformGametype() and not s.battlemodsms))
					if not (p.powers[pw_shield] == (SH_WHIRLWIND) or p.powers[pw_shield] == (SH_WHIRLWIND|SH_FIREFLOWER))
					and not (p.jumpfactor == FRACUNIT)
					p.jumpfactor = FRACUNIT
					end
				end
		end

//This is HMS' boost-flight.
//Thank you for joining Hyper Mystic airlines!

		if p.hmswarpcooldown //This has nothing to do with this script, but we'll use it for convenience.
		and not (p.cmd.buttons & BT_WEAPONPREV and p.hmswarpcooldown == 1) //No constant warping!
		p.hmswarpcooldown = $-1
		end
		if (p.hypermysticsonic and p.hypermysticsonic > 40) //Only HMS, of course.
		//Ok, pay attention, game! When you're HMS in match or CTF, drain rings at x12 speed!
		//If in any other gametype, drain rings at double speed!
				p.charflags = $|SF_CANBUSTWALLS
				if p.hmsthrownnorise
					if not (p.cmd.buttons & BT_TOSSFLAG) and not (p.cmd.buttons & BT_WEAPONPREV)
					p.hmsthrownnorise = false
					end
				end
				if (p.pflags & PF_JUMPED)
					if not s.hmsjumpgfx and not (s.z > s.floorz+27*FRACUNIT)
						if not p.smsgraphix
						s.hjg1 = P_SpawnMobj(s.x, s.y, s.z-20*FRACUNIT, MT_HMSWAVEAURA)
						s.hjg1.dustwave = 1
						s.hjg1.sprite = SPR_SMMK
						s.hjg1.frame = 3
						s.hjg1.target = s
						s.hjg1.fuse = 15
						s.hjg1.scale = s.scale
						s.hjg1.destscale = $*2
						end
						A_SMSSTOMPSMOKE(s, 60, MT_SPINDUST, nil, nil, 2*FRACUNIT)
						A_SMSSTOMPQUAKE(s, 45, 14, FRACUNIT, 0, 0, 0, 0, SKINCOLOR_SUPERGOLD3)
						A_SMSSTOMPQUAKE(s, 80, 18, 2*FRACUNIT, 0, ANG20, 0, 0, SKINCOLOR_SUPERSILVER4)
						s.hjg = P_SpawnGhostMobj(s)
						s.hjg.sprite = SPR_HMSO //Use the spring frame specifically for this.
						s.hjg.frame = H|FF_FULLBRIGHT|TR_TRANS50
					end
					s.hmsjumpgfx = true
				elseif s.hmsjumpgfx
				s.hmsjumpgfx = false
    			end

			/*	if (s.eflags & MFE_JUSTHITFLOOR)
					A_SMSSTOMPSMOKE(s, 30, MT_HMSLIGHTNING1)
					S_StartSound(s, sfx_s3k7c) //Start out sound
				end */

				if p.rings and (leveltime % 35 == 0)
					P_GivePlayerRings(p, -1)
				end
				if G_PlatformGametype() and not s.battlemodsms
				and not (p.hmsrushactive and (gametype == GT_COOP))
					if (leveltime % 35 == 18)
					P_GivePlayerRings(p, -1)
					p.hms_drain = 0
					end
				elseif (p.hms_drain > 2)
					if (p.rings > 300) and not (p.hmsrushactive and (gametype == GT_COOP))
					p.rings = 300
					end
					P_GivePlayerRings(p, -1)
					p.hms_drain = 0
				end

				if (p.cmd.buttons & BT_USE) //Press spin in midair to boost!
				  if not P_IsObjectOnGround(s) //If we could use it on the ground, it'd collide with the spindash.
				  and not (p.pflags & (PF_STARTDASH))
				  and not p.powers[pw_carry]
				  and not (s.state == S_HMSBLACKHOLE)
				  and not (p.novafire > 37) and not (s.hmsgalaxystorm > 102)
				  and not p.smsdivetimer and not s.hmsforcedspin
				  and not p.hmswarpcooldown
				  and not p.starthmscombo
					if (s.frame == 1048577) or (s.state == S_PLAY_SPRING)
					s.state = S_PLAY_RUN
					end
					if not (p.cmd.buttons & BT_CUSTOM1) and not (s.hmsusebuffer and s.hmsusebuffer < 4)
						if not p.hmsdash
							s.hmsspinpass = 0
							s.hmsspinfreeze = true
							s.hmsroflstomped = false
							A_SMSquake(s, 15*FRACUNIT, 8, 1022, true)
							S_StartSound(s, sfx_hmsfly)
							p.hmsdash = 1
							s.hmsusebuffer = 4
							if not s.airboostroll
								if s.hmsrotateright
								s.hmsrotateright = false
								else
								s.hmsrotateright = true
								end
							s.airboostroll = 9
							s.rollangle = 0
							end
						elseif p.hmsdash and (p.hmsdash > 1)
							p.hmsdash = 1
						end
						if not (p.lddiscount and (p.lddiscount == 3 or p.lddiscount == 1))
						P_InstaThrust(s, s.angle, FixedMul(55*FRACUNIT, s.scale)+35*FRACUNIT)
						end
					else //Press custom1 WHILE airboosting to--AAAAAA!!! (Maybe don't?)
						if not p.hmsdash
							S_StartSound(s, sfx_hmsfly)
							p.hmsdash = 1
						end
						if not p.hmsdash
						or p.hmsdash == 1
							s.hmsspinfreeze = true
							s.hmsspinpass = 0
							s.hmsroflstomped = false
							S_StartSound(s, sfx_smach)
							if not s.airboostroll
								if s.hmsrotateright
								s.hmsrotateright = false
								else
								s.hmsrotateright = true
								end
							s.airboostroll = 12
							s.rollangle = 0
							end
							s.hudboost = 1
							if not (p.cmd.buttons & BT_CUSTOM1) //You're using the double-tap method.
								p.sms_autoboosthold = true
							end
							p.hmsdash = 2
							p.smsradialboosteffect = P_SpawnMobj(s.x, s.y, s.z, MT_RADIALBOOST)
							p.smsradialboosteffect.target = s
							A_SMSquake(s, 66*FRACUNIT, 11, 2022)
						end
						if not (p.lddiscount and (p.lddiscount == 3 or p.lddiscount == 1))
							P_InstaThrust(s, s.angle, FixedMul(190*FRACUNIT, s.scale)+60*FRACUNIT)
						end
						s.hmsmwh = 1
					end
					if (p.pflags & PF_SPINNING)
						p.pflags = $ & ~PF_SPINNING
					end	
					if (p.pflags & PF_DIRECTIONCHAR)
						s.forcesmsangletimer = 6
						s.forcesmsangle = s.angle
					end
					if (p.speed > FixedMul(23*FRACUNIT, s.scale)) //When you reach speeds above 250, stick to it.
						s.sprintlin = P_SpawnGhostMobj(s)
						s.sprintlin.rollangle = s.rollangle
						if s.hmsspinpass and s.hmsspinang != nil
						s.sprintlin.angle = s.hmsspinang
						end
						
					end
				/*	if (s.state == S_PLAY_WALK or s.state == S_PLAY_STND) //Bugfix for stand-boosting.
					and (p.speed > FixedMul(35*FRACUNIT, s.scale))
					s.state = S_PLAY_RUN
					end */
				  end
				elseif p.hmsdash
					p.hmsdash = 0
				end

//Rise skywards in the blink of an eye! Kind of wish I had a better 
//button for this than "toss flag", a button you'd never use otherwise.
//I'll make a jump tap alternative for the simpletons, maybe.

			if s.hms_readyriseboost
			s.hms_readyriseboost = $-1
			end
			if s.hms_jumprisen and not p.starthmscombo
				if (s.momz > 2*FRACUNIT or s.momz < -2*FRACUNIT)
					if (leveltime % 2 == 0) and not (p.smsgraphix and p.smsgraphix == 2)
					A_SMSSTOMPSMOKE(s, P_RandomRange(5, 20), MT_NIGHTSPARKLE, P_RandomRange(1, 75)*FRACUNIT, nil, nil, SKINCOLOR_SUPERGOLD5)
					end
					if s.jumprsmoke and s.jumprsmoke.valid and s.jumprsmoke.health
					s.jumprsmoke.fed = 2
					else
					s.jumprsmoke = P_SpawnMobj(s.x, s.y, s.z, MT_HMSRISEAURA)
					s.jumprsmoke.initscale = s.scale*3/2
					s.jumprsmoke.eflags = s.eflags
					s.jumprsmoke.target = s
					s.jumprsmoke.fed = 2
					end
					s.sprintlin = P_SpawnGhostMobj(s)
					s.sprintlin.rollangle = s.rollangle
					if s.hmsspinang != nil and s.hmsspinpass
					s.sprintlin.angle = s.hmsspinang
					end
					if s.momz
					s.sprintlin.z = $-((24*FRACUNIT)*(P_MobjFlip(s)))
					end
				end
				if (s.hms_jumprisen == 3)
				p.pflags = $ & ~PF_STARTJUMP
				S_StartSound(s, sfx_kc5b)
				if not s.haltthespam
				and not p.smsgraphix
				s.novawave = P_SpawnMobj(s.x, s.y, s.z, MT_HMSNOVAWAVE) 
				s.novawave.scale = s.scale*10/P_RandomRange(9,15)	
				A_SMSSTOMPSMOKE(s, 20, MT_ENERGYBALL, 200)
				end
				P_SetObjectMomZ(s, 8*FRACUNIT, true) //Spam the button to rise even faster.
				s.hms_jumprisen = 2
				s.haltthespam = 2
					if (s.momz > 0) and not (s.eflags & MFE_VERTICALFLIP)
					or (s.momz < 0) and (s.eflags & MFE_VERTICALFLIP)
						A_SMSquake(s, s.momz/2, (s.momz/FRACUNIT)/12)
					end
				elseif s.hms_jumprisen
				s.hms_jumprisen = $-1
				end
			end
			if (p.cmd.buttons & BT_JUMP)
				if P_IsObjectOnGround(s)
					s.hms_jumphold = 10
					s.hms_readyriseboost = 0
					s.hms_jumprisen = 0
				else
					if s.hms_jumphold == nil
					s.hms_jumphold = 1
					else
					s.hms_jumphold = $+1
					end
				end
			elseif s.hms_jumphold
				if P_IsObjectOnGround(s)
				s.hms_jumphold = 10
				s.hms_readyriseboost = 0 
				s.hms_jumprisen = 0
				else
				s.hms_jumphold = 0
				end
			end
			if (p.cmd.buttons & BT_JUMP) or (p.cmd.buttons & BT_TOSSFLAG) //Toss flag is more responsive, while jump is simpler for some control layouts.
				if (p.pflags & PF_JUMPED)
				and not (p.cmd.buttons & BT_CUSTOM2) //No stomping and rising at the same time!
				and not (p.pflags & (PF_STASIS|PF_SLIDING))
				and not p.powers[pw_carry] and not p.hmsthrownnorise
				and not p.smsdivetimer 
				and not (p.hmsblackhole > 60)
				and ((p.cmd.buttons & BT_TOSSFLAG) or not (s.hms_jumphold > 2))
				and not (p.novafire and p.novafire > 37) and not (s.hmsgalaxystorm > 105)
				and not (p.hmswarpcooldown)
				and not p.starthmscombo
					if not s.hms_readyriseboost and not (p.cmd.buttons & BT_TOSSFLAG)
						s.hms_readyriseboost = 7
						s.hms_jumphold = 10
					elseif s.hms_readyriseboost or (p.cmd.buttons & BT_TOSSFLAG)
						if (p.cmd.buttons & BT_TOSSFLAG)
						s.hms_readyriseboost = 0
						s.hms_jumphold = 10
						else
						s.hms_jumphold = 0
						s.hms_readyriseboost = 2
						end
						if not s.hms_jumprisen
							s.hms_jumprisen = 3
						else
							s.hms_jumprisen = 2
						end
					if s.momz and not s.hmsspinfreeze
					s.hmsspinpass = 16
					end
					s.hmgodticket = true
					s.hmsstompsfx = false
						if not (s.momz*P_MobjFlip(s) >= FixedMul(FRACUNIT*40, s.scale)) //Don't need to set this if you're already going over 40.
						P_SetObjectMomZ(s, FixedMul(40*FRACUNIT, s.scale))
						end
					end
				end
			end

			p.charability = CA_GLIDEANDCLIMB //No exceptions ever. When HMS, no thokking.
				
			if not P_IsObjectOnGround(s)
				if (p.cmd.buttons & BT_JUMP) and (p.pflags & PF_JUMPED) 
				and not ( ((p.pflags & PF_STARTJUMP) and (s.momz*P_MobjFlip(s)) > FixedMul(FRACUNIT, s.scale))  or (p.sms_jumphold > 1))
				and not s.hms_jumprisen and not p.powers[pw_nocontrol] //Recreating the old superfly.
				and not (p.pflags & PF_STARTDASH)
				and not p.powers[pw_carry]
				and not (s.momz*(P_MobjFlip(s)) > FixedMul(12*FRACUNIT, s.scale))
				and not (s.state == S_HMSBLACKHOLE)
				and not (p.novafire and p.novafire > 37) and not (s.hmsgalaxystorm > 105)
				and not p.hmswarpcooldown
				and not p.starthmscombo
				and not p.exiting
					if (s.state == S_PLAY_SPRING)
					s.state = S_PLAY_RUN
					end
				p.sms_jumphold = 0
				s.hmsstompsfx = false
						if (p.cmd.buttons & BT_FIRENORMAL)
						and (s.z > s.ceilingz-120*FRACUNIT) and (s.floorz < s.ceilingz-300*FRACUNIT) //Not in extremely tight spaces.
						s.momz = 0
						else
						P_SetObjectMomZ(s, 7*FRACUNIT, false)
						end
				p.pflags = $ & ~PF_STARTJUMP
				end			
			end

//Alongside HMS' instant transmi---I mean instant movement, he can also do a short teleport/
//a short warp. It checks whether the missile blew up or not and then dashes you there!

		      if not (s.state == S_HMS_ATOMLAND) // and not s.nohmswarpforawhile
				if (p.cmd.buttons & BT_WEAPONPREV) and not (p.cmd.buttons & BT_WEAPONNEXT) and not (p.weaponprevhold > 1)
					if not p.powers[pw_carry]
					and not (p.novafire > 37)
					and not p.smsdivetimer and not p.hmsthrownnorise
					and not p.starthmscombo
					and not p.powers[pw_nocontrol]
					and not (p.hmsblackhole > 60) and not (s.hmsgalaxystorm > 105)
					and not (p.hmswarpcooldown)
						if P_IsObjectOnGround(s) and (p.pflags & PF_SPINNING) and (s.z < s.floorz)
						s.z = s.floorz //Fix for lava stuckage.
						end
					//	s.hmswshoot = P_SpawnMobj(s.x+FixedMul(110*FRACUNIT, cos(s.angle)), s.y+FixedMul(110*FRACUNIT, sin(s.angle)), s.z, MT_HMSWARPPOINT)
						s.hmswshoot = P_SpawnMobj(s.x, s.y, s.z, MT_HMSWARPPOINT)
						s.hmswshoot.angle = s.angle
						s.hmswshoot.hmst = s
						s.hmswshoot.ogz = s.hmswshoot.z
						s.hmswshoot.scale = s.scale
						P_InstaThrust(s.hmswshoot, s.angle, 150*FRACUNIT)
						P_SpawnMobj(s.x, s.y, s.z, MT_HMSWARPPOINTRETURN)
						P_SetObjectMomZ(s, 0)
						p.hmswarpcooldown = 11
						if (p.pflags  & PF_SPINNING)
						s.forcewarp1 = 2
						p.pflags = $ & ~PF_SPINNING
						end
						s.state = S_HMS_INSTANTWARP1
						s.ghs = P_SpawnGhostMobj(s)
						s.ghs.tics = 20
						s.ghs.color = SKINCOLOR_SUPERSKY5
						s.ghs.scalespeed = $*3
						s.ghs.destscale = $*20
						P_InstaThrust(s, s.angle, 0) //Cancel all momentum.
					end
				elseif s.hmsgcheck
					if P_IsObjectOnGround(s) and (p.pflags & PF_JUMPED)
					p.pflags = $ & ~PF_JUMPED & ~PF_JUMPDOWN
					end
					s.hmsgcheck = false
				end
				if s.forcewarp1
					if (s.forcewarp1 == 1)
					s.state = S_HMS_INSTANTWARP2
					else
					s.state = S_HMS_INSTANTWARP1
					end
					p.pflags = $ & ~PF_SPINNING
				s.forcewarp1 = $-1
				end
				if s.forcewarp2
					if (s.forcewarp2 == 1)
					s.state = S_HMS_INSTANTWARP3
					else
					s.state = S_HMS_INSTANTWARP2
					end
					p.pflags = $ & ~PF_SPINNING
				s.forcewarp2 = $-1
				end
				if s.state == S_HMS_INSTANTWARP2
					
					if (p.pflags  & PF_SPINNING)
					s.forcewarp2 = 2
					p.pflags = $ & ~PF_SPINNING
					end
					if not (p.pflags & PF_JUMPED)
					p.pflags = $|PF_JUMPED
					end
					A_FindTarget (s, MT_HMSWARPPOINT, 0)
					if (s.target and s.target.type == MT_HMSWARPPOINT) and not s.target.dontwarptome
						local secheck = R_PointInSubsector(s.target.x, s.target.y).sector
						for fof in secheck.ffloors()
							if (fof.flags & FF_EXISTS) and ((fof.flags & FF_STRONGBUST) or (fof.flags & FF_BUSTUP))
							and not (s.target.z-99*FRACUNIT >= fof.topheight)
							and not (s.target.z+99*FRACUNIT < fof.bottomheight)
							EV_CrumbleChain(secheck, fof)
							end
						end			
						
						if P_CheckPosition(s, s.target.x, s.target.y, s.target.z)
						and not (secheck.ceilingheight-secheck.floorheight < (P_GetPlayerSpinHeight(p)))
						and not s.target.dontwarptome
							S_StartSound(s, sfx_s3k83)
                            P_NukeEnemies(s, s, FixedMul(850*FRACUNIT, s.scale))
							if (s.subsector.sector == s.target.subsector.sector)
							and s.subsector.sector.floorpic == s.target.subsector.sector.floorpic //Same sector...be careful.
							and not s.target.ihavetped
							s.z = s.target.z
							P_TryMove(s, s.target.x, s.target.y, true) //Fake warp! (to prevent us clipping through walls)
							else
							P_TeleportMove(s, s.target.x, s.target.y, s.target.z) //True Warp!
							end
							P_SetObjectMomZ(s, 0)
							P_InstaThrust(s, s.angle, 0)
							P_FlashPal(p, 1, 4) //Brings up a bright white flash.
							s.ghs = P_SpawnGhostMobj(s)
							s.ghs.tics = 20
							s.ghs.color = SKINCOLOR_RED
							s.ghs.scalespeed = $*3
							s.ghs.destscale = $*20
						else
							P_KillMobj(s.target)
						end
						if s.tics == 2
						s.novawave = P_SpawnMobj(s.x, s.y, s.z, MT_HMSNOVAWAVE)
						s.novawave.scale = s.scale
						s.novawave = P_SpawnMobj(s.x, s.y, s.z, MT_HMSNOVAWAVE)
						s.novawave.scale = s.scale
						s.novawave.rollangle = ANGLE_90
						s.novawave = P_SpawnMobj(s.x, s.y, s.z, MT_HMSNOVAWAVE)
						s.novawave.scale = s.scale
						s.novawave.rollerwave = 16*FRACUNIT
						end
					end
				elseif (s.state == S_HMS_INSTANTWARP3
				or (p.hmswarpcooldown == 2 or p.hmswarpcooldown == 1))
				and not p.smsdivetimer and not s.nohmswarpforawhile
				
					if not P_IsObjectOnGround(s)
					P_SetObjectMomZ(s, 0)
					else
					p.pflags = $|PF_JUMPDOWN
					end
				P_InstaThrust(s, s.angle, 0)
				s.hmsgcheck = true
					local secheck = R_PointInSubsector(s.x, s.y).sector
					if (secheck.ceilingheight-secheck.floorheight < (P_GetPlayerSpinHeight(p)))
					or (p.pflags & PF_SPINNING)
					or not secheck
					A_FindTarget (s, MT_HMSWARPPOINTRETURN, 0)
						if (s.target and s.target.type == MT_HMSWARPPOINTRETURN)
						P_TeleportMove(s, s.target.x, s.target.y, s.target.z) //Warp back!
						p.pflags = $ & ~PF_SPINNING
						end
					end
					if p.hmswarpcooldown == 2
						s.novawave = P_SpawnMobj(s.x, s.y, s.z, MT_HMSNOVAWAVE)
						s.novawave.scale = s.scale
						s.novawave = P_SpawnMobj(s.x, s.y, s.z, MT_HMSNOVAWAVE)
						s.novawave.scale = s.scale
						s.novawave.rollangle = ANGLE_90
						s.novawave = P_SpawnMobj(s.x, s.y, s.z, MT_HMSNOVAWAVE)
						s.novawave.scale = s.scale
						s.novawave.rollerwave = -16*FRACUNIT
					end
				end
		      end

//Instantly flash to any other player present! Works even in match, but with a delay, ofc!

		      if (netgame or splitscreen) //You don't need this anywhere else.
		      and not p.objectplacer
			if (p.warpedtoguy >= 31)
			p.warpedtoguy = 0
			end

			local hmstargetplayer = players[tonumber(p.warpedtoguy)] //One of the rare times you'll see me using local variables
			if (p.warpedtoguy >= 0 and p.warpedtoguy < 31)
				if not (hmstargetplayer and hmstargetplayer.mo and hmstargetplayer.mo.health)
				or (hmstargetplayer != nil and hmstargetplayer.mo == s)
					p.warpedtoguy = $+1
					p.freezesel = true
				else
					p.freezesel = false
					if (s.state == S_HMS_INSTANTMOVE1)
						s.angle = (R_PointToAngle2(s.x, s.y, hmstargetplayer.mo.x, hmstargetplayer.mo.y))
					end
				end
			else
				p.freezesel = true
			end
				if (p.cmd.buttons & BT_WEAPONNEXT)
				and not (p.pflags & (PF_SPINNING))
				and not p.powers[pw_carry]
				and not p.hms_instamove
				and not p.powers[pw_nocontrol]
				and not (p.hmsblackhole > 60)
				and not (p.novafire > 37)
				and not p.smsdivetimer
					s.state = S_HMS_INSTANTMOVE1
					p.hmswarpcooldown = 7
				end

				if (hmstargetplayer and hmstargetplayer.mo and hmstargetplayer.mo.health)
				and not (hmstargetplayer and hmstargetplayer.mo == s)
				p.getpersonname = hmstargetplayer.mo.player.name
				else
				p.getpersonname = "-"
				end

				if (s.state == S_HMS_INSTANTMOVE1)
					P_SetObjectMomZ(s, 0)
					P_InstaThrust(s, s.angle, 0) //Cancel all momentum.
					p.normalspeed = 0 //Why is there a stupid glitch that lets you slowly move anyway...?
					p.pflags = $ & ~PF_JUMPED & ~PF_SPINNING

					if (p.cmd.buttons & BT_WEAPONNEXT)
					and not p.freezesel
					and not p.selectcooldown


						if ((p.cmd.buttons & BT_CAMRIGHT) or (p.cmd.sidemove > 0))
							if not (p.warpedtoguy and p.warpedtoguy > 30)
							p.warpedtoguy = $+1
							S_StartSound(s, sfx_rail2)
							p.selectcooldown = 8
							end
						end
						if (p.cmd.buttons & BT_CAMLEFT) or (p.cmd.sidemove < 0)
							if not p.warpedtoguy == nil
							and p.warpedtoguy == 0
							p.warpedtoguy = 31
							end
							if p.warpedtoguy
							and ((p.warpedtoguy > 0) and p.warpedtoguy <= 31) //Prevent it from going into -1.
							p.warpedtoguy = $-1
							S_StartSound(s, sfx_rail2)
							p.selectcooldown = 8
							end
						end
					end
					if not (p.cmd.buttons & BT_WEAPONNEXT)
						if hmstargetplayer and hmstargetplayer.mo and hmstargetplayer.mo.health
						and not (hmstargetplayer.mo == s)
						s.state = S_HMS_INSTANTMOVE2 //Got a target? Then let's go!
						else
						S_StartSound(s, sfx_ngskid)
						p.hms_instamove = 30
						end
					end
					if (p.cmd.buttons & BT_USE)
					and not (p.spinhold and p.spinhold > 1)
						S_StartSound(s, sfx_ngskid)
						p.hms_instamove = 50
					end

				elseif (s.state == S_HMS_INSTANTMOVE2)
				and not p.powers[pw_carry]	
					if hmstargetplayer and hmstargetplayer.mo and hmstargetplayer.mo.health //Do you even exist, bro?
					and not (hmstargetplayer.mo == s)
					and not (p.hms_instamove)
						if not ((G_PlatformGametype() and not s.battlemodsms)) and not (G_GametypeHasTeams() and (p.ctfteam == hmstargetplayer.mo.player.ctfteam))
							if not p.hms_instamovew
								if hmstargetplayer.powers[pw_sneakers] or (hmstargetplayer.mo.skin == "sms")
								p.hms_instamovew = 40 //Get other SMS players quicker.
								hmstargetplayer.mo.eyesareuponyou = 40
								else
								p.hms_instamovew = 66
								hmstargetplayer.mo.eyesareuponyou = 65
								end
                              P_StartQuake(10*FRACUNIT, 75)
							P_NukeEnemies(s, s, 750*FRACUNIT)
							P_FlashPal(hmstargetplayer.mo.player, PAL_NUKE, 8)
							P_FlashPal(p, PAL_NUKE, 8)
							S_StartSound(hmstargetplayer.mo, sfx_bgxpld)
							S_StartSound(hmstargetplayer.mo, sfx_rail2)
							S_StartSound(hmstargetplayer.mo, sfx_litng2)
							S_StartSound(s, sfx_rumble)
							p.pillarblast = P_SpawnMobj(hmstargetplayer.mo.x, hmstargetplayer.mo.y, hmstargetplayer.mo.z, MT_HMSLIPILLAR)
							A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_RED)
							P_SpawnMobj(hmstargetplayer.mo.x, hmstargetplayer.mo.y, hmstargetplayer.mo.z, MT_HMSLIPILLAR)
							P_SpawnMobj(s.x, s.y, s.z+20*FRACUNIT, MT_HMSLIPILLAR)
							A_ChangeColorAbsolute(p.pillarblast, 0, SKINCOLOR_RED)
							p.instalocz = hmstargetplayer.mo.z
							p.instalocx = hmstargetplayer.mo.x
							p.instalocy = hmstargetplayer.mo.y
							p.instalocz = hmstargetplayer.mo.z

							elseif p.hms_instamovew and (p.hms_instamovew > 1)
								if (leveltime % 2 == 0)
								s.novawave = P_SpawnMobj(s.x, s.y, s.z, MT_HMSNOVAWAVE) //Bigger and of the Super Mystic variety this time!
								s.novawave.scale = s.scale*10/P_RandomRange(5, 30)
								s.novawave.rollangle = P_RandomRange(1,359)*ANG1
								s.novawave.color = P_RandomRange(SKINCOLOR_BLACK, SKINCOLOR_SUPERGOLD5)
								end
							
							s.state = S_HMS_INSTANTMOVE2
							p.powers[pw_nocontrol] = 2
							p.novafire = 38
							P_SetObjectMomZ(s, 0)
							P_InstaThrust(s, s.angle, 0)
							p.normalspeed = 0
							p.pflags = $ & ~PF_JUMPED
							end
						end
						if hmstargetplayer and (((G_PlatformGametype() and not s.battlemodsms)) or (G_GametypeHasTeams() and (p.ctfteam == hmstargetplayer.mo.player.ctfteam))
						or (p.hms_instamovew and (p.hms_instamovew == 1))) 
						P_FlashPal(p, 1, 4)
						P_FlashPal(hmstargetplayer, 1, 4)
						s.ghs = P_SpawnGhostMobj(s)
						s.ghs.sprite = SPR_HMSO
						s.ghs.frame = I|FF_FULLBRIGHT|TR_TRANS20
						s.ghs.tics = 60
						s.ghs.color = SKINCOLOR_SUPERSKY5
						s.ghs.flags2 = $ & ~MF2_SHADOW
						s.ghs.scalespeed = $*5
						s.ghs.destscale = $*30
							if ((G_PlatformGametype() and not s.battlemodsms)) or (G_GametypeHasTeams() and (p.ctfteam == hmstargetplayer.mo.player.ctfteam))
							P_TeleportMove(s, hmstargetplayer.mo.x, hmstargetplayer.mo.y, hmstargetplayer.mo.z)
							elseif (p.instalocx != nil) and p.instalocy != nil and p.instalocz != nil
							P_TeleportMove(s, p.instalocx, p.instalocy, p.instalocz)
							p.instalocx = nil
							p.instalocy = nil
							p.instalocz = nil
							end
						S_StopSound(s) //waaaaaa
						P_SetObjectMomZ(s, 2*FRACUNIT)
						S_StartSound(s, sfx_s3k83)
						s.angle = hmstargetplayer.mo.angle
						s.eflags = hmstargetplayer.mo.eflags
						s.ghs = P_SpawnGhostMobj(s)
						s.ghs.sprite = SPR_HMSO
						s.ghs.frame = I|FF_FULLBRIGHT|TR_TRANS20
						s.ghs.tics = 50
						s.ghs.color = SKINCOLOR_RED
						s.ghs.flags2 = $ & ~MF2_SHADOW
						s.ghs.scalespeed = $*5
						s.ghs.destscale = $*30
						P_InstaThrust(s, s.angle, 0)
						P_NukeEnemies(s, s, 1234*FRACUNIT) //Show up with a bang!
						
						
						s.novawave = P_SpawnMobj(s.x, s.y, s.z, MT_HMSNOVAWAVE) //Bigger and of the Super Mystic variety this time!
						s.novawave.scale = s.scale*2
						s.novawave.color = SKINCOLOR_CRIMSON
						s.novawave = P_SpawnMobj(s.x, s.y, s.z, MT_HMSNOVAWAVE)
						s.novawave.scale = s.scale*2
						s.novawave.color = SKINCOLOR_SUPERGOLD5
						s.novawave.rollangle = ANGLE_90
						s.novawave = P_SpawnMobj(s.x, s.y, s.z, MT_HMSNOVAWAVE)
						s.novawave.scale = s.scale*2
						s.novawave.rollerwave = 16*FRACUNIT
						s.novawave.color = SKINCOLOR_EMERALD
						
						
						p.hms_instamove = 37
						p.hms_instamovew = 0

							if not (hmstargetplayer.mo.flags2 & MF2_TWOD) //If your target isn't in 2D, remove your 2D setting.
							s.flags2 = $ & ~MF2_TWOD
							else
							s.flags2 = $|MF2_TWOD
							end
							if not (hmstargetplayer.mo.flags2 & MF2_OBJECTFLIP)
							s.flags2 = $ & ~MF2_OBJECTFLIP
							else
							s.flags2 = $|MF2_OBJECTFLIP
							end
						end
					end
				end
  		      end
			  if s.hmgodmticket //godmatch-ticket, floating orbs and sparks.
			  	if not (p.smsgraphix and p.smsgraphix == 2)
			  		if ((P_RandomRange(1, 2)) == 1)
					p.zmp = P_SpawnMobj(s.x+((P_RandomRange(FixedMul(-2500, s.scale), FixedMul(2500, s.scale)))*FRACUNIT), s.y+((P_RandomRange(FixedMul(-2500, s.scale), FixedMul(2500, s.scale)))*FRACUNIT), s.z+((P_RandomRange(FixedMul(350, s.scale), FixedMul(-200, s.scale)))*FRACUNIT), MT_THOK)
					else				
					p.zmp = P_SpawnMobj(s.x+((P_RandomRange(FixedMul(-750, s.scale), FixedMul(750, s.scale)))*FRACUNIT), s.y+((P_RandomRange(FixedMul(-750, s.scale), FixedMul(750, s.scale)))*FRACUNIT), s.z+((P_RandomRange(FixedMul(40, s.scale), FixedMul(-200, s.scale)))*FRACUNIT), MT_SMSTSPARK)
					end
					if p.zmp
						p.zmp.target = s
						p.zmp.flags = $|MF_NOCLIP|MF_NOCLIPHEIGHT|MF_NOBLOCKMAP
						P_SetObjectMomZ(p.zmp, ((P_RandomRange(2, 6))*FRACUNIT))	
						if (p.zmp.type == MT_THOK)
							p.zmp.flags2 = $|MF2_SHADOW	
							p.zmp.color = SKINCOLOR_WHITE
							p.zmp.scale = s.scale/2
							p.zmp.scalespeed = $/12
							p.zmp.destscale = s.scale*2
							p.zmp.tics = 80
						end
						if (p.zmp.type == MT_SMSTSPARK)	
							p.zmp.state = S_SMSTSPARK2
							p.zmp.color = P_RandomRange(SKINCOLOR_WHITE, SKINCOLOR_SUPERGOLD5)				
							p.zmp.scale = s.scale*2
							p.zmp.destscale = s.scale*(P_RandomRange(4, 8))
							p.zmp.tics = 40
						end
					end
				end
				s.hmgodmticket = false
			  end
			  if s.hmgodticket //god-ticket, pulsing illusions
			  	if not ((p.hypermysticsonic % 2 == 0) and not P_RandomRange(0,3)) // and not (p.pflags & PF_STARTDASH)
				and not ((p.cmd.buttons & BT_TOSSFLAG) and P_IsObjectOnGround(s) and (p.speed < 5*FRACUNIT))
				and not s.hmsspinpass and not (s.hmsgalaxystorm > 125)
				and not (p.smsgraphix and p.smsgraphix == 2)
					s.spinsmsgr = P_SpawnGhostMobj(s) //God aura's visuals
					s.spinsmsgr.tics = 3
					s.spinsmsgr.scale = s.scale+1000
					s.spinsmsgr.flags = $|MF_NOCLIPHEIGHT|MF_NOCLIP
					s.spinsmsgr.momx = s.momx
					s.spinsmsgr.momy = s.momy
					if not (s.hms_jumprisen and (s.z > s.ceilingz-100*FRACUNIT))
					s.spinsmsgr.momz = s.momz
					end
					s.spinsmsgr.scalespeed = $/2+(P_RandomRange(0, 3000))
					s.spinsmsgr.destscale = s.scale*3
				end
				s.hmgodticket = false
			end
		end
	end
end, MT_PLAYER)

addHook("MapChange", function()
	for z in players.iterate
	z.hmshascome = nil
	end
end)

local function GaxAsteroid(s, planet, star, noroll)
	s.gaxas = P_SpawnMobj(s.x+(P_RandomRange(-100, 100)*s.scale), s.y+(P_RandomRange(-100, 100)*s.scale), s.z+(P_RandomRange(-50, 100)*s.scale), MT_HMSGAXA)
	if s.gaxas and s.gaxas.valid
	local t = s.gaxas
	local cframe = P_RandomRange(1,4)
		t.hitboxspawn = P_SpawnMobj(t.x, t.y, t.z, MT_HMSGAXHB)
		local hb = t.hitboxspawn
		hb.gaxhbtarget = t
		hb.oggax = s
			if s.target
			hb.hmstarget = s.target
			end
			
	//What does the universe bring us today?
		
			if star //Star
			hb.radius = 120*FRACUNIT
			hb.height = 120*FRACUNIT
			t.frame = 5|FF_FULLBRIGHT|TR_TRANS30
			t.color = P_RandomRange(SKINCOLOR_SUPERSILVER4, SKINCOLOR_SUPERGOLD5)
			t.scale = s.scale
			
			elseif planet //Planet
				if noroll
				t.noroll = true
				end
			hb.radius = 430*FRACUNIT
			hb.height = 430*FRACUNIT
				if not (s.target.player and s.target.player.smsgraphix and s.target.player.smsgraphix == 2)
				s.novawave = P_SpawnMobj(s.x, s.y, s.z+P_RandomRange(1, 300)*FRACUNIT, MT_HMSNOVAWAVE)
				s.novawave.scale = s.scale/3
				s.novawave.scalespeed = $*3
				s.novawave.rollangle = s.rollangle
				s.novawave.ghs = P_SpawnGhostMobj(s.novawave)
				s.novawave.ghs.tics = 4
				s.novawave.ghs.rollangle = s.rollangle+ANGLE_90
				end
			t.frame = 6|FF_FULLBRIGHT|TR_TRANS10
			S_StartSound(s, sfx_s3k4e)
			t.scale = s.scale*3/P_RandomRange(14,9)
			t.scalespeed = $*3
			t.destscale = $*2
			
			local planetc = P_RandomRange(1,7)
				if planetc == 1
				t.color = SKINCOLOR_TEAL
				elseif planetc == 2
				t.color = SKINCOLOR_LAVENDER
				elseif planetc == 3
				t.color = SKINCOLOR_GREY
				elseif planetc == 4
				t.color = SKINCOLOR_PERIDOT
				elseif planetc == 5
				t.color = SKINCOLOR_PINK
				elseif planetc == 6
				t.color = SKINCOLOR_AZURE
				else t.color = SKINCOLOR_BLUEBELL
				end
				
			elseif cframe
			
			t.scale = s.scale/10
			t.scalespeed = $*3
			t.destscale = s.scalespeed+1
			hb.radius = 160*FRACUNIT
			hb.height = 160*FRACUNIT
			t.frame = cframe|FF_FULLBRIGHT|TR_TRANS10
			end
			
			t.momx = (FixedMul(FixedDiv(s.x-t.x, 450*FRACUNIT), FixedDiv(132*FRACUNIT, 3*FRACUNIT/2)) )/-6
			t.momy = (FixedMul(FixedDiv(s.y-t.y, 450*FRACUNIT), FixedDiv(132*FRACUNIT, 3*FRACUNIT/2)) )/-6
			t.momz = (FixedMul(FixedDiv(s.z-t.z, 450*FRACUNIT), FixedDiv(132*FRACUNIT, 3*FRACUNIT/2)) )/-8
			if s.target
			t.hmstarget = s.target
			end
	end
end

//HMSGALAXYSTORM Mobjs. Tracker, hitbox, asteroids, galaxy

local function GaxKillMobj(s, t)
	t.hmsgaxed = false
		if not t.player
		P_KillMobj(t, s, s.hmstarget)
		elseif t
			if s.hmstarget and s.hmstarget.player
				if not t.player.rings and not (t.player.powers[pw_shield]
				or t.player.powers[pw_flashing] or t.player.powers[pw_super] or t.player.powers[pw_invulnerability])
				print(s.hmstarget.player.ctfnamecolor+" spaghettified "+t.player.ctfnamecolor+" with the Galaxy Storm!")
				else
				print(s.hmstarget.player.ctfnamecolor+" engulfed "+t.player.ctfnamecolor+" with the Galaxy Storm!")
				end
			end
		P_DamageMobj(t, s, s.hmstarget)
		end
		if s and s.valid
		s.state = S_NULL //Die, trackah
		return
		end
end
addHook("MobjThinker", function(s)
 if s and s.valid
 	if s.gaxedboi and s.gaxedboi.valid
		local t = s.gaxedboi		
			P_SpawnGhostMobj(t)
			if s.oggax and s.oggax.valid
			s.tics = s.oggax.tics
			P_Thrust(t, R_PointToAngle2(t.x, t.y, s.oggax.x, s.oggax.y), 16*FRACUNIT) 
			P_Thrust(t, R_PointToAngle2(t.x, t.y, s.oggax.x, s.oggax.y)-ANGLE_90+ANG2, 65000)
				if t.player
				t.state = S_PLAY_PAIN
				end
				if (t.z < (s.oggax.z+550*FRACUNIT))
				t.momz = $+2*FRACUNIT
				else
				t.momz = $-2*FRACUNIT
				end
				
				if s.gaxangle == nil
				s.maxlimit = 80
				s.gaxangle = 0
				P_HomingAttack(t, s)
				s.hmsec = P_SpawnMobj(t.x+(P_RandomRange(-50,50)*t.scale), t.y+(P_RandomRange(-50,50)*t.scale), t.z+(P_RandomRange(-10,30)*t.scale), MT_BOSSEXPLODE)
				s.hmsec.scale = t.scale*3
				S_StartSound(t, sfx_cybdth)
				else
				s.maxlimit = $-1
				s.gaxangle = $+FixedAngle(30*FRACUNIT)
				t.angle = s.gaxangle
				end
				
				if ((s.oggax.tics <= 3) or (s.maxlimit < 2)) and t and t.valid 
				GaxKillMobj(s, t)
				return
				end
			elseif t and t.valid
			GaxKillMobj(s, t)
			return
			end
			if (s.tics <= 3) and t and t.valid
			GaxKillMobj(s, t)
			return
			end
	elseif s and s.valid
	s.state = S_NULL
	return
	end
 end
end, MT_HMSGAXT)
addHook("MobjThinker", function(s)
 if s and s.valid
 	if s.gaxhbtarget and s.gaxhbtarget.valid
	s.tics = $+1
	local t = s.gaxhbtarget
		if s.gaxmainhb
		P_TeleportMove(s, t.x, t.y, t.z-600*FRACUNIT)		
		else
		P_TeleportMove(s, t.x, t.y, t.z-20*FRACUNIT)
		end
	s.momx = t.momx s.momy = t.momy s.momz = t.momz
	elseif s and s.valid
	s.state = S_NULL
	return
	end
 end
end, MT_HMSGAXHB)
addHook("MobjThinker", function(s)
 if s and s.valid
 	if s.gaxroll == nil
	s.gaxroll = P_RandomRange(-14, 14)
	s.gaxab = true
	end
	if not s.noroll
 	s.rollangle = $+FixedAngle(s.gaxroll*FRACUNIT)
	end
	if s.gaxab
		if s.z < s.floorz-50*FRACUNIT or s.z+50*FRACUNIT > s.ceilingz
		s.momz = $*-1
		s.gaxab = false
			S_StartSound(s, sfx_bexpld)
		end
	end
	if s.tics == 16
	s.frame = $|FF_FULLBRIGHT|TR_TRANS50
	elseif s.tics == 8
	s.frame = $|FF_FULLBRIGHT|TR_TRANS70
	end
 end
end, MT_HMSGAXA)
addHook("MobjThinker", function(s)
 if s and s.valid
	if s.gaxphase1 == nil
	s.gaxphase1 = 30
		if s.target
		s.burstangle = s.target.angle
		s.burstspeed = 45*FRACUNIT
		s.gaxstartscale = s.target.scale
		s.scale = s.target.scale*6
		s.scalespeed = $*2
		s.destscale = s.scalespeed+1
		elseif s and s.valid
		s.state = S_NULL
		return
		end
	end
	P_InstaThrust(s, s.burstangle, 42*FRACUNIT)

//Setup ball	
	if s.gaxphase1
		local trn = TR_TRANS10*max( 1,min(6,6-(s.gaxphase1-9)/2) ) //Mathematics! 
		s.frame = A|(trn)|FF_FULLBRIGHT		
		s.gaxphase1 = $-1
		s.rollangle = $+FixedAngle(30*FRACUNIT)
		
		if (s.gaxphase1 % 2 == 0)
		s.color = P_RandomRange(SKINCOLOR_BLACK, SKINCOLOR_JET)
		else
		s.color = P_RandomRange(SKINCOLOR_SUPERPURPLE2, SKINCOLOR_SUPERPURPLE5)
		end
		if (s.gaxphase1 < 15)
			if not (s.target.player and s.target.player.smsgraphix)
			P_SpawnMobj(s.x+P_RandomRange(-140, 140)*FRACUNIT, s.y+P_RandomRange(-140, 140)*FRACUNIT, s.z+P_RandomRange(-100, 200)*FRACUNIT, MT_SPARK)
				s.ghs = P_SpawnGhostMobj(s)
				s.ghs.rollangle = s.rollangle
				s.ghs.tics = 4
				if (s.gaxphase1 % 3 == 0)
				s.novawave = P_SpawnMobj(s.x, s.y, s.z+s.height/2, MT_HMSNOVAWAVE)
				s.novawave.scale = $*3
				s.novawave.rollerwave = P_RandomRange(-14, 14)*FRACUNIT
				end
			end
			if s.gaxphase1 == 1
				if not s.gaxhitbox and s.target
				s.gaxhitbox = P_SpawnMobj(s.x, s.y, s.z-610*FRACUNIT, MT_HMSGAXHB)
				s.gaxhitbox.gaxmainhb = true	
				s.gaxhitbox.gaxhbtarget = s
				s.gaxhitbox.novatarget = s
				s.gaxhitbox.hmstarget = s.target
				s.gaxhitbox.eflags = s.eflags
				s.gaxhitbox.gaxhbphase2 = true
					if G_GametypeHasSpectators() //As usual, slight range nerf for match.
					s.gaxhitbox.radius = 999*FRACUNIT
					s.gaxhitbox.height = 999*FRACUNIT
					else
					s.gaxhitbox.radius = 1220*FRACUNIT
					s.gaxhitbox.height = 1220*FRACUNIT
					end
				end

				s.gaxphase2 = 180
				s.gaxphase1 = 0
				s.scalespeed = $/2
				s.frame = H|TR_TRANS50|FF_FULLBRIGHT
				s.scale = s.gaxstartscale*8
				s.destscale = s.scale*2

				if not (s.target.player and s.target.player.smsgraphix)			
				s.nbar = P_SpawnMobj(s.x, s.y, s.z+s.height+100*FRACUNIT, MT_THOK)
				s.nbar.sprite = SPR_AURA
				s.nbar.frame = S|TR_TRANS60|FF_FULLBRIGHT
				s.nbar.color = SKINCOLOR_WHITE
				s.nbar.scale = s.scale
				s.nbar.scalespeed = $*2
				s.nbar.momz = s.momz/2  
				s.nbar.destscale = $*50	
				s.nbar.tics = 17
				end

				for nz in players.iterate
					if nz.mo and ( (FixedHypot(nz.mo.x-s.x, nz.mo.y-s.y)) <= 5000*FRACUNIT)
					A_SMSquake(nz.mo, 40*FRACUNIT, 57, 800)
					P_FlashPal(nz, PAL_MIXUP, 5)
					end
				end
				
				if not s.aaaa
				s.aaa = P_SpawnMobj(s.x, s.y, s.z, MT_THOK)
				s.aaa.flags2 = $|MF2_DONTDRAW
				s.aaa.tics = 150
				S_StartSound(s.aaa, sfx_hmsnob)
				s.aaaa = true
				end	
			end
		elseif (s.gaxphase1 % 5 == 0)
				s.ghs = P_SpawnGhostMobj(s)
				s.ghs.rollangle = s.rollangle
				s.ghs.tics = 10
		end
		
//Okay, actual galaxy phase!		

	elseif s.gaxphase2
		if not (s.target.player and s.target.player.smsgraphix and s.target.player.smsgraphix == 2)
			if (s.gaxphase2 % 5 == 0)
			GaxAsteroid(s, false, true)
			s.ghs = P_SpawnGhostMobj(s)
			s.ghs.rollangle = s.rollangle
			s.ghs.tics = 42
			end
			if (s.gaxphase2 % 3 == 0)
			GaxAsteroid(s)
			end
			if (s.gaxphase2 % 20 == 0)
			GaxAsteroid(s, true)
			S_StartSound(s, sfx_bkpoof)
			end
		elseif(s.gaxphase2 % 17 == 0)
			GaxAsteroid(s, true, false, true)
			S_StartSound(s, sfx_bkpoof)
		end
		if (s.gaxphase2 == 129)
			s.nbar = P_SpawnMobj(s.x, s.y, s.z+s.height+100*FRACUNIT, MT_THOK)
			s.nbar.sprite = SPR_AURA
			s.nbar.frame = S|TR_TRANS70|FF_FULLBRIGHT
			s.nbar.color = SKINCOLOR_SUPERGOLD4
			s.nbar.scale = s.scale
			s.nbar.scalespeed = $*2
			s.nbar.momz = s.momz/2  
			s.nbar.destscale = $*50	
			s.nbar.tics = 17
			for z in players.iterate
				if z.mo and ( (FixedHypot(z.mo.x-s.x, z.mo.y-s.y)) <= 5000*FRACUNIT)
				A_SMSquake(z.mo, 30*FRACUNIT, 70, 800)
				end
			end
		end
		if s.z < s.floorz
			s.momz = $+29000
		elseif s.z > s.ceilingz
			s.momz = $-29000
		end
		s.rollangle = $+FixedAngle(s.gaxphase2*5000)
		s.gaxphase2 = $-1
	end	
 end
end, MT_HMSGAX)