#Dynamic properties not working as I want

1 messages · Page 1 of 1 (latest)

old oracle
#

I want to make a cps counter for my world but when I try this it doesn't seem to work. (1st image)
I'm also trying to display a player's own cps, but it ends up just showing the same thing for everyone in the actionbar. (2nd image)

import { world, system } from "@minecraft/server";

world.afterEvents.entityHitEntity.subscribe((data) => {
    let damagingEntity = data.damagingEntity;

    if (damagingEntity?.typeId !== "minecraft:player") return;

    const amount = damagingEntity.getDynamicProperty("cps");
    damagingEntity.setDynamicProperty("cps", amount + 1);

    console.warn(amount)

    system.runTimeout(() => {
        damagingEntity.setDynamicProperty("cps", amount - 1);
    }, 20);
});

//display
system.runInterval(() => {
    world.getAllPlayers().forEach((damagingEntity) => {

        const amount = damagingEntity.getDynamicProperty("cps");
        damagingEntity.onScreenDisplay.setActionBar(amount)

    });
});```
crimson yarrow
#

why do u need to save the cps

old oracle
#

so I can see what their cps is..?

crimson yarrow
#

just cache it

nimble girderBOT
#

Suggestion for @old oracle

Description
A function to get player's clicks in a second

Credits
These scripts were written by Jayly

crimson yarrow
#

just use that

#

its more than removing 1 every second or so