Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added documentation for chat exports. (#234)
Added full documentation on chat exports.
- Loading branch information
Showing
11 changed files
with
276 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
title: Exports | ||
--- | ||
|
||
## Exports | ||
|
||
### Client | ||
- [addMessage](./addMessagecl) | ||
- [addSuggestion](./addSuggestion) | ||
|
||
### Server | ||
- [addMessage](./addMessagesv) | ||
- [registerMessageHook](./registerMessageHook) | ||
- [registerMode](./registerMode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
title: addMessage (client) | ||
--- | ||
|
||
## About | ||
Using this export allows you to add a message to the local players chat.<br> | ||
Message object structure: | ||
|
||
```lua | ||
message = { | ||
template = template, | ||
color = color, | ||
multiline = true, | ||
args = {author, otherArgs...} | ||
} | ||
``` | ||
|
||
## Name | ||
``` | ||
addMessage | ||
``` | ||
|
||
Parameters | ||
---------- | ||
|
||
``` | ||
object/string message | ||
``` | ||
|
||
Examples | ||
-------- | ||
|
||
This example sends a chat message to a player locally from a client script (only the executing client will see it). | ||
|
||
##### Lua Example: | ||
```lua | ||
AddEventHandler('onResourceStart', function(resourceName) | ||
if (GetCurrentResourceName() ~= resourceName) then | ||
return | ||
end | ||
exports.chat:addMessage({ | ||
color = {255, 0, 0}, | ||
args = {"SYSTEM", string.format("%s has started.", resourceName)} | ||
}) | ||
end) | ||
``` | ||
Output:<br> | ||
![screenshot-1](/chat_addMessage_export.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
title: addMessage (server) | ||
--- | ||
|
||
## About | ||
Using this export allows you to add a message to the target players chat.<br> | ||
Message object structure: | ||
|
||
```lua | ||
message = { | ||
template = template, | ||
color = color, | ||
multiline = true, | ||
args = {author, otherArgs...} | ||
} | ||
``` | ||
|
||
## Name | ||
``` | ||
addMessage | ||
``` | ||
|
||
Parameters | ||
---------- | ||
|
||
``` | ||
int target, object/string message | ||
``` | ||
|
||
Examples | ||
-------- | ||
|
||
This example sends a chat message to all players. | ||
|
||
##### Lua Example: | ||
```lua | ||
AddEventHandler('onResourceStart', function(resourceName) | ||
if (GetCurrentResourceName() ~= resourceName) then | ||
return | ||
end | ||
exports.chat:addMessage(-1, { | ||
color = {255, 0, 0}, | ||
args = {"SYSTEM", string.format("%s has started.", resourceName)} | ||
}) | ||
end) | ||
``` | ||
Output:<br> | ||
![screenshot-1](/chat_addMessage_export.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
title: addSuggestion | ||
--- | ||
|
||
## About | ||
Using this export allows you to add command suggestions to your chat. | ||
|
||
## Name | ||
``` | ||
addSuggestion | ||
``` | ||
|
||
Parameters | ||
---------- | ||
|
||
``` | ||
string commandName, string commandDescription, object commandParameters | ||
``` | ||
|
||
Examples | ||
-------- | ||
This example adds a command suggestion for the `/command` command. | ||
|
||
##### Lua Example: | ||
```lua | ||
-- Note, the command has to start with `/`. | ||
exports.chat:addSuggestion('/command', 'help text', { | ||
{ name="paramName1", help="param description 1" }, | ||
{ name="paramName2", help="param description 2" } | ||
}) | ||
``` | ||
|
||
## Example Result: | ||
![screenshot-1](/chat_addSuggestion.png) |
69 changes: 69 additions & 0 deletions
69
content/docs/resources/chat/exports/registerMessageHook.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--- | ||
title: registerMessageHook | ||
--- | ||
|
||
|
||
## About | ||
Using this export allows you to add message hooks to your chat that can modify and cancel chat messages.<br> | ||
outMessage structure: | ||
|
||
```lua | ||
outMessage = { | ||
template = template, | ||
color = color, | ||
multiline = true, | ||
args = {author, otherArgs...} | ||
} | ||
``` | ||
|
||
## Name | ||
``` | ||
registerMessageHook | ||
``` | ||
|
||
Parameters | ||
---------- | ||
|
||
``` | ||
function hookFunction | ||
``` | ||
|
||
hookRef functions | ||
---------- | ||
|
||
### updateMessage(`object messageObject`) | ||
- Updates the message object to the one specified in the function. | ||
### cancel() | ||
- Cancels the sending of the current message. | ||
### setSeObject(`string seObject`) | ||
- Changes the current message ace requirement. | ||
### setRouting(`int/table player(s)`) | ||
- Changes the routing of the current message (Who it is being sent to). | ||
|
||
|
||
Examples | ||
-------- | ||
This example replaces all chat messages with the word slugs to snails. | ||
|
||
##### Lua Example: | ||
```lua | ||
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) | ||
``` | ||
|
||
## Example Result: | ||
![screenshot-1](/chat_registerMessageHook.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--- | ||
title: registerMode | ||
--- | ||
|
||
## About | ||
Using this export allows you to add modes to your chat.<br> | ||
Mode object structure: | ||
|
||
```lua | ||
message = { | ||
name = name, | ||
displayName = displayName, | ||
color = color, | ||
seObject = seObject, | ||
cb = cb | ||
} | ||
``` | ||
|
||
## Name | ||
``` | ||
registerMode | ||
``` | ||
|
||
Parameters | ||
---------- | ||
|
||
``` | ||
object modeData | ||
``` | ||
|
||
Examples | ||
-------- | ||
This example adds a admin chat for all players with the permission `admin.chat`. | ||
|
||
##### Lua Example: | ||
```lua | ||
exports.chat:registerMode({ | ||
name = "adminChat", | ||
displayName = "Admin", | ||
color = "#fca503", | ||
seObject = "admin.chat", | ||
cb = function(source, message, cbs) | ||
cbs.updateMessage({ | ||
template = "[ADMIN]" .. ' {}' | ||
}) | ||
|
||
cbs.setSeObject("admin.chat") | ||
end | ||
}) | ||
``` | ||
|
||
## Example Result: | ||
![screenshot-1](/chat_registerMode.png) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.