//IO system by aquaponiee

addHook("PlayerThink", function(p)
	if p.mo and p.mo.valid
		-- The boost button. I/O shenanigans.
		if not p.driftbutton then
			local file = io.openlocal("client/driftbutton.txt", "r")
			if file then
				local text = file:read("*a")
				if text == ""
					p.driftbutton = BT_ATTACK
				else
					p.driftbutton = tonumber(text)
				end
				file:close()
			else
				p.driftbutton = BT_ATTACK
			end
		end
	end
end)

-- snek
local strToButton = {
    CUSTOM1 = BT_CUSTOM1,
    CUSTOM2 = BT_CUSTOM2,
    CUSTOM3 = BT_CUSTOM3,
	FIRE = BT_ATTACK,
	Firenormal = BT_FIRENORMAL,
	Tossflag = BT_TOSSFLAG,
	Custom1 = BT_CUSTOM1,
    Custom2 = BT_CUSTOM2,
    Custom3 = BT_CUSTOM3,
	Fire = BT_ATTACK,
	Firenormal = BT_FIRENORMAL,
	Tossflag = BT_TOSSFLAG,
	custom1 = BT_CUSTOM1,
    custom2 = BT_CUSTOM2,
    custom3 = BT_CUSTOM3,
	fire = BT_ATTACK,
	firenormal = BT_FIRENORMAL,
	tossflag = BT_TOSSFLAG
}

-- The command.
COM_AddCommand("driftbutton", function(p, arg1)
    io.openlocal("client/driftbutton.txt", "a"):close()
    local file = io.openlocal("client/driftbutton.txt", "w")
    if strToButton[arg1] then
        p.driftbutton = strToButton[arg1]
        file:write(strToButton[arg1])
		print("Button set successfuly.")
    else
        print("Not a valid button.")
    end
    file:close()
end)