forked from JaylyDev/ScriptAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (37 loc) · 1.06 KB
/
index.js
File metadata and controls
39 lines (37 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Script example for ScriptAPI
// Author: iBlqzed#3612 <Bedrock Add-Ons>
// Project: https://github.com/JaylyDev/ScriptAPI
import { Player, Container } from "@minecraft/server";
let sellItems = [{
id: 'minecraft:sand',
value: 2
}, {
id: 'minecraft:gravel',
value: 4
}, {
id: 'minecraft:log',
value: 5
}]
/**
* Sell all items in a player's inventory
* @param {Player} player Player
* @returns {number} The amount that of money that the player made
*/
export const sell = (player) => {
/**
* @type {Container} The player's inventory container
*/
// @ts-ignore
const inv = player.getComponent('inventory').container, { size } = inv
let amount = 0;
for (let i = 0; i < size; i++) {
const item = inv.getItem(i)
if (!item) continue;
const soldItem = sellItems.find(element => element.id === item.typeId)
if (!soldItem) continue;
amount = amount + soldItem.value * item.amount
inv.setItem(i);
}
player.runCommand(`scoreboard players add @s Money ${amount}`)
return amount
}