1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-10-08 22:42:06 +02:00
Files
ComfyFactorio/modules/floaty_chat.lua

70 lines
1.7 KiB
Lua
Raw Normal View History

2021-03-24 20:14:55 +01:00
local Event = require 'utils.event'
local Global = require 'utils.global'
local this = {
player_floaty_chat = {}
}
Global.register(
this,
function (tbl)
this = tbl
end
)
2019-05-07 23:38:14 +02:00
local function on_console_chat(event)
2021-03-24 16:46:00 +01:00
if not event.message then
return
end
if not event.player_index then
return
end
local player = game.players[event.player_index]
if not player.character then
return
end
2020-12-31 18:43:49 +01:00
2021-03-24 16:46:00 +01:00
local y_offset = -4
2020-12-31 18:43:49 +01:00
if this.player_floaty_chat[player.index] then
2024-10-25 21:56:34 +02:00
this.player_floaty_chat[player.index].destroy()
this.player_floaty_chat[player.index] = nil
2021-03-24 16:46:00 +01:00
end
2020-12-31 18:43:49 +01:00
2021-03-24 16:46:00 +01:00
local players = {}
for _, p in pairs(game.connected_players) do
if player.force.index == p.force.index then
players[#players + 1] = p
end
end
if #players == 0 then
return
end
2020-12-31 18:43:49 +01:00
2024-10-26 02:06:48 +02:00
if player.character.surface.index ~= player.physical_surface.index then return end
this.player_floaty_chat[player.index] =
2021-03-24 16:46:00 +01:00
rendering.draw_text {
text = event.message,
2024-10-26 02:06:48 +02:00
surface = player.physical_surface,
2024-10-15 12:27:17 +01:00
target = {
entity = player.character,
offset = { -0.05, y_offset },
},
color = {
r = player.color.r * 0.6 + 0.25,
g = player.color.g * 0.6 + 0.25,
b = player.color.b * 0.6 + 0.25,
a = 1
},
players = players,
time_to_live = 600,
scale = 1.50,
font = 'default-game',
alignment = 'center',
scale_with_zoom = false
}
2019-05-07 23:38:14 +02:00
end
2021-03-24 20:14:55 +01:00
Event.add(defines.events.on_console_chat, on_console_chat)