
--resource in the mb on https://mb.srb2.org/threads/i-o-support-resource.29785/
--this script was found in xmomentum & gained permission to use it for my stuff (plus it was reusable content anyway)

//////////////DEFINE YOUR STUFF HERE

local heads = "client/sshHUD/heads.dat"

//////////////IGNORE THIS STUFF

local configplayer

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

local function load(p,path,var)
	local file = io.openlocal(path)--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 == 0
			COM_BufInsertText(p, tostring(var).." ".."0")--tells that fucker to put the value here
		elseif num == 1
			COM_BufInsertText(p, tostring(var).." ".."1")
		elseif num == 2
			COM_BufInsertText(p, tostring(var).." ".."2")
		elseif num == 3
			COM_BufInsertText(p, tostring(var).." ".."3")
		elseif num == 4
			COM_BufInsertText(p, tostring(var).." ".."4")
		elseif num == 5
			COM_BufInsertText(p, tostring(var).." ".."5")
		elseif num == 6
			COM_BufInsertText(p, tostring(var).." ".."6")
		elseif num == 7
			COM_BufInsertText(p, tostring(var).." ".."7")
		elseif num == 8
			COM_BufInsertText(p, tostring(var).." ".."8")
		elseif num == 9
			COM_BufInsertText(p, tostring(var).." ".."9")
		end
		file:close()--perish
    else--bitch where the file
        COM_BufInsertText(p, tostring(var).." ".."0")--this makes a default if theres no file to read
    end
end

local function save(player,arg1,arg2,text1,text2,path,info) //The Command Shit
	local function saveIns()
		local prnt = text1
		local variable = 1
		if (arg2 == 0)
			prnt = text2
			variable = 0
		end
		if io and player == consoleplayer--this section calls to save the data
			local file = io.openlocal(path, "w+")--w+ neans to write and overwrite all data in the file.
			file:write(arg2)--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
	end
	
	if player.mo and player.mo.valid
		if arg1
			if arg1 == "0" or arg == "00"--for the dummy these are numbers, but they can be strings, but you'll have to call the read differently
				arg2 = 0
				saveIns()
				return
			elseif arg1 == "1" or arg == "01"
				arg2 = 1
				saveIns()
				return
			elseif arg1 == "2" or arg == "02"
				arg2 = 2
				saveIns()
				return
			elseif arg1 == "3" or arg == "03"
				arg2 = 3
				saveIns()
				return
			elseif arg1 == "4" or arg == "04"
				arg2 = 4
				saveIns()
				return
			elseif arg1 == "5" or arg == "05"
				arg2 = 5
				saveIns()
				return
			elseif arg1 == "6" or arg == "06"
				arg2 = 6
				saveIns()
				return
			elseif arg1 == "7" or arg == "07"
				arg2 = 7
				saveIns()
				return
			elseif arg1 == "8" or arg == "08"
				arg2 = 8
				saveIns()
				return
			elseif arg1 == "9" or arg == "09"
				arg2 = 9
				saveIns()
				return
			else
				CONS_Printf(player, "Wrong argument!")
			end
		else
			CONS_Printf(player, info)
		end
	else
		CONS_Printf(player, "You aren't in a stage.")
	end
end





//////////////PUT YOUR STUFF IN HERE

addHook("ThinkFrame", do
	if valid(consoleplayer)
	and not valid(configplayer)--i really dont know if this is needed..
	and consoleplayer.test1 == nil
		configplayer = consoleplayer --i really dont know if this is needed..
		load(consoleplayer,heads,"animalheads")
	end
end)

-- Examples
COM_AddCommand("animalheads", function(player, arg)--This adds the command
	save(player,arg,player.animalheads,"funny","easter egg",heads, "animalheads (0-9) Changes the animal head displayed in the HUD.")--Tells command what function to do
	if (arg == "0" or arg == "00")
		player.animalheads = 0
		CONS_Printf(player, "You are now a Elephant!")
	elseif (arg == "1" or arg == "01")
		player.animalheads = 1
		CONS_Printf(player, "You are now a Crocodile!")
	elseif (arg == "2" or arg == "02")
		player.animalheads = 2
		CONS_Printf(player, "You are now a Bull!")
	elseif (arg == "3" or arg == "03")
		player.animalheads = 3
		CONS_Printf(player, "You are now a Pig!")
	elseif (arg == "4" or arg == "04")
		player.animalheads = 4
		CONS_Printf(player, "You are now a Hipoppotamus!")
	elseif (arg == "5" or arg == "05")
		player.animalheads = 5
		CONS_Printf(player, "You are now a Rabbit!")
	elseif (arg == "6" or arg == "06")
		player.animalheads = 6
		CONS_Printf(player, "You are now a Kangaroo!")
	elseif (arg == "7" or arg == "07")
		player.animalheads = 7
		CONS_Printf(player, "You are now a Polar Bear!")
	elseif (arg == "8" or arg == "08")
		player.animalheads = 8
		CONS_Printf(player, "You are now a Zebra!")
	elseif (arg == "9" or arg == "09")
		player.animalheads = 9
		CONS_Printf(player, "You are now a Monkey!")
	end
end)