API для разработчиков
Developer API
Because BUPA Chat provide 'chat', it implements the standard FiveM chat API. Any resource that already uses chat:addMessage, chat:addSuggestion etc. keeps working unchanged. BUPA Chat exposes each of these both as a networked event (chat:<name>) and as an export (in lowercase and Capitalized form).
The API surface is registered in utils/chat.lua:
registerEvent("addMessage", chatUtility.addMessage)
registerEvent("addSuggestion", chatUtility.addSuggestion)
registerEvent("addSuggestions", chatUtility.addSuggestions)
registerEvent("removeSuggestion", chatUtility.removeSuggestion)
registerEvent("removeSuggestions", chatUtility.removeSuggestions)
registerEvent("clear", chatUtility.clearMessages)registerEvent wires up the event chat:<name>, plus exports(name) and exports(Name), so all three call styles below are equivalent.
Adding a chat message
Client-side, push a message straight into chat:
-- Standard event (works from any resource)
TriggerEvent("chat:addMessage", {
color = { 255, 0, 0 },
multiline = true,
args = { "Dispatch", "A robbery is in progress downtown." },
})
-- Export form
exports.chat:addMessage({ args = { "System", "Server restarting soon." } })Message shape:
| Field | Type | Description |
|---|---|---|
args |
table | Message parts. With config.defaultAddTag, if there is more than one arg and no tags, the first arg becomes a tag and the rest is the body |
color |
RGB | Message / first-tag color { r, g, b } |
tags |
table[] | Explicit tags { tag, bgColor, textColor } |
multiline |
boolean | Allow the message to wrap across lines |
The classic chatMessage client event is also handled (name, color, message), so legacy TriggerClientEvent('chatMessage', ...) output still appears.
Suggestions
Suggestions power the command autocomplete panel. They can be added one at a time or in bulk, and removed the same way.
TriggerEvent("chat:addSuggestion", "/revive", "Revive a nearby player", {
{ name = "id", help = "Server ID of the target" },
})
TriggerEvent("chat:addSuggestions", {
{ name = "/heal", help = "Heal yourself" },
{ name = "/car", help = "Spawn a vehicle", params = {
{ name = "model", help = "Vehicle model", optional = true },
} },
})
TriggerEvent("chat:removeSuggestion", "/car")
exports.chat:clear() -- clear all messagesBUPA Chat auto-populates suggestions from every registered command the player has ACE access to (command.<name>), both on load and whenever a resource starts/stops. You only need chat:addSuggestion(s) for commands that need custom help text or parameters.
Notifications
BUPA Chat exposes a notification event named <resource>:notify — i.e. bupa-chat:notify — backed by ox_lib's lib.notify. It works from both client and server.
-- notify one player (server -> client): source, then Notify args
TriggerClientEvent("bupa-chat:notify", targetSrc, "MY_LOCALE_KEY", "success", 4000)TriggerEvent("bupa-chat:notify", "MY_LOCALE_KEY", "error", 5000)The handler is Notify(text, notifyType, duration, ...). text is passed through the t() localization wrapper, so you may pass a locale key (with format args) or plain text. notifyType defaults to inform and duration to 4000 ms.
Localization helpers
The following globals are available inside the resource (and to files loaded in its context):
| Symbol | Description |
|---|---|
t(key, ...) |
Thin wrapper over ox_lib locale(). Formats with %s/%d args and returns the key itself if the translation is missing |
GetLang() |
Returns the current flattened locale dictionary |
Notify(text, type, duration, ...) |
Fires the bupa-chat:notify notification |
Runtime language switch — bupa:changeLanguage
Trigger this client event to change a player's chat language live, without a restart. It reloads the locale and pushes it to the React UI:
TriggerEvent("bupa:changeLanguage", "fr")See Localization for details.