CPS progress bar code

World Code

Tags:

New Feature, Combat

Creator:

Itz_King_AkshxnOP

Code:

clicks = {};

onPlayerClick = (id) => {
    if (clicks[id] === undefined) {
        clicks[id] = [];
    }
    clicks[id].push(Date.now());
};

tick = () => {
    const now = Date.now();
    const ids = api.getPlayerIds();

    for (let id of ids) {
        if (clicks[id] === undefined) {
            clicks[id] = [];
        }

        clicks[id] = clicks[id].filter(t => now - t <= 1000);
        let cps = clicks[id].length;

        if (cps > 0) {
            let maxCpsGoal = 15;
            let filledSquares = Math.min(Math.floor((cps / maxCpsGoal) * 10), 10);
            
            let squareEmoji = "🟩"; 
            if (cps >= 12) {
                squareEmoji = "🟥"; 
            } else if (cps >= 7) {
                squareEmoji = "🟧"; 
            }

            let barUI = "";
            for (let i = 0; i < 10; i++) {
                barUI += i < filledSquares ? squareEmoji : "⬛";
            }

            api.setClientOption(id, "middleTextLower", "CPS: " + cps + "\n" + barUI);
        } else {
            api.setClientOption(id, "middleTextLower", "");
        }
    } 
};

Instructions:

Paste it in the world code and click to see that how it works and also credit me for this code.
Click faster to get high colour Lime -> Orange -> Red