Tutorial: Chat Tags

[Ins] InsertSoda
Joined 30/12/2017
Posts 463
01:24 PM 21/06/2020
In this tutorial im showing you how to make chat tags!

You need node-hill setup (so you can host your game) and little knowledge of javascript.

Begin by making a JavaScript file in the scripts folder of our node-hill installation.
Open the file in your favorite text editor and being programming.

To begin we need to figure out when a player chats and what they typed so we can modify the message to include the chat tag. Luckily theres the function Game.on() that we can use to run code when a action is made.

Game.on() Usage: Game.on(event, returnedInfo) => { code to run here });

The "event" in our Game.on() in our script needs to be "chat". The returnedInfo needs to be async(palyer, message).

It should look like this: Game.on("chat", async(player, message) => {});

Now we need to do if statements so we can mody the message correctly. Lets say i wan't to give Brick Hill admins a special tag. Node Hill has a admin property in the player object so we can check if player.admin equal true:

if(player.admin){

};

Now we need to send the message to the chat. Node Hil has the messageAll function in the Game object: Game.messageAll(message here) we need to include the message the player originally send to the server in the messageAll function and their username which can we get with the username property in the player object: player.username (returns a string)


So lets use it here:

if(player.admin){
Game.messageAll("[Brick Hill Admin] "+ player.username +": "+ message)
}

So now we gave a special tag to brick hill admins! Wait why are players complaining they can't chat? Oh with the Game.on function we told Node-Hill that we are gonna take care of the chat so it won't send anything to the chat. Lets fix this:

if(player.admin){
Game.messageAll("[Brick Hill Admin] "+ player.username +": "+ message)
}else{
Game.messageAll("[Player] "+ player.username +": "+ message)
}

Now if the player isn't an admin it will still be able to chat.
Now to add multiple tags you need more if statements and else.
Add the more important tags first and slowly go to the less important tags. Like this:

if(player.admin){
Game.messageAll("[Brick Hill Admin] "+ player.username +": "+ message)
}else{
if(player.userId == 1){
Game.messageAll("[MyNotSoImportantTag] "+ player.username +": "+ message)
}
}else{
Game.messageAll("[MyLessImportantTag] "+ player.username +": "+ message)
}

If you want to add color you need to type [HEX VALUE HERE] infront of the part you want to have colored. You need to the text white again before or after the player's username so that the entire chat message isn't colored.

Thanks for reading my first tutorial. I might have something wrong so please check the replies first if theres a error for a possible solution.


[TLVK] Edge.
Joined 19/05/2020
Posts 2,266
01:25 PM 21/06/2020
I'd recommend using Gist / Formatting for the tutorials. It makes it easier for the user to view the code.


[Ins] InsertSoda
Joined 30/12/2017
Posts 463
01:27 PM 21/06/2020
I can't space the code out so you have to include that to make reading it alot easier.

The finished code for lazy people:

Game.on("chat", async(player, message) => {
if(player.admin){
Game.messageAll("[Brick Hill Admin] "+ player.username +": "+ message)
}else{
if(player.userId == 1){
Game.messageAll("[MyNotSoImportantTag] "+ player.username +": "+ message)
}
}else{
Game.messageAll("[MyLessImportantTag] "+ player.username +": "+ message)
}
})


[USA] Sarcastic
Joined 15/10/2017
Posts 21,818
01:27 PM 21/06/2020
Bookmarked for the future. thanks


[Ins] InsertSoda
Joined 30/12/2017
Posts 463
01:27 PM 21/06/2020
Quote from Edge. , 01:25 PM 21/06/2020
I'd recommend using Gist / Formatting for the tutorials. It makes it easier for the user to view the code.
Any source for formatting tutorials?


[TLVK] Edge.
Joined 19/05/2020
Posts 2,266
01:56 PM 21/06/2020
Quote from InsertSoda , 01:27 PM 21/06/2020
Quote from Edge. , 01:25 PM 21/06/2020
I'd recommend using Gist / Formatting for the tutorials. It makes it easier for the user to view the code.

