This repository was archived by the owner on May 1, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +57
-1
lines changed Expand file tree Collapse file tree 2 files changed +57
-1
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ Send random announcements at intervals using `/tellraw` command.
3+ Makes sure next message is not the same as the last.
4+
5+ v1
6+ */
7+
8+ import {
9+ getPlayerList
10+ } from "ez:player" ;
11+
12+ let system = server . registerSystem ( 0 , 0 ) ;
13+ let lastNo = 0 ;
14+
15+ //CHANGE ME
16+
17+ //Note: You can use colour codes, emojis and newline '\n' characters here.
18+ let messages = [
19+ "§l§4[!] §6To kill a mob, hit it until it dies." ,
20+ "§l§4[!] §6Does anyone actually read these?" ,
21+ "§l§4[!] §6You will die if you run out of health." ,
22+ "§l§4[!] §6Mitochondria is the powerhouse of the cell" ,
23+ "§l§4[!] §6Welcome to Joe's Crab Shack!" ,
24+ "§l§4[!] §6Press spacebar/\uE084/\uE000/\uE020 to jump."
25+ ] ;
26+ //Time between messages (in ticks)
27+ let cycleTime = 600 ;
28+
29+ //INTERVAL
30+
31+ let i = setInterval ( ( ) => {
32+ try {
33+ //Do not run if 0 players online
34+ if ( getPlayerList ( ) . length <= 0 ) {
35+ return ;
36+ }
37+ //Generate and display message
38+ let msg = randomMsg ( ) ;
39+ system . executeCommand ( `tellraw @a {"rawtext":[{"text":"${ msg } "}]}` , ( ) => { } ) ;
40+ } catch ( err ) {
41+ console . error ( err ) ;
42+ }
43+ } , cycleTime ) ;
44+
45+ //RANDOM
46+
47+ function randomMsg ( ) {
48+ //Random number between 0 and messages.length
49+ let r = 0 ;
50+ while ( lastNo === r ) {
51+ r = Math . floor ( Math . random ( ) * ( messages . length ) ) ;
52+ }
53+ lastNo = r ;
54+ return messages [ r ] ;
55+ }
Original file line number Diff line number Diff line change @@ -3,4 +3,5 @@ console.log("=== Info ===");
33import "./chatCommands.js" //Chat commands
44import "./playerJoin.js" //Player join message / welcome text
55import "./wild.js" //Adds a .wild command
6- import "./scoreboard.js" //Scoreboard
6+ import "./scoreboard.js" //Scoreboard
7+ import "./announcements.js" //Chat announcements
You can’t perform that action at this time.
0 commit comments