//Please excuse the mess, I'm still new at the whole programming and script-writing thing. 
//So if you are reading this and want to try to shrink it down, be my guest.
//Just let me know if you get it working and I can release the results for you. I will credit you for your work, I'm not an asshole.
//somewhat fixed by FoxMcChoclate
//TheLastKitchenGun was also here
freeslot("sfx_cland", "sfx_cwalk")
sfxinfo[sfx_cland] = {caption = "Wet landing"}
sfxinfo[sfx_cwalk] = {caption = "Wet footsteps"}

local function P_GravAndScale (actor)
	return P_MobjFlip(actor)*actor.scale
end

	local statincrease = CV_RegisterVar({
		name = "chaos_statincrease",
		defaultvalue = "On",
		flags = CV_NETVAR,
		PossibleValue = CV_OnOff
	})
	
local gotoneemerald = 0
local gottwoemeralds = 0
local gotthreeemeralds = 0
local gotfouremeralds = 0
local gotfiveemeralds = 0
local gotsixemeralds = 0
local gotsevenemeralds = 0
local gotmorethanoneemerald = 0
local gotmorethantwoemeralds = 0
local gotmorethanthreeemeralds = 0
local gotmorethanfouremeralds = 0
local gotmorethanfiveemeralds = 0
local gotmorethansixemeralds = 0
local emmymessageone = 0
local emmymessagetwo = 0
local emmymessagethree = 0
local emmymessagefour = 0
local emmymessagefive = 0
local emmymessagesix = 0
local emmymessageseven = 0
addHook("MobjSpawn", function(mo) mo.jumpland = 0 end, MT_PLAYER)
addHook("MobjSpawn", function(mo) mo.walkstart = 0 end, MT_PLAYER)
addHook("ThinkFrame", do //Adds a ThinkFrame hook.
	for player in players.iterate //Gets the local player
		if (player.mo and player.mo.skin == "legacychaos") //Change "skinname" to the character's skin you want to use.
        and not (player.powers[pw_carry] == CR_NIGHTSMODE)//turns out my wip proto port came in handy for this
			//Chaos doesn't have lungs, so suffocation isn't really and issue.
			player.powers[pw_underwater] = 1073741824
			player.powers[pw_spacetime] = 1073741824 
		end
		//So here I'm gonna set up some checks for having certain numbers and combinations of emeralds to keep the ability code that they'll be used for mostly uncluttered.
		//You can use these checks for your own characters or events (ie. For my edit of Chaos 0 to have a message appear for each emerald gained), so long as you credit me, Jacy, for it. Especially since I had to add up the amounts and type in each amount by hand.
		//Emerald Power Numbers For Reference
		//1 = Emerald #1
		//2 = Emerald #2
		//4 = Emerald #3
		//8 = Emerald #4
		//16 = Emerald #5
		//32 = Emerald #6
		//64 = Emerald #7
		//Combine these numbers for any combination of gaining/holding these emeralds, with gaining/holding all 7 being 127
		
		//Also there are actually two kinds of checks for emeralds in lua:
		//player.powers[pw_emeralds] is what you use for emeralds held by a specific player in Match and Capture The Flag
		//(emeralds) is used for emeralds held by all players in Singleplayer and Cooperative.
		
		//The check for having no emeralds
		if player.powers[pw_emeralds] == 0
		and G_RingSlingerGametype() then
			gotoneemerald = 0
			gottwoemeralds = 0
			gotthreeemeralds = 0
			gotfouremeralds = 0
			gotfiveemeralds = 0
			gotsixemeralds = 0
			gotsevenemeralds = 0
			gotmorethanoneemerald = 0
			gotmorethantwoemeralds = 0
			gotmorethanthreeemeralds = 0
			gotmorethanfouremeralds = 0
			gotmorethanfiveemeralds = 0
			gotmorethansixemeralds = 0
			emmymessageone = 0
			emmymessagetwo = 0
			emmymessagethree = 0
			emmymessagefour = 0
			emmymessagefive = 0
			emmymessagesix = 0
			emmymessageseven = 0
		end
		if (emeralds) == 0
		and not G_RingSlingerGametype() then
			gotoneemerald = 0
			gottwoemeralds = 0
			gotthreeemeralds = 0
			gotfouremeralds = 0
			gotfiveemeralds = 0
			gotsixemeralds = 0
			gotsevenemeralds = 0
			gotmorethanoneemerald = 0
			gotmorethantwoemeralds = 0
			gotmorethanthreeemeralds = 0
			gotmorethanfouremeralds = 0
			gotmorethanfiveemeralds = 0
			gotmorethansixemeralds = 0
			emmymessageone = 0
			emmymessagetwo = 0
			emmymessagethree = 0
			emmymessagefour = 0
			emmymessagefive = 0
			emmymessagesix = 0
			emmymessageseven = 0
		end
		//The check for having any one emerald
		if gotmorethanoneemerald == 0 then
			if player.powers[pw_emeralds] == 1 //Emerald 1
			or player.powers[pw_emeralds] == 2 //Emerald 2
			or player.powers[pw_emeralds] == 4 //Emerald 3
			or player.powers[pw_emeralds] == 8 //Emerald 4
			or player.powers[pw_emeralds] == 16 //Emerald 5
			or player.powers[pw_emeralds] == 32 //Emerald 6
			or player.powers[pw_emeralds] == 64 //Emerald 7
			or (emeralds) == 1 //Emerald 1
			or (emeralds) == 2 //Emerald 2
			or (emeralds) == 4 //Emerald 3
			or (emeralds) == 8 //Emerald 4
			or (emeralds) == 16 //Emerald 5
			or (emeralds) == 32 //Emerald 6
			or (emeralds) == 64 //Emerald 7
				gotoneemerald = 1
			end
		end
		//The check for having any combination of two emeralds
		if gotmorethantwoemeralds == 0 then
			if player.powers[pw_emeralds] == 3 //Emeralds 1 and 2
			or player.powers[pw_emeralds] == 5 //Emeralds 1 and 3
			or player.powers[pw_emeralds] == 9 //Emeralds 1 and 4
			or player.powers[pw_emeralds] == 17 //Emeralds 1 and 5
			or player.powers[pw_emeralds] == 33 //Emeralds 1 and 6
			or player.powers[pw_emeralds] == 65 //Emeralds 1 and 7
			or player.powers[pw_emeralds] == 6 //Emeralds 2 and 3
			or player.powers[pw_emeralds] == 10 //Emeralds 2 and 4
			or player.powers[pw_emeralds] == 18 //Emeralds 2 and 5
			or player.powers[pw_emeralds] == 34 //Emeralds 2 and 6
			or player.powers[pw_emeralds] == 66 //Emeralds 2 and 7
			or player.powers[pw_emeralds] == 12 //Emeralds 3 and 4
			or player.powers[pw_emeralds] == 20 //Emeralds 3 and 5
			or player.powers[pw_emeralds] == 36 //Emeralds 3 and 6
			or player.powers[pw_emeralds] == 68 //Emeralds 3 and 7
			or player.powers[pw_emeralds] == 24 //Emeralds 4 and 5
			or player.powers[pw_emeralds] == 40 //Emeralds 4 and 6
			or player.powers[pw_emeralds] == 72 //Emeralds 4 and 7
			or player.powers[pw_emeralds] == 48 //Emeralds 5 and 6
			or player.powers[pw_emeralds] == 80 //Emeralds 5 and 7
			or player.powers[pw_emeralds] == 96 //Emeralds 6 and 7
			or (emeralds) == 3 //Emeralds 1 and 2
			or (emeralds) == 5 //Emeralds 1 and 3
			or (emeralds) == 9 //Emeralds 1 and 4
			or (emeralds) == 17 //Emeralds 1 and 5
			or (emeralds) == 33 //Emeralds 1 and 6
			or (emeralds) == 65 //Emeralds 1 and 7
			or (emeralds) == 6 //Emeralds 2 and 3
			or (emeralds) == 10 //Emeralds 2 and 4
			or (emeralds) == 18 //Emeralds 2 and 5
			or (emeralds) == 34 //Emeralds 2 and 6
			or (emeralds) == 66 //Emeralds 2 and 7
			or (emeralds) == 12 //Emeralds 3 and 4
			or (emeralds) == 20 //Emeralds 3 and 5
			or (emeralds) == 36 //Emeralds 3 and 6
			or (emeralds) == 68 //Emeralds 3 and 7
			or (emeralds) == 24 //Emeralds 4 and 5
			or (emeralds) == 40 //Emeralds 4 and 6
			or (emeralds) == 72 //Emeralds 4 and 7
			or (emeralds) == 48 //Emeralds 5 and 6
			or (emeralds) == 80 //Emeralds 5 and 7
			or (emeralds) == 96 //Emeralds 6 and 7
				gottwoemeralds = 1
				gotmorethanoneemerald = 1
				gotoneemerald = 0
			end
		end
		//The check for having any combination of three emeralds
		if gotmorethanthreeemeralds == 0 then
			if player.powers[pw_emeralds] == 7 //Emeralds 1, 2 and 3
			or player.powers[pw_emeralds] == 11 //Emeralds 1, 2 and 4
			or player.powers[pw_emeralds] == 19 //Emeralds 1, 2 and 5
			or player.powers[pw_emeralds] == 35 //Emeralds 1, 2 and 6
			or player.powers[pw_emeralds] == 33 //Emeralds 1, 2 and 7
			or player.powers[pw_emeralds] == 13 //Emeralds 1, 3 and 4
			or player.powers[pw_emeralds] == 21 //Emeralds 1, 3 and 5
			or player.powers[pw_emeralds] == 37 //Emeralds 1, 3 and 6
			or player.powers[pw_emeralds] == 69	//Emeralds 1, 3 and 7 (Insert stupid sex joke about the number 69 dur hur)
			or player.powers[pw_emeralds] == 25 //Emeralds 1, 4 and 5
			or player.powers[pw_emeralds] == 41	//Emeralds 1, 4 and 6
			or player.powers[pw_emeralds] == 73	//Emeralds 1, 4 and 7
			or player.powers[pw_emeralds] == 49 //Emeralds 1, 5 and 6
			or player.powers[pw_emeralds] == 81 //Emeralds 1, 5 and 7
			or player.powers[pw_emeralds] == 97 //Emeralds 1, 6 and 7
			or player.powers[pw_emeralds] == 14 //Emeralds 2, 3 and 4
			or player.powers[pw_emeralds] == 22 //Emeralds 2, 3 and 5
			or player.powers[pw_emeralds] == 38 //Emeralds 2, 3 and 6
			or player.powers[pw_emeralds] == 70 //Emeralds 2, 3 and 7
			or player.powers[pw_emeralds] == 26 //Emeralds 2, 4 and 5
			or player.powers[pw_emeralds] == 42 //Emeralds 2, 4 and 6 (Funny how all the even ones together make The Answer to Life, The Universe, and Everything...)
			or player.powers[pw_emeralds] == 74 //Emeralds 2, 4 and 7
			or player.powers[pw_emeralds] == 50 //Emeralds 2, 5 and 6
			or player.powers[pw_emeralds] == 82 //Emeralds 2, 5 and 7
			or player.powers[pw_emeralds] == 98 //Emeralds 2, 6 and 7
			or player.powers[pw_emeralds] == 28 //Emeralds 3, 4 and 5
			or player.powers[pw_emeralds] == 44 //Emeralds 3, 4 and 6
			or player.powers[pw_emeralds] == 76 //Emeralds 3, 4 and 7
			or player.powers[pw_emeralds] == 52 //Emeralds 3, 5 and 6
			or player.powers[pw_emeralds] == 84	//Emeralds 3, 5 and 7
			or player.powers[pw_emeralds] == 100 //Emeralds 3, 6 and 7
			or player.powers[pw_emeralds] == 56 //Emeralds 4, 5 and 6
			or player.powers[pw_emeralds] == 36 //Emeralds 4, 5 and 7
			or player.powers[pw_emeralds] == 104 //Emeralds 4, 6 and 7
			or player.powers[pw_emeralds] == 112 //Emeralds 5, 6 and 7
			or (emeralds) == 7 //Emeralds 1, 2 and 3
			or (emeralds) == 11 //Emeralds 1, 2 and 4
			or (emeralds) == 19 //Emeralds 1, 2 and 5
			or (emeralds) == 35 //Emeralds 1, 2 and 6
			or (emeralds) == 33 //Emeralds 1, 2 and 7
			or (emeralds) == 13 //Emeralds 1, 3 and 4
			or (emeralds) == 21 //Emeralds 1, 3 and 5
			or (emeralds) == 37 //Emeralds 1, 3 and 6
			or (emeralds) == 69	//Emeralds 1, 3 and 7
			or (emeralds) == 25 //Emeralds 1, 4 and 5
			or (emeralds) == 41	//Emeralds 1, 4 and 6
			or (emeralds) == 73	//Emeralds 1, 4 and 7
			or (emeralds) == 49 //Emeralds 1, 5 and 6
			or (emeralds) == 81 //Emeralds 1, 5 and 7
			or (emeralds) == 97 //Emeralds 1, 6 and 7
			or (emeralds) == 14 //Emeralds 2, 3 and 4
			or (emeralds) == 22 //Emeralds 2, 3 and 5
			or (emeralds) == 38 //Emeralds 2, 3 and 6
			or (emeralds) == 70 //Emeralds 2, 3 and 7
			or (emeralds) == 26 //Emeralds 2, 4 and 5
			or (emeralds) == 42 //Emeralds 2, 4 and 6
			or (emeralds) == 74 //Emeralds 2, 4 and 7
			or (emeralds) == 50 //Emeralds 2, 5 and 6
			or (emeralds) == 82 //Emeralds 2, 5 and 7
			or (emeralds) == 98 //Emeralds 2, 6 and 7
			or (emeralds) == 28 //Emeralds 3, 4 and 5
			or (emeralds) == 44 //Emeralds 3, 4 and 6
			or (emeralds) == 76 //Emeralds 3, 4 and 7
			or (emeralds) == 52 //Emeralds 3, 5 and 6
			or (emeralds) == 84	//Emeralds 3, 5 and 7
			or (emeralds) == 100 //Emeralds 3, 6 and 7
			or (emeralds) == 56 //Emeralds 4, 5 and 6
			or (emeralds) == 36 //Emeralds 4, 5 and 7
			or (emeralds) == 104 //Emeralds 4, 6 and 7
			or (emeralds) == 112 //Emeralds 5, 6 and 7
				gotthreeemeralds = 1
				gotmorethantwoemeralds = 1
				gottwoemeralds = 0
			end
		end
		//The check for having any combination of four emeralds
		if gotmorethanfouremeralds == 0 then
			if player.powers[pw_emeralds] == 15 //Emeralds 1, 2, 3 and 4
			or player.powers[pw_emeralds] == 23 //Emeralds 1, 2, 3 and 5
			or player.powers[pw_emeralds] == 39 //Emeralds 1, 2, 3 and 6
			or player.powers[pw_emeralds] == 71 //Emeralds 1, 2, 3 and 7
			or player.powers[pw_emeralds] == 27 //Emeralds 1, 2, 4 and 5
			or player.powers[pw_emeralds] == 43 //Emeralds 1, 2, 4 and 6
			or player.powers[pw_emeralds] == 75 //Emeralds 1, 2, 4 and 7
			or player.powers[pw_emeralds] == 51 //Emeralds 1, 2, 5 and 6
			or player.powers[pw_emeralds] == 83 //Emeralds 1, 2, 5 and 7
			or player.powers[pw_emeralds] == 99 //Emeralds 1, 2, 6 and 7
			or player.powers[pw_emeralds] == 29 //Emeralds 1, 3, 4 and 5
			or player.powers[pw_emeralds] == 45 //Emeralds 1, 3, 4 and 6
			or player.powers[pw_emeralds] == 77 //Emeralds 1, 3, 4 and 7
			or player.powers[pw_emeralds] == 53 //Emeralds 1, 3, 5 and 6
			or player.powers[pw_emeralds] == 85 //Emeralds 1, 3, 5 and 7
			or player.powers[pw_emeralds] == 101 //Emeralds 1, 3, 6 and 7
			or player.powers[pw_emeralds] == 57 //Emeralds 1, 4, 5 and 6
			or player.powers[pw_emeralds] == 89 //Emeralds 1, 4, 5 and 7
			or player.powers[pw_emeralds] == 105 //Emeralds 1, 4, 6 and 7
			or player.powers[pw_emeralds] == 113 //Emeralds 1, 5, 6 and 7
			or player.powers[pw_emeralds] == 30 //Emeralds 2, 3, 4 and 5
			or player.powers[pw_emeralds] == 46 //Emeralds 2, 3, 4 and 6
			or player.powers[pw_emeralds] == 78 //Emeralds 2, 3, 4 and 7
			or player.powers[pw_emeralds] == 54 //Emeralds 2, 3, 5 and 6
			or player.powers[pw_emeralds] == 86 //Emeralds 2, 3, 5 and 7
			or player.powers[pw_emeralds] == 102 //Emeralds 2, 3, 6 and 7
			or player.powers[pw_emeralds] == 58 //Emeralds 2, 4, 5 and 6
			or player.powers[pw_emeralds] == 90 //Emeralds 2, 4, 5 and 7
			or player.powers[pw_emeralds] == 114 //Emeralds 2, 5, 6 and 7
			or player.powers[pw_emeralds] == 60 //Emeralds 3, 4, 5 and 6
			or player.powers[pw_emeralds] == 92 //Emeralds 3, 4, 5 and 7
			or player.powers[pw_emeralds] == 116 //Emeralds 3, 5, 6 and 7
			or player.powers[pw_emeralds] == 120 //Emeralds 4, 5, 6 and 7
			or (emeralds) == 15 //Emeralds 1, 2, 3 and 4
			or (emeralds) == 23 //Emeralds 1, 2, 3 and 5
			or (emeralds) == 39 //Emeralds 1, 2, 3 and 6
			or (emeralds) == 71 //Emeralds 1, 2, 3 and 7
			or (emeralds) == 27 //Emeralds 1, 2, 4 and 5
			or (emeralds) == 43 //Emeralds 1, 2, 4 and 6
			or (emeralds) == 75 //Emeralds 1, 2, 4 and 7
			or (emeralds) == 51 //Emeralds 1, 2, 5 and 6
			or (emeralds) == 83 //Emeralds 1, 2, 5 and 7
			or (emeralds) == 99 //Emeralds 1, 2, 6 and 7
			or (emeralds) == 29 //Emeralds 1, 3, 4 and 5
			or (emeralds) == 45 //Emeralds 1, 3, 4 and 6
			or (emeralds) == 77 //Emeralds 1, 3, 4 and 7
			or (emeralds) == 53 //Emeralds 1, 3, 5 and 6
			or (emeralds) == 85 //Emeralds 1, 3, 5 and 7
			or (emeralds) == 101 //Emeralds 1, 3, 6 and 7
			or (emeralds) == 57 //Emeralds 1, 4, 5 and 6
			or (emeralds) == 89 //Emeralds 1, 4, 5 and 7
			or (emeralds) == 105 //Emeralds 1, 4, 6 and 7
			or (emeralds) == 113 //Emeralds 1, 5, 6 and 7
			or (emeralds) == 30 //Emeralds 2, 3, 4 and 5
			or (emeralds) == 46 //Emeralds 2, 3, 4 and 6
			or (emeralds) == 78 //Emeralds 2, 3, 4 and 7
			or (emeralds) == 54 //Emeralds 2, 3, 5 and 6
			or (emeralds) == 86 //Emeralds 2, 3, 5 and 7
			or (emeralds) == 102 //Emeralds 2, 3, 6 and 7
			or (emeralds) == 58 //Emeralds 2, 4, 5 and 6
			or (emeralds) == 90 //Emeralds 2, 4, 5 and 7
			or (emeralds) == 114 //Emeralds 2, 5, 6 and 7
			or (emeralds) == 60 //Emeralds 3, 4, 5 and 6
			or (emeralds) == 92 //Emeralds 3, 4, 5 and 7
			or (emeralds) == 116 //Emeralds 3, 5, 6 and 7
			or (emeralds) == 120 //Emeralds 4, 5, 6 and 7
				gotfouremeralds = 1
				gotmorethanthreeemeralds = 1
				gotthreeemeralds = 0
			end
		end
		//The check for having any combination of five emeralds
		if gotmorethanfiveemeralds == 0 then
			if player.powers[pw_emeralds] == 31 //Emeralds 1, 2, 3, 4 and 5
			or player.powers[pw_emeralds] == 47 //Emeralds 1, 2, 3, 4 and 6
			or player.powers[pw_emeralds] == 79 //Emeralds 1, 2, 3, 4 and 7
			or player.powers[pw_emeralds] == 55 //Emeralds 1, 2, 3, 5 and 6
			or player.powers[pw_emeralds] == 87 //Emeralds 1, 2, 3, 5 and 7
			or player.powers[pw_emeralds] == 103 //Emeralds 1, 2, 3, 6 and 7
			or player.powers[pw_emeralds] == 59 //Emeralds 1, 2, 4, 5 and 6
			or player.powers[pw_emeralds] == 91 //Emeralds 1, 2, 4, 5 and 7
			or player.powers[pw_emeralds] == 107 //Emeralds 1, 2, 4, 6 and 7
			or player.powers[pw_emeralds] == 115 //Emeralds 1, 2, 5, 6 and 7
			or player.powers[pw_emeralds] == 61 //Emeralds 1, 3, 4, 5 and 6
			or player.powers[pw_emeralds] == 93 //Emeralds 1, 3, 4, 5 and 7
			or player.powers[pw_emeralds] == 109 //Emeralds 1, 3, 4, 6 and 7
			or player.powers[pw_emeralds] == 117 //Emeralds 1, 3, 5, 6 and 7
			or player.powers[pw_emeralds] == 121 //Emeralds 1, 4, 5, 6 and 7
			or player.powers[pw_emeralds] == 62 //Emeralds 2, 3, 4, 5 and 6
			or player.powers[pw_emeralds] == 94 //Emeralds 2, 3, 4, 5 and 7
			or player.powers[pw_emeralds] == 110 //Emeralds 2, 3, 4, 6 and 7
			or player.powers[pw_emeralds] == 118 //Emeralds 2, 3, 5, 6 and 7
			or player.powers[pw_emeralds] == 122 //Emeralds 2, 4, 5, 6 and 7
			or player.powers[pw_emeralds] == 124 //Emeralds 3, 4, 5, 6 and 7
			or (emeralds) == 31 //Emeralds 1, 2, 3, 4 and 5
			or (emeralds) == 47 //Emeralds 1, 2, 3, 4 and 6
			or (emeralds) == 79 //Emeralds 1, 2, 3, 4 and 7
			or (emeralds) == 55 //Emeralds 1, 2, 3, 5 and 6
			or (emeralds) == 87 //Emeralds 1, 2, 3, 5 and 7
			or (emeralds) == 103 //Emeralds 1, 2, 3, 6 and 7
			or (emeralds) == 59 //Emeralds 1, 2, 4, 5 and 6
			or (emeralds) == 91 //Emeralds 1, 2, 4, 5 and 7
			or (emeralds) == 107 //Emeralds 1, 2, 4, 6 and 7
			or (emeralds) == 115 //Emeralds 1, 2, 5, 6 and 7
			or (emeralds) == 61 //Emeralds 1, 3, 4, 5 and 6
			or (emeralds) == 93 //Emeralds 1, 3, 4, 5 and 7
			or (emeralds) == 109 //Emeralds 1, 3, 4, 6 and 7
			or (emeralds) == 117 //Emeralds 1, 3, 5, 6 and 7
			or (emeralds) == 121 //Emeralds 1, 4, 5, 6 and 7
			or (emeralds) == 62 //Emeralds 2, 3, 4, 5 and 6
			or (emeralds) == 94 //Emeralds 2, 3, 4, 5 and 7
			or (emeralds) == 110 //Emeralds 2, 3, 4, 6 and 7
			or (emeralds) == 118 //Emeralds 2, 3, 5, 6 and 7
			or (emeralds) == 122 //Emeralds 2, 4, 5, 6 and 7
			or (emeralds) == 124 //Emeralds 3, 4, 5, 6 and 7
				gotfiveemeralds = 1
				gotmorethanfouremeralds = 1
				gotfouremeralds = 0
			end
		end
		//The check for having any combination of six emeralds
		if gotmorethansixemeralds == 0 then
			if player.powers[pw_emeralds] == 63 //Emeralds 1, 2, 3, 4, 5 and 6
			or player.powers[pw_emeralds] == 95 //Emeralds 1, 2, 3, 4, 5 and 7
			or player.powers[pw_emeralds] == 111 //Emeralds 1, 2, 3, 4, 6 and 7
			or player.powers[pw_emeralds] == 119 //Emeralds 1, 2, 3, 5, 6 and 7
			or player.powers[pw_emeralds] == 123 //Emeralds 1, 2, 4, 5, 6 and 7
			or player.powers[pw_emeralds] == 125 //Emeralds 1, 3, 4, 5, 6 and 7
			or player.powers[pw_emeralds] == 126 //Emeralds 2, 3, 4, 5, 6 and 7
			or (emeralds) == 63 //Emeralds 1, 2, 3, 4, 5 and 6
			or (emeralds) == 95 //Emeralds 1, 2, 3, 4, 5 and 7
			or (emeralds) == 111 //Emeralds 1, 2, 3, 4, 6 and 7
			or (emeralds) == 119 //Emeralds 1, 2, 3, 5, 6 and 7
			or (emeralds) == 123 //Emeralds 1, 2, 4, 5, 6 and 7
			or (emeralds) == 125 //Emeralds 1, 3, 4, 5, 6 and 7
			or (emeralds) == 126 //Emeralds 2, 3, 4, 5, 6 and 7
				gotsixemeralds = 1
				gotmorethanfiveemeralds = 1
				gotfiveemeralds = 0
			end
		end
		//The check for having all seven of the emeralds
			if player.powers[pw_emeralds] == 127 //Emeralds 1, 2, 3, 4, 5, 6 and 7
			or (emeralds) == 127
				gotsevenemeralds = 1
				gotmorethansixemeralds = 1
				gotsixemeralds = 0
			end
		//Let's give Chaos some stat changes in certain situations...
		if (player.mo and player.mo.skin == "legacychaos") then //If you are Chaos...
			if player.mo.eflags & MFE_UNDERWATER //And you are underwater...
			and not (player.gotflag)		//If you have not grabbed a flag
				player.normalspeed = 50*FRACUNIT //Underwater Superiority!
				player.actionspd = 45*FRACUNIT
				player.accelstart = 150
				player.acceleration = 50
				player.thrustfactor = 5
				player.jumpfactor = (6*FRACUNIT)/4
				player.maxdash = 120*FRACUNIT
			elseif  player.mo.eflags & MFE_UNDERWATER 
			and gotmorethanfiveemeralds == 0
			and (player.gotflag)		//If you have grabbed a flag
				player.normalspeed = 30*FRACUNIT //Stats only multiplied by 150% of Chaos' default stats so you can't outspeed the other team
				player.actionspd = 24*FRACUNIT
				player.accelstart = 96
				player.acceleration = 37 
				player.thrustfactor = 4 
				player.jumpfactor = (3*FRACUNIT)/2
				player.maxdash = 75*FRACUNIT
			elseif (player.powers[pw_shield] == SH_ELEMENTAL) //If you have an elemental shield...
			and gotmorethanfiveemeralds == 0
				player.normalspeed = 29*FRACUNIT
				player.actionspd = 23*FRACUNIT
				player.accelstart = 104
				player.acceleration = 38
				player.thrustfactor = 4 
				player.jumpfactor = (84*FRACUNIT)/100
				player.maxdash = 75*FRACUNIT
			elseif (mapheaderinfo[gamemap].lvlttl == "Special Stage III") //Make this compatible with SRB2DVD Special stages. Otherwise you can't beat them without a certain number of emeralds since Chaos can't jump high enough or run fast enough.
				player.normalspeed = 33*FRACUNIT
				player.actionspd = 27*FRACUNIT
				player.accelstart = 120
				player.acceleration = 44
				player.thrustfactor = 4 
				player.jumpfactor = (3*FRACUNIT)/2
				player.maxdash = 75*FRACUNIT
			elseif (gotoneemerald == 1 and statincrease.value == 1) //If you have one emerald
				player.normalspeed = 21*FRACUNIT
				player.actionspd = 19*FRACUNIT
				player.accelstart = 72
				player.acceleration = 34 
				player.thrustfactor = 4 
				player.jumpfactor = (3*FRACUNIT)/2
				player.maxdash = 55*FRACUNIT
			elseif (gottwoemeralds == 1 and statincrease.value == 1) //If you have two emeralds
				player.normalspeed = 23*FRACUNIT
				player.actionspd = 20*FRACUNIT
				player.accelstart = 80
				player.acceleration = 35
				player.thrustfactor = 4 
				player.jumpfactor = (3*FRACUNIT)/2
				player.maxdash = 60*FRACUNIT
			elseif (gotthreeemeralds == 1 and statincrease.value == 1) //If you have three emeralds
				player.normalspeed = 25*FRACUNIT
				player.actionspd = 21*FRACUNIT
				player.accelstart = 88
				player.acceleration = 36
				player.thrustfactor = 4 
				player.jumpfactor = (3*FRACUNIT)/2
				player.maxdash = 65*FRACUNIT
			elseif (gotfouremeralds == 1 and statincrease.value == 1) //If you have four emeralds
				player.normalspeed = 27*FRACUNIT
				player.actionspd = 22*FRACUNIT
				player.accelstart = 96
				player.acceleration = 37
				player.thrustfactor = 4 
				player.jumpfactor = (3*FRACUNIT)/2
				player.maxdash = 70*FRACUNIT
			elseif (gotfiveemeralds == 1 and statincrease.value == 1) //If you have five emeralds
				player.normalspeed = 29*FRACUNIT
				player.actionspd = 23*FRACUNIT
				player.accelstart = 104
				player.acceleration = 38
				player.thrustfactor = 4 
				player.jumpfactor = (4*FRACUNIT)/3
				player.maxdash = 75*FRACUNIT
			elseif (gotsixemeralds == 1 and statincrease.value == 1) //If you have six emeralds
				player.normalspeed = 31*FRACUNIT
				player.actionspd = 24*FRACUNIT
				player.accelstart = 112
				player.acceleration = 39
				player.thrustfactor = 4 
				player.jumpfactor = (4*FRACUNIT)/3
				player.maxdash = 80*FRACUNIT
			elseif (gotsevenemeralds == 1 and statincrease.value == 1) //If you have all seven emeralds
				player.normalspeed = 33*FRACUNIT
				player.actionspd = 27*FRACUNIT
				player.accelstart = 120
				player.acceleration = 44
				player.thrustfactor = 4 
				player.jumpfactor = (5*FRACUNIT)/3
				player.maxdash = 90*FRACUNIT
			elseif (emeralds == 0 or player.powers[pw_emeralds] == 0)
			and (statincrease.value == 1) //If none of these are happening...
				player.normalspeed = 20*FRACUNIT //Regular stats
				player.actionspd = 18*FRACUNIT
				player.accelstart = 64
				player.acceleration = 33
				player.thrustfactor = 4
				player.jumpfactor = (3*FRACUNIT)/4 //God DAMN, it took me a while to get the jumpfactor to change correctly.
				player.maxdash = 50*FRACUNIT
			elseif (statincrease.value == 0)
				player.normalspeed = 29*FRACUNIT
				player.actionspd = 23*FRACUNIT
				player.accelstart = 104
				player.acceleration = 38
				player.thrustfactor = 4 
				player.jumpfactor = (86*FRACUNIT)/100
				player.maxdash = 75*FRACUNIT
			else
				player.normalspeed = 20*FRACUNIT 
				player.actionspd = 18*FRACUNIT
				player.accelstart = 64
				player.acceleration = 33
				player.thrustfactor = 4
				player.jumpfactor = (5*FRACUNIT)/4
			end
			if (player.powers[pw_super])
				player.runspeed = 30*FRACUNIT
			else
				player.runspeed = 22*FRACUNIT
			end
			if emmymessageone == 0
			and gotoneemerald == 1
				emmymessageone = 1
				CONS_Printf(player,"You've collected a\x83 Chaos Emerald\x80. Chaos' stats have gone up a little bit.")
				return
			end
			if emmymessagetwo == 0
			and gottwoemeralds == 1
				emmymessagetwo = 1
				CONS_Printf(player,"You've collected two\x83 Chaos Emeralds\x80. Chaos' stats have gone up a bit more.")
				return
			end
			if emmymessagethree == 0
			and gotthreeemeralds == 1
				emmymessagethree = 1
				CONS_Printf(player,"You've collected three\x83 Chaos Emeralds\x80. Chaos' stats have gone up more.")
				return
			end
			if emmymessagefour == 0
			and gotfouremeralds == 1
				emmymessagefour = 1
				CONS_Printf(player,"You've collected four\x83 Chaos Emeralds\x80. Chaos' stats have gone up even more.")
				return
			end
			if emmymessagefive == 0
			and gotfiveemeralds == 1
				emmymessagefive = 1
				CONS_Printf(player,"You've collected five\x83 Chaos Emeralds\x80! Chaos' stats have gone up far more!")
				return
			end
			if emmymessagesix == 0
			and gotsixemeralds == 1
				emmymessagesix = 1
				CONS_Printf(player,"You've collected six\x83 Chaos Emeralds\x80! Chaos' stats are almost maxed out!")
				return
			end
			if emmymessageseven == 0
			and gotsevenemeralds == 1
				emmymessageseven = 1
				CONS_Printf(player,"Congratulations, you've collected all seven\x83 Chaos Emeralds\x80! Chaos' stats have reached their maximum level!")
				return
			end
		end
        if (player.mo and player.mo.skin == "legacychaos")
		and not (player.pflags & PF_GLIDING) then
            if (player.pflags & PF_JUMPED)
			and P_MobjFlip(player.mo) == 1 // Are you Rightside-up?
            and (player.mo.momz>0) // Player vertical momentum is greater than 0
            and not P_IsObjectOnGround(player.mo)
                player.mo.state=S_PLAY_SPRING
                player.pflags=$1 & ~PF_SPINNING // Remove spinning flags if player has any at this point, otherwise it will act weird
            elseif (player.pflags & PF_JUMPED)
			and  P_MobjFlip(player.mo) == -1 // Are you Upside-down?
            and (player.mo.momz<0) // Player vertical momentum is less than 0 (Technically greater than since you are upside-down)
            and not P_IsObjectOnGround(player.mo)
                player.mo.state=S_PLAY_SPRING
                player.pflags=$1 & ~PF_SPINNING // Remove spinning flags if player has any at this point, otherwise it will act weird
            elseif (player.pflags & PF_JUMPED)
			and P_MobjFlip(player.mo) == 1 // Are you Rightside-up?
            and (player.mo.momz<=0) // Player vertical momentum is less than or equal to 0
            and not P_IsObjectOnGround(player.mo)
                player.mo.state=S_PLAY_FALL
                player.pflags=$1 & ~PF_SPINNING // Remove spinning flags if player has any at this point, otherwise it will act weird
            elseif (player.pflags & PF_JUMPED)
			and  P_MobjFlip(player.mo) == -1 // Are you Upside-down?
            and (player.mo.momz>=0) // Player vertical momentum is greater than or equal to 0 (Technically less than since you are upside-down)
            and not P_IsObjectOnGround(player.mo)
                player.mo.state=S_PLAY_FALL
                player.pflags=$1 & ~PF_SPINNING // Remove spinning flags if player has any at this point, otherwise it will act weird
			end
			if not P_IsObjectOnGround(player.mo)
			and (player.pflags & PF_JUMPED)
				player.charability2 = CA2_NONE 
			else
				player.charability2 = CA2_SPINDASH
			end
			if not P_IsObjectOnGround(player.mo)
			and not (player.powers[pw_carry] == CR_NIGHTSMODE) //because i forgot people actually play sp special stages
			and player.mo.jumpland == 0
				player.mo.jumpland = 1
			elseif P_IsObjectOnGround(player.mo)
			and player.mo.jumpland == 1
				player.mo.jumpland = 0
				S_StartSound(player.mo, sfx_cland)
			end
			if player.mo.walkstart == 0
			and not (player.powers[pw_carry] == CR_NIGHTSMODE)
			and P_IsObjectOnGround(player.mo)
			and not (player.pflags & PF_SPINNING)
			and not (player.pflags & PF_STARTDASH)
			and not (player.pflags & PF_SLIDING)
				if (player.cmd.forwardmove)
				and not (player.cmd.sidemove)
					player.mo.walkstart = 1
					S_StartSound(player.mo, sfx_cwalk)
				elseif (player.cmd.sidemove)
				and not (player.cmd.forwardmove)
					player.mo.walkstart = 1
					S_StartSound(player.mo, sfx_cwalk)
				elseif (player.cmd.sidemove)
				and (player.cmd.forwardmove)
					player.mo.walkstart = 1
					S_StartSound(player.mo, sfx_cwalk)
				end
			elseif player.mo.walkstart == 1
				if not (player.cmd.forwardmove)
				and not (player.cmd.sidemove)
					player.mo.walkstart = 0
				elseif not P_IsObjectOnGround(player.mo)
				or (player.pflags & PF_SPINNING)
				or (player.pflags & PF_STARTDASH)
				or (player.pflags & PF_SLIDING)
					player.mo.walkstart = 0
				end
			end
        end
		if player and player.valid then
			if player.mo and player.mo.valid and player.mo.skin == "legacychaos"
			and not (player.powers[pw_carry] == CR_NIGHTSMODE) then
				player.mo.frame = $|TR_TRANS30
			end
		end
	end
end)

