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
73 lines (65 loc) · 1.49 KB
/
index.js
File metadata and controls
73 lines (65 loc) · 1.49 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Script example for ScriptAPI
// Author: FrankyRayMS#7172 <Bedrock Add-Ons>
// Project: https://github.com/JaylyDev/ScriptAPI
import {
world,
ScoreboardIdentity,
ScoreboardObjective,
} from "@minecraft/server";
const WILDCARD_INT = {
MIN: -2_147_483_648,
MAX: 2_147_483_647,
};
/**
* Test target's score on specific number range
*
* @param {string|ScoreboardIdentity} player
* Target/score holder
*
* @param {string|ScoreboardObjective} objective
* Scoreboard objective
*
* @param {"*"|number|null} min
* Minimum value/number (Allowed value: "*" - Wildcard Int)
*
* @param {"*"|number|null} max
* Maximum value/number (Allowed value: "*" - Wildcard Int)
*
* @return {boolean}
*/
export default function testScore(
player,
objective,
min = WILDCARD_INT.MIN,
max = WILDCARD_INT.MAX
) {
// Score
if (min === "*" || min === null) {
min = WILDCARD_INT.MIN;
}
if (max === "*" || max === null) {
max = WILDCARD_INT.MAX;
}
if (min > max) {
this.min = max;
this.max = min;
} else {
this.min = min;
this.max = max;
}
// Objective
if (typeof objective == "string") {
this.obj = world.scoreboard.getObjective(objective);
} else {
this.obj = objective;
}
// Player
if (typeof player == "string") {
this.plr = this.obj.getParticipants().find((v) => (v.displayName == player));
} else {
this.plr = player;
}
this.scr = this.obj.getScore(this.plr);
if (min < this.scr && this.scr > max) return true;
else return false;
}