This repository was archived by the owner on Nov 13, 2023. It is now read-only.
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
83 lines (82 loc) · 2.47 KB
/
index.js
File metadata and controls
83 lines (82 loc) · 2.47 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
74
75
76
77
78
79
80
81
82
83
// Script example for ScriptAPI
// Author: Jayly#1397 <Jayly Discord>
// Project: https://github.com/JaylyDev/ScriptAPI
import { world, Entity } from "@minecraft/server";
/**
* Gets the score recorded for entity on objective
* @param {Entity} entity
* @param {string} objectiveId
*/
export function getScore(entity, objectiveId) {
const objective = world.scoreboard.getObjective(objectiveId);
return entity.scoreboard.getScore(objective);
}
/**
* Sets the score recorded for entity on objective
* @param {Entity} entity
* @param {string} objectiveId
* @param {number} score
*/
export function setScore(entity, objectiveId, score) {
const objective = world.scoreboard.getObjective(objectiveId);
return entity.scoreboard.setScore(objective, score);
}
/**
* Add the score recorded for entity on objective
* @param {Entity} entity
* @param {string} objectiveId
* @param {number} score
*/
export function addScore(entity, objectiveId, score) {
const previousScore = getScore(entity, objectiveId);
return setScore(entity, objectiveId, previousScore + score);
}
/**
* Subtract the score recorded for entity on objective
* @param {Entity} entity
* @param {string} objectiveId
* @param {number} score
*/
export function subtractScore(entity, objectiveId, score) {
const previousScore = getScore(entity, objectiveId);
return setScore(entity, objectiveId, previousScore - score);
}
/**
* Divide the score recorded for entity on objective
* @param {Entity} entity
* @param {string} objectiveId
* @param {number} score
*/
export function divideScore(entity, objectiveId, score) {
const previousScore = getScore(entity, objectiveId);
return setScore(entity, objectiveId, Math.floor(previousScore / score));
}
/**
* Test if the score recorded for entity on objective in range.
* @param {Entity} entity
* @param {string} objectiveId
* @param {number} min
* @param {number} max
*/
export function testScore(entity, objectiveId, min, max) {
const score = getScore(entity, objectiveId);
return score >= min && score <= max;
}
/**
* Set a random score between a range for entity on objective.
* @param {Entity} entity
* @param {string} objectiveId
* @param {number} min
* @param {number} max
*/
export function randomScore(entity, objectiveId, min, max) {
return setScore(entity, objectiveId, getRandomArbitrary(min, max));
}
/**
* @param {number} min
* @param {number} max
* @returns {number}
*/
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}