local function DontTouchThis(bubb, chaos)
	if chaos.skin == "legacychaos" then
		return true
	end
end

addHook("MobjSpawn", function(mo) mo.airactionswitch = 0 end, MT_PLAYER)
addHook("MobjSpawn", function(mo) mo.cooldowntimer = 0 end, MT_PLAYER)
addHook("ThinkFrame", do
	for player in players.iterate do
		if player.mo and player.mo.skin == "legacychaos"
		and not (player.powers[pw_carry] == CR_NIGHTSMODE)
			if player.mo.airactionswitch == 0
				player.charability = CA_GLIDEANDCLIMB
			elseif player.mo.airactionswitch == 1
				player.charability = CA_DOUBLEJUMP
			end
			if player.mo.cooldowntimer == 0
			and P_IsObjectOnGround(player.mo) then
				if (player.cmd.buttons & BT_CUSTOM1) then
					if player.mo.airactionswitch == 0
						player.mo.airactionswitch = 1
						player.mo.cooldowntimer = 5
					elseif player.mo.airactionswitch == 1
						player.mo.airactionswitch = 0
						player.mo.cooldowntimer = 5
					end
				end
			end
			if player.mo.cooldowntimer == 0
				player.mo.cooldowntimer = 0
			elseif player.mo.cooldowntimer > 0
				player.mo.cooldowntimer = $1 - 1
			end
			if (player.mo.cooldowntimer >= 1)
			and (player.cmd.buttons == BT_CUSTOM1) then
			player.mo.cooldowntimer = 5
			end
		end
	end
end)

