#Need help with crate system
1 messages · Page 1 of 1 (latest)
@hearty glacier
import { world, Player } from "@minecraft/server";
world.beforeEvents.playerInteractWithBlock.subscribe(ev => {
const jugador = ev.player;
const bloque = ev.block;
if (
!ev.isFirstEvent ||
!(jugador instanceof Player) ||
ev.itemStack?.typeId !== "minecraft:stick" ||
bloque.typeId !== "minecraft:grass"
) return;
});
Can you fix this I kept getting error like crate opening failed: TypeError: not a function @odd mantle
I Need help with my crate system
Do you think you can help me @odd mantle
Yo @odd mantle can you help me
@hearty glacier Pass code
Ok
This and can you make it use structure like if I get randomly got a apple it will load the structure apple above my head if you want to
And if you want to can you make it use a chance system so like 50percent or like 12 percent if you want you don’t have to I just if you don’t want to I just need this to work @odd mantle
There you go @odd mantle
checking if player is player is funny. You made a block and player variable but no itemstack?
Don't tag person multiple times bruv
Bro what ok
import { system, world, ItemStack } from '@minecraft/server';
const cooldowns = new Map();
const cooldownTime = 10 * 1000;
const rewards = [
{
name: 'Epic Sword',
itemId: 'minecraft:diamond_sword',
amount: 1,
lore: ['Forged in fire'],
nameTag: 'Epic Sword'
},
{
name: 'Golden Apple',
itemId: 'minecraft:golden_apple',
amount: 3
},
{
name: 'Diamond',
itemId: 'minecraft:diamond',
amount: 5
}
];
function getRandomReward() {
return rewards[Math.floor(Math.random() * rewards.length)];
}
world.beforeEvents.playerInteractWithBlock.subscribe((event) => {
const { player, block } = event;
if (block.typeId !== 'minecraft:light_gray_shulker_box') return;
const { container } = player.getComponent('inventory');
let keySlot = -1;
for (let i = 0; i < container.size; i++) {
const item = container.getItem(i);
if (item?.typeId === 'minecraft:trial_key') {
keySlot = i;
break;
}
}
if (keySlot === -1) return player.sendMessage('§cYou need a Crate Key to open this!');
const playerId = player.id;
const currentTime = Date.now();
if (cooldowns.has(playerId)) {
const lastUse = cooldowns.get(playerId);
const timePassed = currentTime - lastUse;
if (timePassed < cooldownTime) {
const secondsLeft = Math.ceil((cooldownTime - timePassed) / 1000);
return player.sendMessage(`§eCrate cooling down... ${secondsLeft}s left.`);
}
}
cooldowns.set(playerId, currentTime);
const reward = getRandomReward();
const itemStack = new ItemStack(reward?.itemId ?? 'minecraft:stick', reward?.amount ?? 1);
if (reward?.nameTag) itemStack.nameTag = reward.nameTag;
if (reward?.lore) itemStack.setLore(reward.lore);
if (container.emptySlotsCount === 0) return console.error('Inventory full');
else system.run(() => container.addItem(itemStack));
player.sendMessage(`§aYou opened a crate and received: §b${reward.name}`);
system.run(() => player.runCommand('playsound random.levelup @s'));
const keyItem = container.getItem(keySlot);
if (keyItem.amount > 1) {
keyItem.amount--;
system.run(() => container.setItem(keySlot, keyItem));
} else container.setItem(keySlot, undefined);
});```
Debug result for [code](#1395327878345916487 message)
Compiler found 1 errors:
[36m<REPL0>.js[0m:[33m74[0m:[33m5[0m - [31merror[0m[30m TS2304: [0mCannot find name 'system'.
[7m74[0m system.run(() => container.setItem(keySlot, keyItem));
[7m [0m [31m ~~~~~~[0m
There are no errors from ESLint.
No errors in [code](#1395327878345916487 message)
@hearty glacier