//Custom Invincibility Jingle by Pontrol
//If you want to use this script on your own mod, Go ahead! But make sure to credit me on your mod's Message Board page tho.

//anyways my discord username for no reason at all: aether.brightheart

//important detail
local thecharacter = "finhatguythe3rd"
local custominvtheme = "tunes fininv"
local customgrowtheme = "tunes fingrw"

//the other stuff
local defaulttheme = "tunes -default"
local tuned = 0

//inv
addHook("ThinkFrame", do
	for player in players.iterate
		if not consoleplayer.exiting
			if consoleplayer.mo.skin == thecharacter
				if consoleplayer.invincibilitytimer and tuned == 0 and not consoleplayer.exiting then
					COM_BufInsertText(consoleplayer, custominvtheme)
					tuned = 1
				elseif consoleplayer.exiting
					COM_BufInsertText(consoleplayer, defaulttheme)
					tuned = 0
				elseif not consoleplayer.invincibilitytimer
					if consoleplayer.growshrinktimer == 0
						COM_BufInsertText(consoleplayer, defaulttheme)
						tuned = 0
					end
				end
			end
		else
			COM_BufInsertText(consoleplayer, defaulttheme)
			tuned = 0
		end
	end
end)

//grow
addHook("ThinkFrame", do
	for player in players.iterate
		if not consoleplayer.exiting
			if consoleplayer.mo.skin == thecharacter
				if consoleplayer.growshrinktimer > 0 and tuned == 0 and not consoleplayer.exiting and not consoleplayer.invincibilitytimer then
					COM_BufInsertText(consoleplayer, customgrowtheme)
					tuned = 1
				elseif consoleplayer.exiting
					COM_BufInsertText(consoleplayer, defaulttheme)
					tuned = 0
				elseif consoleplayer.growshrinktimer == 0 and not consoleplayer.invincibilitytimer
					COM_BufInsertText(consoleplayer, defaulttheme)
					tuned = 0
				end
			end
		else
			COM_BufInsertText(consoleplayer, defaulttheme)
			tuned = 0
		end
	end
end)

addHook("GameQuit", function()
	if tuned == 1
		COM_BufInsertText(consoleplayer, defaulttheme)
		tuned = 0
	end
end)