local function hud_abilityswitch(v, player)
	for player in players.iterate do --Get players.
		if not (player.powers[pw_carry] == CR_NIGHTSMODE) or (player.spectator) continue end
		end
        if (player.mo and player.mo.valid and player.mo.skin == "legacychaos")
			if player.charability == CA_GLIDEANDCLIMB
			v.drawString(hudinfo[HUD_LIVES].x, hudinfo[HUD_LIVES].y-15, "Glide and Climb", V_YELLOWMAP|V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_ALLOWLOWERCASE, "small")
			elseif player.charability == CA_DOUBLEJUMP
			v.drawString(hudinfo[HUD_LIVES].x, hudinfo[HUD_LIVES].y-15, "Double Jump", V_YELLOWMAP|V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_ALLOWLOWERCASE, "small")
			end
			v.drawString(hudinfo[HUD_LIVES].x, hudinfo[HUD_LIVES].y-10, "Custom 1: Switch Ability", V_YELLOWMAP|V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_ALLOWLOWERCASE, "small")
		end
	end
hud.add(hud_abilityswitch)

//Custom Super Colors!
//even though they're just vanilla colors -TLKG 
freeslot("SKINCOLOR_SUPERPERFECTCHAOS1")
freeslot("SKINCOLOR_SUPERPERFECTCHAOS2")
freeslot("SKINCOLOR_SUPERPERFECTCHAOS3")
freeslot("SKINCOLOR_SUPERPERFECTCHAOS4")
freeslot("SKINCOLOR_SUPERPERFECTCHAOS5")
skincolors[SKINCOLOR_SUPERPERFECTCHAOS1] = {
name = "Super PerfectChaos 1",
accessible = false
}

