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
38 lines (36 loc) · 1.13 KB
/
index.js
File metadata and controls
38 lines (36 loc) · 1.13 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
// Script example for ScriptAPI
// Author: Jayly#1397 <Jayly Discord>
// Project: https://github.com/JaylyDev/ScriptAPI
import { Player, world } from "@minecraft/server"
/**
* Get score
* @param {string} objective
* @param {Player | string} target
* @param {boolean} useZero
* @returns
*/
function getScore(objective, target, useZero = false) {
try {
const obj = world.scoreboard.getObjective(objective);
if (typeof target == 'string') {
return obj.getScore(obj.getParticipants().find(v => v.displayName === target));
}
return obj.getScore(target.scoreboardIdentity);
} catch {
return useZero ? 0 : NaN;
}
}
function levelup() {
for (let player of world.getPlayers()) {
let xp = getScore('xp', player, true);
let xpmax = getScore('xpmax', player, true);
let level = getScore('level', player, true);
if (xp == xpmax && level <= 100) {
player.runCommand(`scoreboard players add @s level 1`)
player.runCommand(`scoreboard players set @s xp 0`)
xpmax += xpmax + (xpmax * 0.03)
player.runCommand(`scoreboard players set @s xpmax ${xpmax}`)
}
}
}
export { levelup }