IMIsle Modkit
Pages in this area

chat

Server

Sending chat lines and reacting to what players type. Chat commands have their own page, commands.

modkit.chat.broadcast

modkit.chat.broadcast(text [, sender])

Shows a chat line to every player.

Parameter Type Description
text string the message
sender string name shown in front, default "Server"

Returns: number of players it was sent to.

modkit.setInterval(600000, function()
  modkit.chat.broadcast("Join our Discord, the link is in the launcher.", "Info")
end)

player:message

Chat line to one player. See player:message.

Event: chat

chat(player, text, mode)

Fires when a player sends a chat message that is not a registered command.

Argument Type Description
player player the sender
text string the message
mode integer 0 spatial, 1 global, 2 admin, 3 logging

Return false from a handler to cancel the message. A cancelled message reaches nobody. Any other return value, or none, lets it pass. When several handlers or resources listen, one false is enough.

modkit.events.add("chat", function(player, text, mode)
  if mode == 1 and not player.admin and #text > 200 then
    player:message("Global messages are limited to 200 characters.")
    return false
  end
end)

The handler runs inside the game's chat call, before the game processes the message. Keep it short.

Event: chatCommand

chatCommand(player, line)

Fires for every line that starts with / or !, and for the game's own chat command call. It fires before the command table is searched, for known and unknown commands.

Argument Type Description
player player the sender
line string the line without the leading / or !

This event can not cancel anything. Use it for logging.

modkit.events.add("chatCommand", function(player, line)
  print(player.steamId .. " ran /" .. line)
end)