// 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 BOWZA = "client/bisbowser/showtime.dat"--you need a place to save that shit
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.bowsercontrolstyle == 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(BOWZA)--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
					if num == 1
						COM_BufInsertText(consoleplayer, "bowsercontrolstyle ".."hold")--tells that fucker to put the value here
					else
						COM_BufInsertText(consoleplayer, "bowsercontrolstyle ".."custom")
					end
				file:close()--perish
            else--bitch where the file
                COM_BufInsertText(consoleplayer, "bowsercontrolstyle hold")--this makes a default if theres no file to read
        end
	end
end)


//The Command Shit
local function BlueShoes(player, arg)--Conjunction junction, what's your function?
	if player.mo and player.mo.valid
		if arg
			if arg == "hold" or arg == "1"--for the dummy these are numbers, but they can be strings, but you'll have to call the read differently
				player.bowsercontrolstyle =  1
				CONS_Printf(player, "Control style set to \"Hold\".")
				if io and player == consoleplayer--this section calls to save the data
					local file = io.openlocal(BOWZA, "w+")--w+ neans to write and overwrite all data in the file.
					file:write(player.bowsercontrolstyle)--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 == "custom" or arg == "1"--same thing but different answer
				player.bowsercontrolstyle =  2
				CONS_Printf(player, "Control style set to \"Custom\".")
				if io and player == consoleplayer
					local file = io.openlocal(BOWZA, "w+")
					file:write(player.bowsercontrolstyle)
					file:close()
				end
			end
		else
			if player.bowsercontrolstyle == 1
				CONS_Printf(player, "Changes how bowser\'s spin and punch attacks are activated. Can either be \"hold\" or \"custom\". Currently set to \"hold\".")
			else
				CONS_Printf(player, "Changes how bowser\'s spin and punch attacks are activated. Can either be \"hold\" or \"custom\". Currently set to \"custom\".")
			end
		end
	else
		CONS_Printf(player, "You aren't in a stage.")
	end
end

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



