--BLUE BALLS
--By Callmore and fucked with by Ivo and Eldog

if (Bings_n_Rings_initialized) then return end -- Check if the script has already been run

freeslot("MT_BINGBVO", "sfx_bingss")

rawset(_G, "yellowballmode", CV_RegisterVar({
	name = "yellowballmode",
	defaultvalue = "Respawn",
	flags = CV_NETVAR,
	possiblevalue = {Off = 0, Once = 1, Respawn = 2}
}))

local function YellowBallSpecial(mt, mt2)
	--print("FUCKINGSPECIAL")
	if not (mt2.valid and mt2.player and mt2.player.valid) then return true end
	if not mt.pickedup then
		mt.pickedup = {}
	end
	if mt.pickedup[mt2.player] then
		return true
	end
	mt.pickedup[mt2.player] = true
	mt2.player.kartstuff[k_driftboost] = $+15
	S_StartSoundAtVolume(nil, sfx_bingss, 160, mt2.player)
	--print("FUCKINGSPEED")
	return true
end

addHook("TouchSpecial", YellowBallSpecial, MT_BINGBVO)
--print("FUCKINGBALLS")

local function YellowBallThink(mo)
    --Thinker for ivo's blue balls
	if not mo.pickedup then return end
    local newFlags = 0
    if not splitscreen then
        if mo.pickedup[displayplayers[0]] then
            newFlags = MF2_DONTDRAW
        end
        mo.flags2 = ($&~MF2_DONTDRAW)|newFlags
    else
        for p, n in displayplayers.iterate do
            if not mo.pickedup[p] then
                newFlags = MFE_DRAWONLYFORP1 << n
            end
            if newFlags then
                local flgs = MFE_DRAWONLYFORP1|MFE_DRAWONLYFORP2|MFE_DRAWONLYFORP3|MFE_DRAWONLYFORP4
                mo.eflags = ($&~flgs)|newFlags
            else
                mo.flags2 = $|MF2_DONTDRAW
            end
        end
    end
end

addHook("MobjThinker", YellowBallThink, MT_BINGBVO)

rawset(_G, "Bings_n_Rings_initialized", true) -- The script ran, don't run it again