// Here we go again.
local function adv2hud(v, player)
		if G_IsSpecialStage() return end

		if player.mo and player.mo.valid
		and not (player.powers[pw_carry] == CR_NIGHTSMODE)
			if player.mo.skin ~= "advancesonic"
				if not hud.enabled("lives") // Re-enable vanilla HUD for other characters
					hud.enable("lives")
				end
				if not hud.enabled("rings")
					hud.enable("rings")
				end
				if not hud.enabled("time")
					hud.enable("time")
				end
				if not hud.enabled("score")
					hud.enable("score")
				end
				return
			else
				if hud.enabled("score") // Disable vanilla HUD
					hud.disable("score")
				end
				if hud.enabled("time")
					hud.disable("time")
				end
				if hud.enabled("rings")
					hud.disable("rings")
				end
				if hud.enabled("lives")
					hud.disable("lives")
				end
			end
			
			//Big thingy with numbers on it
			v.draw(1,4,v.cachePatch("ADVCOUNT"),V_SNAPTOTOP|V_SNAPTOLEFT|V_PERPLAYER|V_HUDTRANS)
			
			//Spinning ring
			v.draw(7,9,v.cachePatch("ADVRING"..tostring(player.ringspinframe)),V_SNAPTOTOP|V_SNAPTOLEFT|V_PERPLAYER|V_HUDTRANS)
			
			//Ring count
			local numfont = "ADVNUM"
			local ringstring = tostring(player.rings)
			ringstring = string.format("%0".."3".."d", $1)
			
			for i = 1,ringstring:len() do
				if (((leveltime/2) % 15) < 5)
				and player.rings <= 0
					v.draw(28+((i-1)*8),4,v.cachePatch("ADVRED"),V_SNAPTOTOP|V_SNAPTOLEFT|V_PERPLAYER|V_HUDTRANS)
				else
					v.draw(28+((i-1)*8),4,v.cachePatch(numfont..ringstring:sub(i,i)),V_SNAPTOTOP|V_SNAPTOLEFT|V_PERPLAYER|V_HUDTRANS)
				end
			end
			
			
			//Score count
			local scorestring = tostring(player.score)
			scorestring = string.format("%0".."6".."d", $1)
			
			for i = 1,scorestring:len() do
				v.draw(28+((i-1)*8),19,v.cachePatch(numfont..scorestring:sub(i,i)),V_SNAPTOTOP|V_SNAPTOLEFT|V_PERPLAYER|V_HUDTRANS)
			end
			
			//Timer
			local posx = 136 //Offset so I can easily adjust
			local posy = 4
			local minutes = tostring(G_TicsToMinutes(player.realtime), true) // Minutes
			
			local newposx = (posx - ((minutes:len() - 1) * 8))
			for i = 1,minutes:len() do
				local readd = (i-1)*8
				v.draw(newposx+readd,posy,v.cachePatch(numfont..minutes:sub(i,i)),V_SNAPTOTOP|V_SNAPTOLEFT|V_PERPLAYER|V_HUDTRANS)
			end
			
			v.draw(posx+8,4,v.cachePatch("ADVCOLON"),V_SNAPTOTOP|V_SNAPTOLEFT|V_PERPLAYER|V_HUDTRANS) // :
			
			local seconds = tostring(G_TicsToSeconds(player.realtime)) // Seconds
			if (G_TicsToSeconds(player.realtime)) < 10
				v.draw(posx+17,4,v.cachePatch("ADVNUM0"),V_SNAPTOTOP|V_SNAPTOLEFT|V_PERPLAYER|V_HUDTRANS)
				v.draw(posx+25,4,v.cachePatch(numfont..seconds),V_SNAPTOTOP|V_SNAPTOLEFT|V_PERPLAYER|V_HUDTRANS)
			else
				v.draw(posx+17,4,v.cachePatch(numfont..seconds:sub(1,1)),V_SNAPTOTOP|V_SNAPTOLEFT|V_PERPLAYER|V_HUDTRANS)
				v.draw(posx+25,4,v.cachePatch(numfont..seconds:sub(2,2)),V_SNAPTOTOP|V_SNAPTOLEFT|V_PERPLAYER|V_HUDTRANS)
			end
			
			v.draw(posx+33,4,v.cachePatch("ADVCOLON"),V_SNAPTOTOP|V_SNAPTOLEFT|V_PERPLAYER|V_HUDTRANS) // :
			
			local centi = tostring(G_TicsToCentiseconds(player.realtime)) // Centiseconds
			if (G_TicsToCentiseconds(player.realtime)) < 10
				v.draw(posx+42,4,v.cachePatch("ADVNUM0"),V_SNAPTOTOP|V_SNAPTOLEFT|V_PERPLAYER|V_HUDTRANS)
				v.draw(posx+50,4,v.cachePatch(numfont..centi),V_SNAPTOTOP|V_SNAPTOLEFT|V_PERPLAYER|V_HUDTRANS)
			else
				v.draw(posx+42,4,v.cachePatch(numfont..centi:sub(1,1)),V_SNAPTOTOP|V_SNAPTOLEFT|V_PERPLAYER|V_HUDTRANS)
				v.draw(posx+50,4,v.cachePatch(numfont..centi:sub(2,2)),V_SNAPTOTOP|V_SNAPTOLEFT|V_PERPLAYER|V_HUDTRANS)
			end
			
			//Lives count
			if not modeattacking
				local lifeicon = v.getSprite2Patch(player.mo.skin,SPR2_XTRA,(player.powers[pw_super] ~= 0),0,0)
				v.drawScaled(8*FRACUNIT,180*FRACUNIT,FRACUNIT/2,lifeicon,V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_PERPLAYER|V_HUDTRANS,v.getColormap(player.mo.skin, player.mo.color))
				
				if (player.lives > -1) and (player.lives < 127)
					local livesstring = tostring(player.lives)
					local newposx = 32 - ((livesstring:len() - 1) * 8)
					for i = 1,livesstring:len() do
						local readd = (i-1)*8
						v.draw(newposx+readd,182,v.cachePatch(numfont..livesstring:sub(i,i)),V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_PERPLAYER|V_HUDTRANS)
					end
				end
			end
			
			//Token count
			for i = 1,token do
				v.draw(4+(8*(i-1)),31,v.cachePatch("ADVTOKEN"),V_SNAPTOTOP|V_SNAPTOLEFT|V_PERPLAYER|V_HUDTRANS)
			end
			
		end // End of hud drawing, bye bye
		
end // End of hud function

hud.add(adv2hud) // ok put it in the game now, pauly

addHook("PlayerThink",function(player) //Function so that the spinning ring actually... spins
	if player.ringspinframe == nil
		player.ringspinframe = 0
		player.ringspinning = 3
		player.ringspinreset = 4
	end
	
	if player.speed > (skins[player.mo.skin].normalspeed + 5*FRACUNIT)
		player.ringspinreset = 1
	elseif player.speed > skins[player.mo.skin].runspeed
		player.ringspinreset = 2
	else
		player.ringspinreset = 3
	end
	
	player.ringspinning = $1 - 1
	if player.ringspinning <= 0
		player.ringspinframe = $1 + 1
		if player.ringspinframe > 3
			player.ringspinframe = 0
		end
		player.ringspinning = player.ringspinreset
	end
end)