#How would I create a cooldown for drops with Kubejs

10 messages · Page 1 of 1 (latest)

rain mirage
#

I made a script with Kubejs that has a small chance to drop coins from any entity you kill. However, I want to combat farming them by just creating mass mob farms to rapidly gather coins. Is there any way to add a cooldown time (maybe 15 seconds) before its possible for the coins to drop again?

timid pondBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

iron canyon
#

would have to use lootjs
id also attach the timer to the killing entity, so that its per player
that would also require the player tick event to decrease it tho. which is getting rather complex

mortal cosmosBOT
#

LootJS is an addon for KubeJS that allows modifying loot from all sources dynamically (much nicer than loot tables)!
It also supports removing loot added by mods, unlike KubeJS' current loot table events.

waxen patrol
#

You don't need the tick event. Just store the Gametime. Then you can use apply from lootjs to check for the current Gametime if the delta between the two gametimes is > 15 seconds. If yes, add loot and store the Gametime again.

iron canyon
#

ah yeah, that works too

waxen patrol
#

So at my PC now. Probably something like this

let lastCheckedGameTicks = 0;
let DELTA_TIME = 20 * 15; // 15 seconds
LootJS.modifiers((event) => {
    event.addLootTypeModifier(LootType.ENTITY).apply((ctx) => {
        let gameTicks = ctx.server.tickCount;
        if (gameTicks - lastCheckedGameTicks > DELTA_TIME) {
            lastCheckedGameTicks = gameTicks;
            ctx.addLoot("minecraft:diamond");
        }
    });
});

timid pondBOT
#

@rain mirage Unresolved thread still hasn't been closed! If your question was answered, please close this post with </ticket close:1054771505520717835> command!

rain mirage
# waxen patrol So at my PC now. Probably something like this ```js let lastCheckedGameTicks = 0...

Sorry I know this was forever ago that you sent it and the script works great. Im just wondering what I would add to it in order to make the item have a chance of dropping every 15 seconds, not a 100% chance of a drop every 15 seconds. I've been looking through the Lootjs and Kubejs wikis to try and find an answer but I havent been able to add one without my game crashing. I have tried doing ctx.addWeightedLoot, and adding .randomChance(.03) after the item but it doesnt work. Any more help would be appreciated greatly, especially since I am really not good at Kubejs haha

timid pondBOT
#

@rain mirage Unresolved thread still hasn't been closed! If your question was answered, please close this post with </ticket close:1054771505520717835> command!