1 local minecraftaliases
= true
3 local S
= minetest
.get_translator("mcl_commands")
5 local mod_death_messages
= minetest
.get_modpath("mcl_death_messages")
7 local function handle_kill_command(suspect
, victim
)
8 if minetest
.settings
:get_bool("enable_damage") == false then
9 return false, S("Players can't be killed right now, damage has been disabled.")
11 local victimref
= minetest
.get_player_by_name(victim
)
12 if victimref
== nil then
13 return false, S("Player @1 does not exist.", victim
)
14 elseif victimref
:get_hp() <= 0 then
15 if suspect
== victim
then
16 return false, S("You are already dead")
18 return false, S("@1 is already dead", victim
)
21 -- If player holds a totem of undying, destroy it before killing,
22 -- so it doesn't rescue the player.
23 local wield
= victimref
:get_wielded_item()
24 if wield
:get_name() == "mobs_mc:totem" then
25 victimref
:set_wielded_item("")
27 if mod_death_messages
then
29 if suspect
== victim
then
30 msg
= S("@1 committed suicide.", victim
)
32 msg
= S("@1 was killed by @2.", victim
, suspect
)
34 mcl_death_messages
.player_damage(victimref
, msg
)
39 if not suspect
== victim
then
40 minetest
.log("action", string.format("%s killed %s using /kill", suspect
, victim
))
42 minetest
.log("action", string.format("%s committed suicide using /kill", victim
))
47 if minetest
.registered_chatcommands
["kill"] then
48 minetest
.unregister_chatcommand("kill")
50 minetest
.register_chatcommand("kill", {
51 params
= S("[<name>]"),
52 description
= S("Kill player or yourself"),
53 privs
= {server
=true},
54 func
= function(name
, param
)
57 return handle_kill_command(name
, name
)
59 return handle_kill_command(name
, param
)
64 minetest
.register_privilege("announce", {
65 description
= S("Can use /say"),
66 give_to_singleplayer
= false,
68 minetest
.register_chatcommand("say", {
69 params
= S("<message>"),
70 description
= S("Send a message to every player"),
71 privs
= {announce
=true},
72 func
= function(name
, param
)
74 return false, S("Invalid usage, see /help say.")
76 minetest
.chat_send_all(("["..name
.."] "..param
))
81 minetest
.register_chatcommand("setblock", {
82 params
= S("<X>,<Y>,<Z> <NodeString>"),
83 description
= S("Set node at given position"),
84 privs
= {give
=true, interact
=true},
85 func
= function(name
, param
)
87 local nodestring
= nil
88 p
.x
, p
.y
, p
.z
, nodestring
= param
:match("^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+) +(.+)$")
89 p
.x
, p
.y
, p
.z
= tonumber(p
.x
), tonumber(p
.y
), tonumber(p
.z
)
90 if p
.x
and p
.y
and p
.z
and nodestring
then
91 local itemstack
= ItemStack(nodestring
)
92 if itemstack
:is_empty() or not minetest
.registered_nodes
[itemstack
:get_name()] then
93 return false, S("Invalid node")
95 minetest
.set_node(p
, {name
=nodestring
})
96 return true, S("@1 spawned.", nodestring
)
98 return false, S("Invalid parameters (see /help setblock)")
102 minetest
.register_chatcommand("list", {
103 description
= S("Show who is logged on"),
106 func
= function(name
)
108 for _
, player
in ipairs(minetest
.get_connected_players()) do
109 players
= players
..player
:get_player_name().."\n"
111 minetest
.chat_send_player(name
, players
)
115 minetest
.register_chatcommand("seed", {
116 description
= S("Displays the world seed"),
119 func
= function(name
)
120 minetest
.chat_send_player(name
, minetest
.get_mapgen_setting("seed"))
124 local function register_chatcommand_alias(alias
, cmd
)
125 local def
= minetest
.chatcommands
[cmd
]
126 minetest
.register_chatcommand(alias
, def
)
129 if minecraftaliases
then
130 register_chatcommand_alias("?", "help")
131 register_chatcommand_alias("who", "list")
132 register_chatcommand_alias("pardon", "unban")
133 register_chatcommand_alias("stop", "shutdown")
134 register_chatcommand_alias("summon", "spawnentity")
135 register_chatcommand_alias("tell", "msg")
136 register_chatcommand_alias("w", "msg")
137 register_chatcommand_alias("tp", "teleport")
138 register_chatcommand_alias("clear", "clearinv")
140 minetest
.register_chatcommand("banlist", {
141 description
= S("List bans"),
142 privs
= minetest
.chatcommands
["ban"].privs
,
143 func
= function(name
)
144 return true, S("Ban list: @1", core
.get_ban_list())