skincolors[SKINCOLOR_SUPERPERFECTCHAOS1].ramp = skincolors[SKINCOLOR_CYAN].ramp

skincolors[SKINCOLOR_SUPERPERFECTCHAOS2] = {
name = "Super PerfectChaos 2",
accessible = false
}

skincolors[SKINCOLOR_SUPERPERFECTCHAOS2].ramp = skincolors[SKINCOLOR_BLUEBELL].ramp

skincolors[SKINCOLOR_SUPERPERFECTCHAOS3] = {
name = "Super PerfectChaos 3",
accessible = false
}

skincolors[SKINCOLOR_SUPERPERFECTCHAOS3].ramp = skincolors[SKINCOLOR_BLUE].ramp

skincolors[SKINCOLOR_SUPERPERFECTCHAOS4] = {
name = "Super PerfectChaos 4",
accessible = false
}
skincolors[SKINCOLOR_SUPERPERFECTCHAOS4].ramp = skincolors[SKINCOLOR_CYAN].ramp

skincolors[SKINCOLOR_SUPERPERFECTCHAOS5] = {
name = "Super PerfectChaos 5",
accessible = false
}

skincolors[SKINCOLOR_SUPERPERFECTCHAOS5].ramp = skincolors[SKINCOLOR_WHITE].ramp

