Use minetest.raillike_group for rails
[MineClone/MineClone2/MineClone2.git] / mods / MISC / mcl_commands / init.lua
blobc77b30816aab27637b7d2232faa8c2caca101ee8
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 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())
145 end,