Initial release

This commit is contained in:
Mahmut Elmas 2016-01-20 12:30:19 +02:00
parent adf69fdc29
commit 8501e2ae5c
2 changed files with 154 additions and 0 deletions

69
commands.lua Normal file
View File

@ -0,0 +1,69 @@
-- Kill Function
local function handle_kill_command(suspect, victim)
local victimref = minetest.get_player_by_name(victim)
if victimref == nil then
return false, ("Player "..victim.." does not exist.")
elseif victimref:get_hp() <= 0 then
if suspect == victim then
return false, "You are already dead"
else
return false, (victim.." is already dead")
end
end
if not suspect == victim then
minetest.log("action", suspect.." killed "..victim)
end
victimref:set_hp(0)
end
-- Kill a player
minetest.register_chatcommand("kill", {
params = "<name>",
description = "Kill player",
privs = {kill=true},
func = function(name, param)
return handle_kill_command(name, param)
end,
})
-- Kill yourself
minetest.register_chatcommand("killme", {
description = "Kill yourself",
func = function(name)
return handle_kill_command(name, name)
end,
})
-- List banned players
minetest.register_chatcommand("banlist", {
description = "List bans",
privs = minetest.chatcommands["ban"].privs,
func = function(name)
return true, "Ban list: " .. core.get_ban_list()
end,
})
-- Aliases function
local function register_chatcommand_alias(alias, cmd)
local def = minetest.chatcommands[cmd]
minetest.register_chatcommand(alias, def)
end
-- Minecraft commands for minetest
register_chatcommand_alias("?", "help")
register_chatcommand_alias("list", "status")
register_chatcommand_alias("pardon", "unban")
register_chatcommand_alias("stop", "shutdown")
register_chatcommand_alias("tell", "msg")
register_chatcommand_alias("w", "msg")
register_chatcommand_alias("tp", "teleport")

85
init.lua Normal file
View File

@ -0,0 +1,85 @@
local commander = ""
minetest.after(0, function()
for cmd in pairs(minetest.chatcommands) do
if cmd ~= "command_gui" then
commander = commander..cmd..","
end
end
commander = commander:sub(1, -2)
end)
local function formspec(cmd_name)
local number = 1
if cmd_name then
for i, cmd in ipairs(commander:split(",")) do
if cmd == cmd_name then
number = i
break
end
end
else
cmd_name = commander:split(",")[1]
end
local def = minetest.chatcommands[cmd_name]
local privileges = ""
for priv, bool in pairs(def.privs or {}) do
if bool then
privileges = privileges..priv..","
end
end
privileges = minetest.formspec_escape(#privileges ~= 0 and privileges:sub(1, -2) or "")
local description = minetest.formspec_escape(def.description or "")
local parameters = minetest.formspec_escape(def.params or "")
return "size[9,4;]"..
"dropdown[,;9.5,1;command;"..commander..";"..number.."]"..
"label[,1;Description: "..description.."]"..
"label[,1.5;Privileges: "..privileges.."]"..
"field[.3,2.7;9,1;param;Parameter:;"..parameters.."]"..
"button[,3.3;9,1;run;Run]"
end
-- Open command gui by chat
minetest.register_chatcommand("command_gui", {
func = function(name)
minetest.after(0.5, minetest.show_formspec, name, "command_gui:menu", formspec())
end
})
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "command_gui:menu" then
return
end
local name = player:get_player_name()
if fields.run then
local def = minetest.chatcommands[fields.command]
if not def then
return
end
local has_privs, missing_privs = minetest.check_player_privs(name, def.privs)
if has_privs then
minetest.set_last_run_mod(def.mod_origin)
local success, message = def.func(name, fields.param)
if message then
minetest.chat_send_player(name, message)
end
else
minetest.chat_send_player(name, "You don't have permission"..
" to run this command (missing privileges: "..
table.concat(missing_privs, ", ") .. ")")
end
elseif fields.command and not fields.quit then
minetest.show_formspec(name, "command_gui:menu", formspec(fields.command))
end
end)
dofile(minetest.get_modpath("commander").."/commands.lua")