//actually finally making my own I/O system that i can understand and reuse in future projects
//instead of just piggybacking off of code cyron wrote like 2 years ago before I/O was even fully
//implemented, woo! -frost
local config = "client/elfilin/elfilin.cfg"
local values = {}
values["true"] = 1
values["on"] = 1
values["1"] = 1
values["yes"] = 1

values["false"] = 2
values["off"] = 2
values["0"] = 2
values["no"] = 2
COM_AddCommand("elfilinassist", function(p, arg, silent)
	if p.mo and p.mo.valid
		if arg and values[arg]
			if silent
				--CONS_Printf(p, "Elfilin configuration file loaded.")
			else
				CONS_Printf(p, "Assist settings saved.")
			end	
			if p == consoleplayer --only write for the local player
				local file = io.openlocal(config, "w+")
				file:write(values[arg])
				file:close()
			end
			p.elfioset = values[arg]
		else
			if p.elfioset == 1
				CONS_Printf(p, "Toggles whether or not Elfilin players are able to assist you in multiplayer. Assisting is currently turned on.")
			elseif p.elfioset == 2
				CONS_Printf(p, "Toggles whether or not Elfilin players are able to assist you in multiplayer. Assisting is currently turned off.")
			else
				CONS_Printf(p, "The hell did you do?? This message should not show up. If it somehow did, please alert me so I can fix it. (error 1)")
			end
		end
	else
		CONS_Printf(p, "You aren't in a stage.")
	end
end)
addHook("ThinkFrame", do
	for p in players.iterate
		if not (p == consoleplayer) continue end --do NOT netsynch
		--print("check 1")
		if not (p.elfioset == nil) continue end
		--print("check 2")
		if not (p.mo and p.mo.valid) continue end
		--print("check 3")
		if not (leveltime % 35 == 10) continue end
		local file = io.openlocal(config)
		if file
			--print("check 4")
			local num = file:read("*n")
			--too many errors so fuck it unnecessary if time, sue me
			if num == 1
				COM_BufInsertText(p, "elfilinassist on true")
			elseif num == 2
				COM_BufInsertText(p, "elfilinassist off true")
			else
				CONS_Printf(p, "The hell did you do?? This message should not show up. If it somehow did, please alert me so I can fix it. (error 2)")
			end
			file:close()
		else
			--print("check 5")
			COM_BufInsertText(p, "elfilinassist on true")
		end		
	end
end)
addHook("PlayerThink", function(p)
		if p.bot
			p.elfioset = 1
		end
end)