Any source for formatting tutorials?
Most markdown works fine on the forum.
https://guides.github.com/features/mastering-markdown/

You can always use gist to make a Markdown file and use all of its potential.


[TLVK] Edge.
Joined 19/05/2020
Posts 2,266
01:59 PM 21/06/2020
Quote from Edge. , 01:56 PM 21/06/2020
Quote from InsertSoda , 01:27 PM 21/06/2020
Quote from Edge. , 01:25 PM 21/06/2020
I'd recommend using Gist / Formatting for the tutorials. It makes it easier for the user to view the code.

Any source for formatting tutorials?

Most markdown works fine on the forum.
https://guides.github.com/features/mastering-markdown/

You can always use gist to make a Markdown file and use all of its potential.
I'll try Gist rn


[TLVK] Edge.
Joined 19/05/2020
Posts 2,266
02:08 PM 21/06/2020
Quote from Edge. , 01:59 PM 21/06/2020
Quote from Edge. , 01:56 PM 21/06/2020
Quote from InsertSoda , 01:27 PM 21/06/2020
Quote from Edge. , 01:25 PM 21/06/2020
I'd recommend using Gist / Formatting for the tutorials. It makes it easier for the user to view the code.

Any source for formatting tutorials?

Most markdown works fine on the forum.
https://guides.github.com/features/mastering-markdown/

You can always use gist to make a Markdown file and use all of its potential.

I'll try Gist rn
https://gist.github.com/Core-commits/25c960b3d3227d0c5b3ea6adb809fae0


[TLVK] Edge.
Joined 19/05/2020
Posts 2,266
02:10 PM 21/06/2020
Quote from Edge. , 02:08 PM 21/06/2020
Quote from Edge. , 01:59 PM 21/06/2020
Quote from Edge. , 01:56 PM 21/06/2020
Quote from InsertSoda , 01:27 PM 21/06/2020
Any source for formatting tutorials?

Most markdown works fine on the forum.
https://guides.github.com/features/mastering-markdown/

You can always use gist to make a Markdown file and use all of its potential.

I'll try Gist rn

https://gist.github.com/Core-commits/25c960b3d3227d0c5b3ea6adb809fae0
<script src="https://gist.github.com/Core-commits/25c960b3d3227d0c5b3ea6adb809fae0.js"></script>


[TLVK] Edge.
Joined 19/05/2020
Posts 2,266
02:10 PM 21/06/2020
Quote from Edge. , 02:10 PM 21/06/2020
Quote from Edge. , 02:08 PM 21/06/2020
Quote from Edge. , 01:59 PM 21/06/2020
Quote from Edge. , 01:56 PM 21/06/2020
Most markdown works fine on the forum.
https://guides.github.com/features/mastering-markdown/

You can always use gist to make a Markdown file and use all of its potential.

I'll try Gist rn

https://gist.github.com/Core-commits/25c960b3d3227d0c5b3ea6adb809fae0

<script src="https://gist.github.com/Core-commits/25c960b3d3227d0c5b3ea6adb809fae0.js"></script>
Noooo html is not a thing ensive:


[Ins] InsertSoda
Joined 30/12/2017
Posts 463
02:12 PM 21/06/2020
Quote from Edge. , 02:08 PM 21/06/2020
Quote from Edge. , 01:59 PM 21/06/2020
Quote from Edge. , 01:56 PM 21/06/2020
Quote from InsertSoda , 01:27 PM 21/06/2020
Any source for formatting tutorials?

Most markdown works fine on the forum.
https://guides.github.com/features/mastering-markdown/

You can always use gist to make a Markdown file and use all of its potential.

I'll try Gist rn

https://gist.github.com/Core-commits/25c960b3d3227d0c5b3ea6adb809fae0
testing console.log(&quot;aaaaaaaaaaaaaaa&quot;)

1 2