mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Added Chat Popups
This commit is contained in:
@@ -14,6 +14,8 @@ return {
|
||||
'modules.commands.cheat-mode',
|
||||
'modules.commands.interface',
|
||||
'modules.commands.help',
|
||||
-- QoL Addons
|
||||
'modules.addons.chat-popups',
|
||||
-- Config Files
|
||||
'config.command_auth_admin', -- commands tags with admin_only are blocked for non admins
|
||||
'config.permission_groups', -- loads some predefined permission groups
|
||||
|
||||
3
locale/en/addons.cfg
Normal file
3
locale/en/addons.cfg
Normal file
@@ -0,0 +1,3 @@
|
||||
[chat-popup]
|
||||
message=__1__: __2__
|
||||
ping=You have been mentioned in chat by __1__.
|
||||
3
modules/addons/addons.cfg
Normal file
3
modules/addons/addons.cfg
Normal file
@@ -0,0 +1,3 @@
|
||||
[chat-popup]
|
||||
message=__1__: __2__
|
||||
ping=You have been mentioned in chat by __1__.
|
||||
30
modules/addons/chat-popups.lua
Normal file
30
modules/addons/chat-popups.lua
Normal file
@@ -0,0 +1,30 @@
|
||||
--- Creates flying text entities when a player sends a message in chat
|
||||
-- also displays a ping above users who are named in the message
|
||||
local Game = require 'utils.game'
|
||||
local Event = require 'utils.event'
|
||||
|
||||
local send_text = Game.print_player_floating_text -- (player_index, text, color)
|
||||
|
||||
Event.add(defines.events.on_console_chat,function(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
|
||||
-- Some basic sanity checks
|
||||
if not player then return end
|
||||
if not event.message then return end
|
||||
|
||||
-- Sends the message as text above them
|
||||
send_text(player.index,{'chat-popup.message',player.name,event.message},player.chat_color)
|
||||
|
||||
-- Makes lower and removes white space from the message
|
||||
local search_string = event.message:lower():gsub("%s+", "")
|
||||
|
||||
-- Loops over online players to see if they name is included
|
||||
for _,mentioned_player in pairs(game.connected_players) do
|
||||
if mentioned_player.index ~= player.index then
|
||||
if search_string:match(mentioned_player.name:lower()) then
|
||||
send_text(mentioned_player.index,{'chat-popup.ping',player.name},player.chat_color)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end)
|
||||
Reference in New Issue
Block a user