Using this export allows you to add message hooks to your chat that can modify and cancel chat messages.
outMessage structure:
outMessage = {
template = template,
color = color,
multiline = true,
args = {author, otherArgs...}
}
registerMessageHook
function hookFunction
object messageObject
)string seObject
)int/table player(s)
)This example replaces all chat messages with the word slugs to snails.
exports.chat:registerMessageHook(function(source, outMessage, hookRef)
if string.find(string.lower(outMessage.args[2]), "slugs") then
local filtered = string.gsub(string.lower(outMessage.args[2]), "slugs", "snails")
hookRef.updateMessage({
args = {
outMessage.args[1],
filtered -- updates the message with our version
}
})
--hookRef.cancel() -- You can also just cancel the message
exports.chat:addMessage(source, {
color = {255, 0, 0},
args = {"SYSTEM", "No slugs, just snails."}
}) -- Send them a friendly message.
end
end)