-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlocalGlobalChat.js
More file actions
76 lines (70 loc) · 3.01 KB
/
localGlobalChat.js
File metadata and controls
76 lines (70 loc) · 3.01 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
//██╗░░░░░░█████╗░░█████╗░░█████╗░██╗░░░░░░█████╗░██╗░░██╗░█████╗░████████╗
//██║░░░░░██╔══██╗██╔══██╗██╔══██╗██║░░░░░██╔══██╗██║░░██║██╔══██╗╚══██╔══╝
//██║░░░░░██║░░██║██║░░╚═╝███████║██║░░░░░██║░░╚═╝███████║███████║░░░██║░░░
//██║░░░░░██║░░██║██║░░██╗██╔══██║██║░░░░░██║░░██╗██╔══██║██╔══██║░░░██║░░░
//███████╗╚█████╔╝╚█████╔╝██║░░██║███████╗╚█████╔╝██║░░██║██║░░██║░░░██║░░░
//╚══════╝░╚════╝░░╚════╝░╚═╝░░╚═╝╚══════╝░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝░░░╚═╝░░░
//
//Allows to use local and global chat in your game!
//Author: qIMIXERIp vk.com/svtlng
//Version 2.0.1
//config
let radius = 10 //Radius of local message (in blocks)
let globalSymbol = '!' //Symbol that marks message as global
let globalPrefix = '[G]' //Prefix that marks message as global
let headChat = true //Displays messages above player's head
let smallMessage = 10 //Amount of symbols that small message has
let useMuteSystem = true //Set to true if you are using this script witn MixerAPI
//yes, I could make it in JSON but I don't want to
function setHeadMsg(mes, plr) {
let name = plr.realName
plr.rename(`${name}\n>> ${mes}`)
function nameback(){
plr.rename(plr.realName)
}
if(mes.length >= smallMessage){
setTimeout(nameback, mes.length * 500)
}else{
setTimeout(nameback, mes.length * 1000)
}
}
function sendMsgToChat(type, mssg, name, x, y, z){
switch(type){
case 0:
mc.runcmd(`tellraw @a[x=${x},y=${y},z=${z},r=${radius}] {"rawtext":[{"text":"<${name}> ${mssg}"}]}`)
break;
case 1:
mc.runcmd(`tellraw @a {"rawtext":[{"text":"${globalPrefix} <${name}> ${mssg}"}]}`)
break;
}
}
mc.listen('onChat', function(player, msg){
let isMuted = player.hasTag(`is_muted`)
let rname = player.realName
let x = player.pos.x
let y = player.pos.y
let z = player.pos.z
let muteMsg
let isGlobal = msg[0] == globalSymbol
if (isMuted && useMuteSystem){
return false
muteMsg = true
}
if (headChat && !muteMsg) {
if (isGlobal){
msg = msg.replace(globalSymbol,'')
setHeadMsg(msg, player)
}else{
setHeadMsg(msg, player)
}
}
if (!muteMsg){
if (isGlobal){
sendMsgToChat(1, msg, rname, x, y, z)
return false
}else{
sendMsgToChat(0, msg, rname, x, y, z)
return false
}
}
})