#Daily Reward function isnt working?

1 messages · Page 1 of 1 (latest)

dense zephyr
#
import { world, MinecraftEntityTypes, DynamicPropertiesDefinition } from "@minecraft/server";

const overworld = world.getDimension(`overworld`);

const formatTime = milliseconds => {
    const seconds = Math.floor((milliseconds / 1000) % 60);
    const minutes = Math.floor((milliseconds / 1000 / 60) % 60);
    const hours = Math.floor((milliseconds / 1000 / 60 / 60) % 24);

    return [
        hours.toString().padStart(2, "0"),
        minutes.toString().padStart(2, "0"),
        seconds.toString().padStart(2, "0")
    ];
};

world.afterEvents.worldInitialize.subscribe((world) => {
    let playerEntityProperties = new DynamicPropertiesDefinition();
    playerEntityProperties.defineString("lastClaimedDaily", 13);
    world.propertyRegistry.registerEntityTypeDynamicProperties(playerEntityProperties, MinecraftEntityTypes.player);
});


world.afterEvents.entityHitEntity.subscribe(data => {
    if (data.hitBlock) return;
    const npc = data.hitEntity;
    let player = data.damagingEntity;
    if (npc.hasTag('Dailyclaim')) {
        if (!Number.parseInt(player.getDynamicProperty("lastClaimedDaily"))) player.setDynamicProperty("lastClaimedDaily", "0");
        let timeSinceLastClaim = Date.now() - Number.parseInt(player.getDynamicProperty("lastClaimedDaily"));
        if (timeSinceLastClaim > 86400000) {
            player.playSound('random.levelup');
            player.sendMessage('§7[§c!§7]:§a Daily Reward Claimed!'); //Change Claim Message Here
            overworld.runCommandAsync(`give @a[name="${player.nameTag}"] netherite_scrap 2`);
            player.setDynamicProperty("lastClaimedDaily", Date.now().toString());
        } else {
            player.playSound('random.glass');
            let [hours, minutes, seconds] = formatTime(86400000 - timeSinceLastClaim);
            player.sendMessage(`§7[§c!§7]: You've already claimed you Daily Reward! You can claim again in §3${hours} hours ${minutes} minutes ${seconds} seconds`); //Change Claimed Message Here
        }
    }
})```
#

this is the error idk how to fix

toxic epoch
# dense zephyr this is the error idk how to fix

MinecraftEntityTypes has been moved from @minecraft/server to @minecraft/vanilla-data. You will need to learn how to bundle vanilla-data into your project so it ships with the pack and of course target it instead of @minecraft/server or change all instances to use strings such as minecraft:player.

vagrant beaconBOT
#
Debug Result

There are 10 errors in this [code](#1173102811635007629 message).
Please read the attached file for the result.

dense zephyr
#

its saying this now

#
import { MinecraftEntityTypes } from "@minecraft/vanilla-data";
import { world, DynamicPropertiesDefinition } from "@minecraft/server";```
dull quartz
dull quartz
#

Because vanilla data is not actually a Minecraft native module.

It is a folder that you download and put it in your scripts. You would have to import it like a normal file

#

npm install @minecraft/vanilla-data

dense zephyr
#

ohh

dull quartz
#

It will download a folder inside node_modules

#

Get that folder out of node_modules and put it on your scripts folder

#

Then use it like
import { .... } from "./vanilla-data/main.js"

#

Something like that, it's just an example

dense zephyr
#
import { MinecraftEntityTypes } from "./vanilla-data";```
What is wrong
dull quartz
#

Where did u saved the vanilla data folder

dense zephyr
#

same folder as the script

dull quartz
dense zephyr
dull quartz
#

Click lib and send ss

dense zephyr
dull quartz
# dense zephyr

Ok you would have to import it like this:

import { MinecraftEntityTypes } from './vanilla-data/lib/index.js'
#

And you don't need to use MinecraftEntityTypes from Minecraft vanilla data, you can use EntityTypes.getAll() from minecraft/server which is better.

dull quartz
#

Vanilla data could be useful for things like get all enchantments cuz there's not EnchantmentTypes.getAll()
...

dense zephyr
#

oh

#

also is there a way to get DynamicPropertiesDefinition

dull quartz