Skip to content

Commit

Permalink
Added documentation for chat exports. (#234)
Browse files Browse the repository at this point in the history
Added full documentation on chat exports.
  • Loading branch information
The-Neco committed Jan 18, 2024
1 parent 29bdc05 commit 4bc0d0e
Show file tree
Hide file tree
Showing 11 changed files with 276 additions and 2 deletions.
10 changes: 9 additions & 1 deletion content/docs/resources/chat/_index.md
Expand Up @@ -10,7 +10,15 @@ It is included and maintained at the cfx-server-data repository.


## Exports
_This resource does not have any export functions._

### Client
- [addMessage](./exports/addMessagecl)
- [addSuggestion](./exports/addSuggestion)

### Server
- [addMessage](./exports/addMessagesv)
- [registerMessageHook](./exports/registerMessageHook)
- [registerMode](./exports/registerMode)

## Events

Expand Down
2 changes: 1 addition & 1 deletion content/docs/resources/chat/events/_index.md
Expand Up @@ -14,4 +14,4 @@ title: Events
- [chat:clear](./chat-clear)

### Server
- [chatMessage](./chatMessage)
- [chatMessage](./chatMessage)
14 changes: 14 additions & 0 deletions content/docs/resources/chat/exports/_index.md
@@ -0,0 +1,14 @@
---
title: Exports
---

## Exports

### Client
- [addMessage](./addMessagecl)
- [addSuggestion](./addSuggestion)

### Server
- [addMessage](./addMessagesv)
- [registerMessageHook](./registerMessageHook)
- [registerMode](./registerMode)
48 changes: 48 additions & 0 deletions content/docs/resources/chat/exports/addMessagecl.md
@@ -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)
48 changes: 48 additions & 0 deletions content/docs/resources/chat/exports/addMessagesv.md
@@ -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)
34 changes: 34 additions & 0 deletions content/docs/resources/chat/exports/addSuggestion.md
@@ -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 content/docs/resources/chat/exports/registerMessageHook.md
@@ -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)
53 changes: 53 additions & 0 deletions content/docs/resources/chat/exports/registerMode.md
@@ -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)
Binary file added static/chat_addMessage_export.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/chat_registerMessageHook.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/chat_registerMode.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4bc0d0e

Please sign in to comment.