Prefixes lets plugins handle chat messages that start with a certain text, such as // for
out of character chat, without making them commands.
Register a prefix on the server with Prefixes:add: messages that start with it are handed
to its callback instead of the regular chat, and are never treated as commands. The
PlayerUsedPrefix hook is run after a prefix has handled a message.
Summary
Hooks
Methods
Hooks
Implements hook PlayerSay
Hands chat messages that start with a registered prefix (or pass its check function)
over to that prefix instead of regular chat. Commands are left alone. While the Chatbox
plugin is loaded, only the text that Chatbox.submit passes on is handled here; anything
else is left to the chatbox, which submits it, so that its flood guard and length limit
apply to the prefixes as well.
Parameters
- actor Player the speaker
- text String the message
- team_chat Boolean whether the message was sent to team chat
Returns
- String empty string to suppress the message if a prefix matched, nil otherwise
Implements hook StringIsCommand
Prevents text that starts with a registered prefix from being treated as a command.
Parameters
- text String the text being checked
Returns
- Boolean false if the text starts with a registered prefix, nil otherwise
Methods
Registers a chat prefix, replacing any prefix with the same id. Serverside only. Messages that start with the prefix go to the callback instead of regular chat.
Prefixes:add('ooc', {
prefix = { '//', '((' },
callback = function(actor, message, team_chat)
-- message is the text with the prefix stripped
end
})
Parameters
- id String unique identifier of the prefix
- data Map prefix (lowercase String or List<String>), callback (Function that receives the player, the message without the prefix and team_chat) and optionally check (Function that receives the full text and returns true if it matches)
Prefixes:process_prefix(actor, prefix_id, prefix, text, team_chat)
server plugins/sh_prefixes.lua:65Strips the prefix from the message and passes the rest to the prefix's callback, then runs the PlayerUsedPrefix hook. Neither is run if nothing is left of the message.
Parameters
- actor Player the speaker
- prefix_id String id the prefix was registered with
- prefix String optional, defaults to
''the prefix text that matched - text String the full message
- team_chat Boolean whether the message was sent to team chat
Returns
- String always an empty string, which suppresses the original message