Tagged: integration, rpgmod, tutorial, twitch
- This topic has 0 replies, 1 voice, and was last updated 10 months, 2 weeks ago by peq42.
-
AuthorPosts
-
December 22, 2023 at 17:37 #2577peq42Keymaster
RPGMod comes with twitch’s “tmi.js” library. It allows the client to connect to twitch and get all chat messages from a given channel. Through it, you can create your own custom, twitch integrated, map! Here’s how:
First:
Before anything, look at my tutorial on how to host a server and make a custom map. There I explain how to setup a custom map(it works both for servers and offline). On top of that, I recommend that you know the basics of javascript.
Programming stuff:
Initially, we will need the following piece of code:
const tmi = require(‘./js/plugins/tmi.js’);const client = new tmi.Client({connection: { reconnect: true },channels: [ localStorage.twitchname ]});client.connect().catch(FunctionToHandleErrors);This code will make the connection(reading the player’s twitch name, if they set it up within settings) and create an object named “client” to handle things. I recommend making a function to handle errors and placing it within catch above to help debug things.With the client object created, you can use “client.on” to handle messages(reminder that you can only read). For example:
client.on(‘cheer’, (channel, userstate, message) => {const username = userstate[‘display-name’];const amount = userstate.bits;$gameMessage.add(“Thanks for the “+amount+”bits ” +username+”!”);});client.on(‘message’, (channel, tags, message, self) => {$gameMessage.add(“${tags[‘display-name’]} said “+message);})Here if someone use bits, the event “cheer” is triggered, and a message is added in the game thanking them for it. If it’s a normal message, its just shown after the person’s name.Now you’ll need to place this code somewhere. You have two options for this:- Minimize your code and place it inside an event
- Place it within a .js file and call it from inside an event in a map.
Normally whenever the game loads a custom map, be it multiplayer or offline, it wont load the JS folder of a custom map for safety reasons, so I recommend using the first method(although a little… “junky”).
Save everything, package your map and test it out!
-
AuthorPosts
- You must be logged in to reply to this topic.