#cps counter only shows up in spawn

1 messages · Page 1 of 1 (latest)

lilac pawn
#

code where...

dire lantern
#
// Script example for ScriptAPI
// Author: Jayly <https://github.com/JaylyDev>
// Project: https://github.com/JaylyDev/ScriptAPI
import { Player, world, system } from 
"@minecraft/server";
;
//Using map because typescript doesn't support prototype property declaration properly
const clicks = new Map();
world.afterEvents.entityHitBlock.subscribe(function ({ damagingEntity }) {
    if (!(damagingEntity instanceof Player))
        return;
    const clickInfo = { timestamp: Date.now() };
    const playerClicks = clicks.get(damagingEntity) || [];
    playerClicks.push(clickInfo);
    clicks.set(damagingEntity, playerClicks);
});
world.afterEvents.entityHitEntity.subscribe(function ({ damagingEntity }) {
    if (!(damagingEntity instanceof Player))
        return;
    const clickInfo = { timestamp: Date.now() };
    const playerClicks = clicks.get(damagingEntity) || [];
    playerClicks.push(clickInfo);
    clicks.set(damagingEntity, playerClicks);
});
/**
 * Get a player's clicks per second
 * @param player
 * @returns
 */
export function getPlayerCPS(player) {
    const currentTime = Date.now();
    const playerClicks = clicks.get(player) || [];
    const recentClicks = playerClicks.filter(({ timestamp }) => currentTime - 1000 < timestamp);
    clicks.set(player, recentClicks);
    return recentClicks.length;
}

system.runInterval(() => {
    for (const player of world.getPlayers()){
      player.onScreenDisplay.setActionBar(`§d§lCps: ${getPlayerCPS(player)}`)
      if(getPlayerCPS(player)>15) {
        world.sendMessage(`${player.name} went over the Cps Limit ${getPlayerCPS(player)}`)
        player.runCommandAsync(`kick "${player.name}" Cps Limit ${getPlayerCPS(player)}`)
      }
      world.afterEvents.EntityHit((data) => {
          data.cancel = true;
      }); 
    }
})
;
#

jayals templet

sand salmon
#

Do you have any other actionsbars outside of spawn?

dire lantern
#

hm no

dire lantern
dire lantern
sand salmon
#

How does it only work in spawn

#

Nothing here tells me that it should only work in spawn