]> git.lizzy.rs Git - dragonfireclient.git/blob - builtin/client/chatcommands.lua
fc6ed5b2bfdecf008c51c188a2b03bc571f19dad
[dragonfireclient.git] / builtin / client / chatcommands.lua
1 -- Minetest: builtin/client/chatcommands.lua
2
3 core.register_on_sending_chat_message(function(message)
4         if message:sub(1,2) == ".." then
5                 return false
6         end
7
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)
11         end
12
13         if first_char ~= "." then
14                 return false
15         end
16
17         local cmd, param = string.match(message, "^%.([^ ]+) *(.*)")
18         param = param or ""
19
20         if not cmd then
21                 core.display_chat_message(core.gettext("-!- Empty command"))
22                 return true
23         end
24
25         -- Run core.registered_on_chatcommand callbacks.
26         if core.run_callbacks(core.registered_on_chatcommand, 5, cmd, param) then
27                 return true
28         end
29
30         local cmd_def = core.registered_chatcommands[cmd]
31         if cmd_def then
32                 core.set_last_run_mod(cmd_def.mod_origin)
33                 local _, result = cmd_def.func(param)
34                 if result then
35                         core.display_chat_message(result)
36                 end
37         else
38                 core.display_chat_message(core.gettext("-!- Invalid command: ") .. cmd)
39         end
40
41         return true
42 end)
43
44 function core.run_server_chatcommand(cmd, param)
45         core.send_chat_message("/" .. cmd .. " " .. param)
46 end
47
48 core.register_chatcommand("say", {
49         description = "Send raw text",
50         func = function(text)
51                 core.send_chat_message(text)
52                 return true
53         end,
54 })
55
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)
61                 if success then
62                         core.localplayer:set_pos(pos)
63                         return true, "Teleporting to " .. core.pos_to_string(pos)
64                 end
65                 return false, pos
66         end,
67 })
68
69 core.register_chatcommand("wielded", {
70         description = "Print itemstring of wieleded item",
71         func = function()
72                 return true, core.localplayer:get_wielded_item():get_name()
73         end
74 })
75
76 core.register_chatcommand("disconnect", {
77         description = "Exit to main menu",
78         func = function(param)
79                 core.disconnect()
80         end,
81 })
82
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(), ", ")
87         end
88 })
89
90 core.register_chatcommand("kill", {
91         description = "Kill yourself",
92         func = function()
93                 core.send_damage(10000)
94         end,
95 })
96
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
105                 end
106
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."
111                         end
112                         core.settings:set(setname, setvalue)
113                         return true, setname .. " = " .. setvalue
114                 end
115
116                 setname = string.match(param, "([^ ]+)")
117                 if setname then
118                         setvalue = core.settings:get(setname)
119                         if not setvalue then
120                                 setvalue = "<not set>"
121                         end
122                         return true, setname .. " = " .. setvalue
123                 end
124
125                 return false, "Invalid parameters (see .help set)."
126         end,
127 })
128
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)
134                 if success then
135                         core.place_node(pos)
136                         return true, "Node placed at " .. core.pos_to_string(pos)
137                 end
138                 return false, pos
139         end,
140 })
141
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)
147                 if success then
148                         core.dig_node(pos)
149                         return true, "Node at " .. core.pos_to_string(pos) .. " dug"
150                 end
151                 return false, pos
152         end,
153 })
154
155 core.register_chatcommand("setyaw", {
156         params = "<yaw>",
157         description = "Set your yaw",
158         func = function(param)
159                 local yaw = tonumber(param)
160                 if yaw then
161                         core.localplayer:set_yaw(yaw)
162                         return true
163                 else
164                         return false, "Invalid usage (See .help setyaw)"
165                 end
166         end
167 })
168
169 core.register_chatcommand("setpitch", {
170         params = "<pitch>",
171         description = "Set your pitch",
172         func = function(param)
173                 local pitch = tonumber(param)
174                 if pitch then
175                         core.localplayer:set_pitch(pitch)
176                         return true
177                 else
178                         return false, "Invalid usage (See .help setpitch)"
179                 end
180         end
181 })
182
183 core.register_list_command("xray", "Configure X-Ray", "xray_nodes") 
184 core.register_list_command("search", "Configure NodeESP", "node_esp_nodes")