Replace clear command with alias to clearinv
[MineClone/MineClone2.git] / mods / MISC / mcl_commands / init.lua
blobb76aaff1496479afe4071b187fd8a844eadbf2cd
1 local minecraftaliases = true
3 local S
4 if minetest.get_modpath("intllib") then
5 S = intllib.Getter()
6 else
7 S = function(s,a,...)a={a,...}return s:gsub("@(%d+)",function(n)return a[tonumber(n)]end)end
8 end
10 local function handle_kill_command(suspect, victim)
11 if minetest.settings:get_bool("damage_enabled") == false then
12 return false, S("Players can't be killed right now, damage has been disabled.")
13 end
14 local victimref = minetest.get_player_by_name(victim)
15 if victimref == nil then
16 return false, S("Player @1 does not exist.", victim)
17 elseif victimref:get_hp() <= 0 then
18 if suspect == victim then
19 return false, S("You are already dead")
20 else
21 return false, S("@1 is already dead", victim)
22 end
23 end
24 if not suspect == victim then
25 minetest.log("action", S("@1 killed @2", suspect, victim))
26 end
27 -- If player holds a totem of undying, destroy it before killing,
28 -- so it doesn't rescue the player.
29 local wield = victimref:get_wielded_item()
30 if wield:get_name() == "mobs_mc:totem" then
31 victimref:set_wielded_item("")
32 end
33 -- DIE!
34 victimref:set_hp(0)
35 return true
36 end
38 minetest.register_privilege("kill", {
39 description = S("Can use /kill"),
40 give_to_singleplayer = false,
42 minetest.register_privilege("announce", {
43 description = S("Can use /say"),
44 give_to_singleplayer = false,
47 minetest.register_chatcommand("kill", {
48 params = S("[<name>]"),
49 description = S("Kill player"),
50 privs = {kill=true},
51 func = function(name, param)
52 if(param == "") then
53 -- Selfkill
54 return handle_kill_command(name, name)
55 else
56 return handle_kill_command(name, param)
57 end
58 end,
61 minetest.register_chatcommand("say", {
62 params = S("<message>"),
63 description = S("Send a message to every player"),
64 privs = {announce=true},
65 func = function(name, param)
66 if not param then
67 return false, S("Invalid usage, see /help say.")
68 end
69 minetest.chat_send_all(("["..name.."] "..param))
70 return true
71 end,
74 minetest.register_chatcommand("setblock", {
75 params = S("<X>,<Y>,<Z> <NodeString>"),
76 description = S("Set node at given position"),
77 privs = {give=true, interact=true},
78 func = function(name, param)
79 local p = {}
80 local nodestring = nil
81 p.x, p.y, p.z, nodestring = param:match("^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+) +(.+)$")
82 p.x, p.y, p.z = tonumber(p.x), tonumber(p.y), tonumber(p.z)
83 if p.x and p.y and p.z and nodestring then
84 local itemstack = ItemStack(nodestring)
85 if itemstack:is_empty() or not minetest.registered_nodes[itemstack:get_name()] then
86 return false, S("Invalid node")
87 end
88 minetest.set_node(p, {name=nodestring})
89 return true, S("@1 spawned.", nodestring)
90 end
91 return false, S("Invalid parameters (see /help setblock)")
92 end,
95 minetest.register_chatcommand("list", {
96 description = "Show who is logged on",
97 params = "",
98 privs = {},
99 func = function(name)
100 local players = ""
101 for _, player in ipairs(minetest.get_connected_players()) do
102 players = players..player:get_player_name().."\n"
104 minetest.chat_send_player(name, players)
108 minetest.register_chatcommand("seed", {
109 description = "Displays the world seed",
110 params = "",
111 privs = {},
112 func = function(name)
113 minetest.chat_send_player(name, minetest.get_mapgen_setting("seed"))
117 local function register_chatcommand_alias(alias, cmd)
118 local def = minetest.chatcommands[cmd]
119 minetest.register_chatcommand(alias, def)
122 if minecraftaliases then
123 register_chatcommand_alias("?", "help")
124 register_chatcommand_alias("who", "list")
125 register_chatcommand_alias("pardon", "unban")
126 register_chatcommand_alias("stop", "shutdown")
127 register_chatcommand_alias("summon", "spawnentity")
128 register_chatcommand_alias("tell", "msg")
129 register_chatcommand_alias("w", "msg")
130 register_chatcommand_alias("tp", "teleport")
131 register_chatcommand_alias("clear", "clearinv")
133 minetest.register_chatcommand("banlist", {
134 description = S("List bans"),
135 privs = minetest.chatcommands["ban"].privs,
136 func = function(name)
137 return true, S("Ban list: @1", core.get_ban_list())
138 end,