Category | Scripting |
Created | 17.11.2021 18:41 |
Daniel Kehr (Droggl) | 17.11.2021 18:41 |
---|---|
Hey, I am trying to create a mod to link ingame chat with a discord channel. (Maybe there is such a mod already, then please post it :) ) Is there any event or function to get a posted chat message on the dedicated server side? I tried to watch the ChatWindow.messages array inside the ChatWindow:update function, but this was not working for me. It is getting called, but it was not changing. Currently I only got 1 licence, so I needed to post chat messages with the dedi app. Maybe this is not working when no player is on the server?! Best regards |
Gtx | Andy (GtX_Andy) | 21.11.2021 03:20 |
---|---|
Hey Daniel, The last 50 chat messages are stored in the table 'g_currentMission.chatMessages'. You could append the 'Mission00.addChatMessage' function as this is called each time a message is sent on both Client and Server side. See the example appended function below with some options on how to monitor the messages. I hope this helps ;-) local function addChatMessage(mission, senderName, message) -- Server only check if mission:getIsServer() then -- Option 1 if senderName ~= nil and message ~= nil then -- Send to your Discord App here end -- Option 2 (If you do not want the same message spammed for example) local numMessages = #mission.chatMessages if numMessages > 0 then local lastMessage = mission.chatMessages[numMessages] local lastSyncedMessage = mission.lastSyncedMessage if lastSyncedMessage == nil or lastMessage.sender ~= lastSyncedMessage.sender or lastMessage.msg ~= lastSyncedMessage.msg then -- Save the last synced message mission.lastSyncedMessage = { sender = lastMessage.sender, msg = lastMessage.msg } -- Send to your Discord App here end end end end Mission00.addChatMessage = Utils.appendedFunction(Mission00.addChatMessage, addChatMessage) |
Daniel Kehr (Droggl) | 22.11.2021 12:22 |
---|---|
This is awesome. Thank you very much. As I understund, the only way to communicate with a Discord Bot is to save the messages into a file and read that file with the discord bot. Cause I run the server on a rented server I dont have the possibilities to run an external application (bot). Or is there any way to do http calls to an external webpage to use the discord rest api inside farm sim 22? |
Note: Log in to post. Create a new account here.