Could we have something like this:
game.on_console_chat (player_index, command, parameters)
Called when someone talks in-game either a player or through the server interface.
Contains
player_index :: uint (optional): The player if any.
message_index :: uint: The message index.
message :: string: The chat message.
game.on_pre_console_chat (player_index, command, parameters)
Called before a message is sent in-game
Contains
player_index :: uint (optional): The player if any.
message_index :: uint: The message index.
message :: string: The chat message.
game.map_settings.use_pre_console_chat = truegame.console_chat (player_index, message_index, message, cancel)
Cancels or modifies an in-game message before sending.
Parameters
player_index :: uint (optional): The player if any.
message_index :: uint: The message index.
message :: string (optional): The chat message.
cancel :: boolean (optional): cancel sending if true
Makes sending in-game message only possible with game.console_chat
(As we process the message and we do not know how long it takes between the beginning of the execution of the function and the end of the execution, it is necessary to prevent the sending of the original message. Either with a map option, or with a boolean configurable in LUA when on_init.)
Example of use :
Code: Select all
script.on_event(defines.events.on_on_pre_console_chat, function(e)
new_message = chat_filter(e.message)
if new_message == "" then
game.console_chat (e.player_index, e.message_index, false, true)
else
game.console_chat (e.player_index, e.message_index, new_message, false)
end
end)
Example 1 :
Example 2 :Before sendind :
Bob475: I do not care about your life asshole
In-game chat :
Bob475: I do not care about your life ****"
Before sendind :
Bob475: Fuck you
In-game chat :
(Nothing appears the message is canceled)
Example 3 :
(*With other personnal function)
And we can find other use cases.Before sendind :
Teo102: note.test
In-game chat :
Teo102: This is a pre-recorded message named test