Update helptext of obsidian
[MineClone/MineClone2.git] / mods / MISC / mcl_commands / init.lua
blob8b931d0b8bdeb49bc8148638ba62787f4b18e276
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.")
10 end
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")
17 else
18 return false, S("@1 is already dead", victim)
19 end
20 end
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("")
26 end
27 if mod_death_messages then
28 local msg
29 if suspect == victim then
30 msg = S("@1 committed suicide.", victim)
31 else
32 msg = S("@1 was killed by @2.", victim, suspect)
33 end
34 mcl_death_messages.player_damage(victimref, msg)
35 end
36 -- DIE!
37 victimref:set_hp(0)
38 -- Log
39 if not suspect == victim then
40 minetest.log("action", string.format("%s killed %s using /kill", suspect, victim))
41 else
42 minetest.log("action", string.format("%s committed suicide using /kill", victim))
43 end
44 return true
45 end
47 if minetest.registered_chatcommands["kill"] then
48 minetest.unregister_chatcommand("kill")
49 end
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)
55 if(param == "") then
56 -- Selfkill
57 return handle_kill_command(name, name)
58 else
59 return handle_kill_command(name, param)
60 end
61 end,
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)
73 if not param then
74 return false, S("Invalid usage, see /help say.")
75 end
76 minetest.chat_send_all(("["..name.."] "..param))
77 return true
78 end,
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)
86 local p = {}
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")
94 end
95 minetest.set_node(p, {name=nodestring})
96 return true, S("@1 spawned.", nodestring)
97 end
98 return false, S("Invalid parameters (see /help setblock)")
99 end,
102 minetest.register_chatcommand("list", {
103 description = S("Show who is logged on"),
104 params = "",
105 privs = {},
106 func = function(name)
107 local players = ""
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"),
117 params = "",
118 privs = {},
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 -- Replace spawnentity cmd to disallow spawning of hostile mobs if disabled
130 local orig_func = minetest.registered_chatcommands["spawnentity"].func
131 local cmd = table.copy(minetest.registered_chatcommands["spawnentity"])
132 cmd.func = function(name, param)
133 local ent = minetest.registered_entities[param]
134 if minetest.settings:get_bool("only_peaceful_mobs", false) and ent and ent._cmi_is_mob and ent.type == "monster" then
135 return false, S("Only peaceful mobs allowed!")
136 else
137 local bool, msg = orig_func(name, param)
138 return bool, msg
141 minetest.unregister_chatcommand("spawnentity")
142 minetest.register_chatcommand("spawnentity", cmd)
144 if minecraftaliases then
145 register_chatcommand_alias("?", "help")
146 register_chatcommand_alias("who", "list")
147 register_chatcommand_alias("pardon", "unban")
148 register_chatcommand_alias("stop", "shutdown")
149 register_chatcommand_alias("summon", "spawnentity")
150 register_chatcommand_alias("tell", "msg")
151 register_chatcommand_alias("w", "msg")
152 register_chatcommand_alias("tp", "teleport")
153 register_chatcommand_alias("clear", "clearinv")
155 minetest.register_chatcommand("banlist", {
156 description = S("List bans"),
157 privs = minetest.chatcommands["ban"].privs,
158 func = function(name)
159 return true, S("Ban list: @1", minetest.get_ban_list())
160 end,