//Borrowed From Miguel
if not(CBW_Battle) then return end
local ScriptLoaded = ScriptLoaded or false
if ScriptLoaded then return end
ScriptLoaded = true

local B = CBW_Battle
local cooldown = 8*TICRATE

B.Action.Hellno = function(mo, doaction)
    local player = mo.player
    -- Properties
    player.actiontext = "Deny"
	player.actionrings = 15

    local Hellno_cost = 15

    -- Initialize cooldown tracker if not already
    player.Hellno_cooldown = player.Hellno_cooldown or 0

    -- Ensure player is fakerguide
    if player and player.mo and player.mo.skin == "fakerguide" then
        if doaction then
            if player.rings >= Hellno_cost and player.Hellno_cooldown <= 0 then

                -- Apply Pity shield to player
                player.powers[pw_invulnerability] = 2*TICRATE

                player.rings = player.rings - Hellno_cost
                S_StartSound(player.mo, sfx_s3k73)
                player.Hellno_cooldown = cooldown
            end
        end
    end
end

addHook("ThinkFrame", function()
    for player in players.iterate do
        if player.mo and player.mo.valid then
            -- Initialize custom variables properly
            if player.Hellno_triggered == nil then player.Hellno_triggered = false end

            if player.spectator then continue end

            -- Ensure player is fakerguide
            if player.mo.skin == "fakerguide" then
                if (player.cmd.buttons & BT_ATTACK) ~= 0 and not player.Hellno_triggered then
                    B.Action.Hellno(player.mo, true)
                end

                -- Update shield triggered state
                player.Hellno_triggered = (player.cmd.buttons & BT_ATTACK) ~= 0

                -- Decrement cooldown if any
                if player.Hellno_cooldown and player.Hellno_cooldown > 0 then
                    player.Hellno_cooldown = player.Hellno_cooldown - 1
                end
            end
        end
    end
end)

addHook("PlayerQuit", function(player)
    player.Hellno_triggered = false
    player.Hellno_cooldown = 0
end)

//Battle!
local BattleFuncSet = false

addHook("ThinkFrame",function()
	if (BattleFuncSet) or not(CBW_Battle and CBW_Battle.SkinVars) then return end
	BattleFuncSet = true

	CBW_Battle.SkinVars["fakerguide"] = {
		flags = SKINVARS_GUARD,
		weight = 75,
		shields = 2,
		special = CBW_Battle.Action.Hellno,
		guard_frame = 1
	}
end)
