// I/O example by Cyron. Slightly edited by frostiikin, but the vast majority of this is all cyron's doing.
// I/O Support, I don't know how to put them in one file so I make multiple vars
local configplayer--I'm actually not sure if configplayer ever needs to be used tbh, I'm mostly winging it off what I saw in derp code

local function valid(mo)
	return mo and mo.valid
end

local EGGTOGGLE = "client/eggtoggle.dat"--you need a place to save that shit
local EGGMUSICTOGGLE = "client/eggmusictoggle.dat"--you need a place to save that shit
//local FILETWO = "client/whatever.dat DUMMY"
//

//
addHook("ThinkFrame", do--Cyron can't fucking code but this is IO stuff
	if valid(consoleplayer)
		and not valid(configplayer)--i really dont know if this is needed..
		and consoleplayer.eggflymode == nil	--my codes ass backwards so this will always read nil at launch, that won't work for all types of codes probably
			configplayer = consoleplayer --i really dont know if this is needed..
			local file = io.openlocal(EGGTOGGLE)--check for the file
            if file--do you actually have a file to read
                local num = file:read("*n")--tells the fucker to OPEN UP, use *a for strings, *n for numbers
                COM_BufInsertText(consoleplayer, "eggflymode "..num)--tells that fucker to put the value here
                file:close()--perish
            else--bitch where the file
                COM_BufInsertText(consoleplayer, "eggflymode 1")--this makes a default if theres no file to read
        end
            local file = io.openlocal(EGGMUSICTOGGLE)--check for the file
            if file--do you actually have a file to read
                local num2 = file:read("*n")--tells the fucker to OPEN UP, use *a for strings, *n for numbers
                COM_BufInsertText(consoleplayer, "eggmusic "..num2)--tells that fucker to put the value here
                file:close()--perish
            else--bitch where the file
                COM_BufInsertText(consoleplayer, "eggmusic 1")--this makes a default if theres no file to read
        end
	end
end)


//The Command Shit
local function EggFlyMode(player, arg)--Conjunction junction, what's your function?
	if player.mo and player.mo.valid
		if arg
			if arg == "1"--for the dummy these are numbers, but they can be strings, but you'll have to call the read differently
				player.eggflymode =  1
				CONS_Printf(player, "Flight Start Mode set to Hover. [1]")
				if io and player == consoleplayer--this section calls to save the data
					local file = io.openlocal(EGGTOGGLE, "w+")--w+ neans to write and overwrite all data in the file.
					file:write(player.eggflymode)--put that value in the file, idfk how to make boolean functions save so i force put "true" or "false" here cuz im shit
					file:close()--perish
				end
			elseif arg == "2"--same thing but different answer
				player.eggflymode =  2
				CONS_Printf(player, "Flight Start Mode set to Instant Input. [2]")
				if io and player == consoleplayer
					local file = io.openlocal(EGGTOGGLE, "w+")
					file:write(player.eggflymode)
					file:close()
				end
			end
		else
			CONS_Printf(player, "Sets your Flight Start Mode. Can be set to either 1 or 2. Currently set to "+ player.eggflymode)
		end
	else
		CONS_Printf(player, "You aren't in a stage, fuckwit.")
	end
end

COM_AddCommand("eggflymode", function(player, arg)--This adds the command
	EggFlyMode(player, arg)--Tells command what function to do
end)
local function EggMusic(player, arg)--Conjunction junction, what's your function?
	if player.mo and player.mo.valid
		if arg
			if arg == "0"--for the dummy these are numbers, but they can be strings, but you'll have to call the read differently
				player.eggmusic =  0
				CONS_Printf(player, "Egg Reverie Zone music is now off.")
				if io and player == consoleplayer--this section calls to save the data
					local file = io.openlocal(EGGMUSICTOGGLE, "w+")--w+ neans to write and overwrite all data in the file.
					file:write(player.eggmusic)--put that value in the file, idfk how to make boolean functions save so i force put "true" or "false" here cuz im shit
					file:close()--perish
				end
			elseif arg == "1"--same thing but different answer
				player.eggmusic =  1
				CONS_Printf(player, "Egg Reverie Zone music is now on.")
				if io and player == consoleplayer
					local file = io.openlocal(EGGMUSICTOGGLE, "w+")
					file:write(player.eggmusic)
					file:close()
				end
			end
		else
			CONS_Printf(player, "Allows you to toggle the Egg Reverie Zone music when super as sonic. Can be set to either 0 or 1. Currently is set to "+ player.eggmusic)
		end
	else
		CONS_Printf(player, "You aren't in a stage, fuckwit.")
	end
end

COM_AddCommand("eggmusic", function(player, arg)--This adds the command
	EggMusic(player, arg)--Tells command what function to do
end)