1 -- Boilerplate to support localized strings if intllib mod is installed.
3 if minetest
.get_modpath("intllib") then
6 S
= function(s
,a
,...)a
={a
,...}return s
:gsub("@(%d+)",function(n
)return a
[tonumber(n
)]end)end
10 if(minetest
.setting_getbool("enable_damage") == true) then
11 minetest
.register_privilege("heal", {
12 description
= S("Allows player to set own health and breath with /sethp, /sethealth and /setbreath"),
13 give_to_singleplayer
= false
16 minetest
.register_privilege("physics", {
17 description
= S("Allows player to set own gravity, jump height and movement speed with /setgravity, /setjump and /setspeed, respectively"),
18 give_to_singleplayer
= false
20 minetest
.register_privilege("hotbar", {
21 description
= S("Allows player to set the number of slots of the hotbar with /sethotbarsize"),
22 give_to_singleplayer
= false
25 --[[ informational commands ]]
26 minetest
.register_chatcommand("whoami", {
28 description
= S("Shows your player name"),
31 minetest
.chat_send_player(name
, S("Your player name is @1.", name
))
35 minetest
.register_chatcommand("ip", {
37 description
= S("Shows your IP address"),
40 minetest
.chat_send_player(name
, S("Your IP address is @1.", minetest
.get_player_ip(name
)))
45 minetest
.register_chatcommand("sethotbarsize", {
46 params
= S("<1...23>"),
47 description
= S("Sets the size of your hotbar to the provided number of slots; the number must be between 1 and 23"),
48 privs
= {hotbar
=true},
49 func
= function(name
, slots
)
51 minetest
.chat_send_player(name
, S("You did not specify the parameter."))
54 if type(tonumber(slots
)) ~= "number" then
55 minetest
.chat_send_player(name
, S("This is not a number."))
58 if tonumber(slots
) < 1 or tonumber(slots
) > 23 then
59 minetest
.chat_send_player(name
, S("Number of slots is out of bounds. The number of slots must be between 1 and 23."))
62 local player
= minetest
.get_player_by_name(name
)
63 player
:hud_set_hotbar_itemcount(tonumber(slots
))
67 --[[ health and breath commands ]]
69 if(minetest
.setting_getbool("enable_damage") == true) then
70 minetest
.register_chatcommand("sethp", {
72 description
= S("Sets your health to <hp> HP (=half the number of “hearts”)"),
74 func
= function(name
, hp
)
75 local player
= minetest
.get_player_by_name(name
)
80 minetest
.chat_send_player(name
, S("You did not specify the parameter."))
83 if type(tonumber(hp
)) ~= "number" then
84 minetest
.chat_send_player(name
, S("This is not a number."))
87 hp
= math
.max(0, math
.floor(hp
+0.5)) -- round the number, ensure minimum value of 0
88 player
:set_hp(tonumber(hp
))
92 minetest
.register_chatcommand("sethealth", {
93 params
= S("<hearts>"),
94 description
= S("Sets your health to <hearts> hearts"),
96 func
= function(name
, hearts
)
97 local player
= minetest
.get_player_by_name(name
)
102 minetest
.chat_send_player(name
, S("You did not specify the parameter."))
105 if type(tonumber(hearts
)) ~= "number" then
106 minetest
.chat_send_player(name
, S("This is not a number."))
109 local hp
= tonumber(hearts
) * 2
110 hp
= math
.max(0, math
.floor(hp
+0.5)) -- round the number, ensure minimum value of 0
115 minetest
.register_chatcommand("setbreath", {
116 params
= S("<breath>"),
117 description
= S("Sets your breath to <breath> breath points"),
119 func
= function(name
, breath
)
120 local player
= minetest
.get_player_by_name(name
)
125 minetest
.chat_send_player(name
, S("You did not specify the parameter."))
128 if type(tonumber(breath
)) ~= "number" then
129 minetest
.chat_send_player(name
, S("This is not a number."))
132 local bp
= math
.max(0, tonumber(breath
)) -- ensure minimum value of 0
133 player
:set_breath(bp
)
137 minetest
.register_chatcommand("killme", {
139 description
= S("Kills yourself"),
140 func
= function(name
, param
)
141 local player
= minetest
.get_player_by_name(name
)
150 --[[ Player physics commands ]]
153 minetest
.register_chatcommand("setspeed", {
154 params
= S("[<speed>]"),
155 description
= S("Sets your movement speed to <speed> (default: 1)"),
156 privs
={physics
=true},
157 func
= function(name
, speed
)
158 local player
= minetest
.get_player_by_name(name
)
165 if type(tonumber(speed
)) ~= "number" then
166 minetest
.chat_send_player(name
, S("This is not a number."))
170 player
:set_physics_override(tonumber(speed
), nil, nil)
175 minetest
.register_chatcommand("setgravity", {
176 params
= S("[<gravity>]"),
177 description
= S("Sets your gravity to <gravity> (default: 1)"),
178 privs
={physics
=true},
179 func
= function(name
, gravity
)
180 local player
= minetest
.get_player_by_name(name
)
184 if gravity
== "" then
187 if type(tonumber(gravity
)) ~= "number" then
188 minetest
.chat_send_player(name
, S("This is not a number."))
191 player
:set_physics_override(nil, tonumber(gravity
), nil)
196 minetest
.register_chatcommand("setjump", {
197 params
= S("[<jump height>]"),
198 description
= S("Sets your jump height to <jump height> (default: 1)"),
199 privs
= {physics
=true},
200 func
= function(name
, jump_height
)
201 local player
= minetest
.get_player_by_name(name
)
205 if jump_height
== "" then
208 if type(tonumber(jump_height
)) ~= "number" then
209 minetest
.chat_send_player(name
, S("This is not a number."))
212 player
:set_physics_override(nil, nil, jump_height
)
216 minetest
.register_chatcommand("pulverizeall", {
218 description
= S("Destroys all items in your player inventory and crafting grid"),
219 func
= function(name
, param
)
220 local player
= minetest
.get_player_by_name(name
)
224 local inv
= player
:get_inventory()
225 inv
:set_list("main", {})
226 inv
:set_list("craft", {})