addHook("TouchSpecial", DontTouchThis, MT_EXTRALARGEBUBBLE)

addHook("PlayerThink", function(player)
	if (player.mo ~= nil and player.mo.valid and player.mo and player.mo.skin == "legacychaos")
	local skin = skins[player.mo.skin].spinitem
		if (player.mo.state == S_PLAY_RUN) 
		//do not do this -TheLastKitchenGun
		and (leveltime%TICRATE == 2 or leveltime%TICRATE == 10 or leveltime%TICRATE == 18 or leveltime%TICRATE == 26 or leveltime%TICRATE == 34)
		P_SpawnSpinMobj(player, skin)
		end
	end
end)

//This color was made by SonicSpades
freeslot("SKINCOLOR_CHAOSCYAN")
skincolors[SKINCOLOR_CHAOSCYAN] = {
    name = "ChaosCyan",
    ramp = {128,128,129,129,130,130,131,131,132,132,133,135,134,134,134,136},
    invcolor = SKINCOLOR_ORANGE,
    invshade = 9,
    chatcolor = V_SKYMAP,
    accessible = true
}

print("Chaos 0 originally by Nitro (Chrispy)")
print("Ported to 2.0 by Senku")
print("Port to 2.1 and Lua by Jacy")
print("Ported to 2.2 by FoxMcChoclate")
print("Finishing touches by TheLastKitchenGun")
print("ChaosCyan color by SonicSpades")