Chat: Restructure layout
This commit is contained in:
parent
4506a8c3da
commit
83067e5027
@ -8,19 +8,21 @@ redirect_from: /en/chapters/chat.html
|
|||||||
cmd_online:
|
cmd_online:
|
||||||
level: warning
|
level: warning
|
||||||
title: Offline players can run commands
|
title: Offline players can run commands
|
||||||
message: <p>A player name is passed instead of a player object because mods
|
message: |
|
||||||
can run commands on behalf of offline players. For example, the IRC
|
A player name is passed instead of a player object because mods
|
||||||
bridge allows players to run commands without joining the game.</p>
|
can run commands on behalf of offline players. For example, the IRC
|
||||||
|
bridge allows players to run commands without joining the game.
|
||||||
|
|
||||||
<p>So make sure that you don't assume that the player is online.
|
So make sure that you don't assume that the player is online.
|
||||||
You can check by seeing if <pre>minetest.get_player_by_name</pre> returns a player.</p>
|
You can check by seeing if `minetest.get_player_by_name` returns a player.
|
||||||
|
|
||||||
cb_cmdsprivs:
|
cb_cmdsprivs:
|
||||||
level: warning
|
level: warning
|
||||||
title: Privileges and Chat Commands
|
title: Privileges and Chat Commands
|
||||||
message: The shout privilege isn't needed for a player to trigger this callback.
|
message: |
|
||||||
This is because chat commands are implemented in Lua, and are just
|
The shout privilege isn't needed for a player to trigger this callback.
|
||||||
chat messages that begin with a /.
|
This is because chat commands are implemented in Lua, and are just
|
||||||
|
chat messages that begin with a /.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -29,17 +31,20 @@ cb_cmdsprivs:
|
|||||||
Mods can interact with player chat, including
|
Mods can interact with player chat, including
|
||||||
sending messages, intercepting messages, and registering chat commands.
|
sending messages, intercepting messages, and registering chat commands.
|
||||||
|
|
||||||
- [Sending Messages to All Players](#sending-messages-to-all-players)
|
- [Sending Messages](#sending-messages)
|
||||||
- [Sending Messages to Specific Players](#sending-messages-to-specific-players)
|
- [To All Players](#to-all-players)
|
||||||
|
- [To Specific Players](#to-specific-players)
|
||||||
- [Chat Commands](#chat-commands)
|
- [Chat Commands](#chat-commands)
|
||||||
- [Complex Subcommands](#complex-subcommands)
|
- [Accepting Multiple Arguments](#accepting-multiple-arguments)
|
||||||
- [Using string.split](#using-stringsplit)
|
- [Using string.split](#using-stringsplit)
|
||||||
- [Using Lua patterns](#using-lua-patterns)
|
- [Using Lua patterns](#using-lua-patterns)
|
||||||
- [Intercepting Messages](#intercepting-messages)
|
- [Intercepting Messages](#intercepting-messages)
|
||||||
|
|
||||||
## Sending Messages to All Players
|
## Sending Messages
|
||||||
|
|
||||||
To send a message to every player in the game, call the chat_send_all function.
|
### To All Players
|
||||||
|
|
||||||
|
To send a message to every player in the game, call the `chat_send_all` function.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
minetest.chat_send_all("This is a chat message to all players")
|
minetest.chat_send_all("This is a chat message to all players")
|
||||||
@ -53,9 +58,9 @@ Here is an example of how this appears in-game:
|
|||||||
|
|
||||||
The message appears on a separate line to distinguish it from in-game player chat.
|
The message appears on a separate line to distinguish it from in-game player chat.
|
||||||
|
|
||||||
## Sending Messages to Specific Players
|
### To Specific Players
|
||||||
|
|
||||||
To send a message to a specific player, call the chat_send_player function:
|
To send a message to a specific player, call the `chat_send_player` function:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
minetest.chat_send_player("player1", "This is a chat message for player1")
|
minetest.chat_send_player("player1", "This is a chat message for player1")
|
||||||
@ -82,20 +87,25 @@ minetest.register_chatcommand("foo", {
|
|||||||
In the above snippet, `interact` is listed as a required
|
In the above snippet, `interact` is listed as a required
|
||||||
[privilege](privileges.html) meaning that only players with the `interact` privilege can run the command.
|
[privilege](privileges.html) meaning that only players with the `interact` privilege can run the command.
|
||||||
|
|
||||||
|
`param` is a string containing everything a player writes after the chatcommand
|
||||||
|
name. For example, if a user types `/grantme one,two,three` then `param` will be
|
||||||
|
`one,two,three`.
|
||||||
|
|
||||||
Chat commands can return up to two values,
|
Chat commands can return up to two values,
|
||||||
the first being a Boolean indicating success, and the second being a
|
the first being a Boolean indicating success, and the second being a
|
||||||
message to send to the user.
|
message to send to the user.
|
||||||
|
|
||||||
{% include notice.html notice=page.cmd_online %}
|
{% include notice.html notice=page.cmd_online %}
|
||||||
|
|
||||||
## Complex Subcommands
|
### Accepting Multiple Arguments
|
||||||
|
|
||||||
It's common for chat commands to require multiple arguments, for example,
|
<a name="complex-subcommands"></a>
|
||||||
`/team join <team_name>`. There are two ways
|
|
||||||
of doing this, either using Minetest's string split or Lua patterns.
|
|
||||||
|
|
||||||
|
`param` gives you all the arguments to a chat command in a single string. It's
|
||||||
|
common for chat commands to need to extract multiple arguments. There are two
|
||||||
|
ways of doing this, either using Minetest's string split or Lua patterns.
|
||||||
|
|
||||||
### Using string.split
|
#### Using string.split
|
||||||
|
|
||||||
A string can be split up into words using `string.split(" ")`:
|
A string can be split up into words using `string.split(" ")`:
|
||||||
|
|
||||||
@ -120,8 +130,7 @@ else
|
|||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Using Lua patterns
|
||||||
### Using Lua patterns
|
|
||||||
|
|
||||||
[Lua patterns](https://www.lua.org/pil/20.2.html) are a way of extracting stuff
|
[Lua patterns](https://www.lua.org/pil/20.2.html) are a way of extracting stuff
|
||||||
from text using rules. They're best suited for when there are arguments that can
|
from text using rules. They're best suited for when there are arguments that can
|
||||||
|
Loading…
x
Reference in New Issue
Block a user