1 -- Minetest: builtin/client/chatcommands.lua
3 core.register_on_sending_chat_message(function(message)
4 if message:sub(1,2) == ".." then
8 local first_char = message:sub(1,1)
9 if first_char == "/" or first_char == "." then
10 core.display_chat_message(core.gettext("issued command: ") .. message)
13 if first_char ~= "." then
17 local cmd, param = string.match(message, "^%.([^ ]+) *(.*)")
21 core.display_chat_message(core.gettext("-!- Empty command"))
25 -- Run core.registered_on_chatcommand callbacks.
26 if core.run_callbacks(core.registered_on_chatcommand, 5, cmd, param) then
30 local cmd_def = core.registered_chatcommands[cmd]
32 core.set_last_run_mod(cmd_def.mod_origin)
33 local _, result = cmd_def.func(param)
35 core.display_chat_message(result)
38 core.display_chat_message(core.gettext("-!- Invalid command: ") .. cmd)
44 function core.run_server_chatcommand(cmd, param)
45 core.send_chat_message("/" .. cmd .. " " .. param)
48 core.register_chatcommand("say", {
49 description = "Send raw text",
51 core.send_chat_message(text)
56 core.register_chatcommand("teleport", {
57 params = "<X>,<Y>,<Z>",
58 description = "Teleport to coordinates.",
59 func = function(param)
60 local success, pos = core.parse_pos(param)
62 core.localplayer:set_pos(pos)
63 return true, "Teleporting to " .. core.pos_to_string(pos)
69 core.register_chatcommand("wielded", {
70 description = "Print itemstring of wieleded item",
72 return true, core.localplayer:get_wielded_item():get_name()
76 core.register_chatcommand("disconnect", {
77 description = "Exit to main menu",
78 func = function(param)
83 core.register_chatcommand("players", {
84 description = "List online players",
85 func = function(param)
86 return true, "Online players: " .. table.concat(core.get_player_names(), ", ")
90 core.register_chatcommand("kill", {
91 description = "Kill yourself",
93 core.send_damage(10000)
97 core.register_chatcommand("set", {
98 params = "([-n] <name> <value>) | <name>",
99 description = "Set or read client configuration setting",
100 func = function(param)
101 local arg, setname, setvalue = string.match(param, "(-[n]) ([^ ]+) (.+)")
102 if arg and arg == "-n" and setname and setvalue then
103 core.settings:set(setname, setvalue)
104 return true, setname .. " = " .. setvalue
107 setname, setvalue = string.match(param, "([^ ]+) (.+)")
108 if setname and setvalue then
109 if not core.settings:get(setname) then
110 return false, "Failed. Use '.set -n <name> <value>' to create a new setting."
112 core.settings:set(setname, setvalue)
113 return true, setname .. " = " .. setvalue
116 setname = string.match(param, "([^ ]+)")
118 setvalue = core.settings:get(setname)
120 setvalue = "<not set>"
122 return true, setname .. " = " .. setvalue
125 return false, "Invalid parameters (see .help set)."
129 core.register_chatcommand("place", {
130 params = "<X>,<Y>,<Z>",
131 description = "Place wielded item",
132 func = function(param)
133 local success, pos = core.parse_relative_pos(param)
136 return true, "Node placed at " .. core.pos_to_string(pos)
142 core.register_chatcommand("dig", {
143 params = "<X>,<Y>,<Z>",
144 description = "Dig node",
145 func = function(param)
146 local success, pos = core.parse_relative_pos(param)
149 return true, "Node at " .. core.pos_to_string(pos) .. " dug"
155 core.register_chatcommand("setyaw", {
157 description = "Set your yaw",
158 func = function(param)
159 local yaw = tonumber(param)
161 core.localplayer:set_yaw(yaw)
164 return false, "Invalid usage (See .help setyaw)"
169 core.register_chatcommand("setpitch", {
171 description = "Set your pitch",
172 func = function(param)
173 local pitch = tonumber(param)
175 core.localplayer:set_pitch(pitch)
178 return false, "Invalid usage (See .help setpitch)"
183 core.register_list_command("xray", "Configure X-Ray", "xray_nodes")
184 core.register_list_command("search", "Configure NodeESP", "node_esp_nodes")