world.afterEvents.playerInteractWithEntity.subscribe((event) => {
const { player, target } = event;
if (target.typeId !== 'ngc:shop_gun') return
shopgun(player);
});
function calculateCash(player) {
let cash = 0;
const playerInventory = player.inventory;
const items = playerInventory.items;
for (const item of items) {
if (item.type === 'tnt') {
cash += 10;
} else if (item.type === 'grass') {
cash += 1;
}
// Ajoutez plus de conditions pour d'autres objets si nécessaire
}
return cash;
}
function shopgun(player) {
const cash = calculateCash(player);
const form = new ActionFormData();
form.title("Boutique");
form.body(`Vous avez actuellement ${cash} cash.`);
form.button("Arme 1");
form.button("Arme 2");
form.show(player).then((r) => {
if (r.canceled) return;
if (r.selection === 0) {
// Logique pour Arme 1
}
});
}
#not resolve
1 messages · Page 1 of 1 (latest)
to get the inventory of a player, use player.getComponent('minecraft:inventory')
the problem is y try to convert item valeur to score
and is not work
ex tnt = 10 and grass = 1
and set variable total of item and prise
okay, first you would need an object to hold the prices of each item