--BLUE BALLS
--By Callmore and fucked with by Ivo and Eldog
--Fixed Fucked by ShihoAJoke

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

freeslot("MT_SHIBALL", "sfx_shibal")

local function BSphereSpecial(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] = $+7
	S_StartSoundAtVolume(nil, sfx_shibal, 160, mt2.player)
	--print("FUCKINGSPEED")
	return true
end

addHook("TouchSpecial", BSphereSpecial, MT_SHIBALL)
--print("FUCKINGBALLS")

local function BSphereThink(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", BSphereThink, MT_SHIBALL)

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