File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // https://discord.com/channels/523663022053392405/854033525546942464/995831911039647824
2+ import { Player , world } from "mojang-minecraft"
3+
4+ /**
5+ * Get score
6+ * @param {string } objective
7+ * @param {Player | string } target
8+ * @param {boolean } useZero
9+ * @returns
10+ */
11+ function getScore ( objective , target , useZero = false ) {
12+ try {
13+ const obj = world . scoreboard . getObjective ( objective ) ;
14+ if ( typeof target == 'string' ) {
15+ return obj . getScore ( obj . getParticipants ( ) . find ( v => v . displayName === target ) ) ;
16+ }
17+ return obj . getScore ( target . scoreboard ) ;
18+ } catch {
19+ return useZero ? 0 : NaN ;
20+ }
21+ }
22+
23+ function levelup ( ) {
24+ for ( let player of world . getPlayers ( ) ) {
25+ let xp = getScore ( 'xp' , player , true ) ;
26+ let xpmax = getScore ( 'xpmax' , player , true ) ;
27+ let level = getScore ( 'level' , player , true ) ;
28+ if ( xp == xpmax && level <= 100 ) {
29+ world . getDimension ( "overworld" ) . runCommand ( `scoreboard players add @s level 1` )
30+ world . getDimension ( "overworld" ) . runCommand ( `scoreboard players set @s xp 0` )
31+ xpmax += xpmax + ( xpmax * 0.03 )
32+ world . getDimension ( "overworld" ) . runCommand ( `scoreboard players set @s xpmax ${ xpmax } ` )
33+ }
34+ }
35+ }
36+ export { levelup }
You can’t perform that action at this time.
0 commit comments