Compare commits
5 Commits
1ffcc83b41
...
696dacf435
Author | SHA1 | Date |
---|---|---|
|
696dacf435 | |
|
c78f609e10 | |
|
ca62e50f38 | |
|
9152e07b60 | |
|
4c79740827 |
|
@ -1 +0,0 @@
|
|||
A programmable tool which, wheen used, executes a server command.
|
20
init.lua
20
init.lua
|
@ -5,6 +5,8 @@ local NEWLINE = "\n"
|
|||
local DESCRIPTION = S("Command Tool")
|
||||
local MAX_CMD_TOOLTIP_LEN = 48
|
||||
|
||||
local print_result = minetest.settings:get_bool("cmdtool_print_result", true)
|
||||
|
||||
local split_commands = function(commands_string)
|
||||
return string.split(commands_string, NEWLINE)
|
||||
end
|
||||
|
@ -88,7 +90,7 @@ local execute_command = function(itemstack, player, pointed_thing)
|
|||
end
|
||||
local player_privs = minetest.get_player_privs(player_name)
|
||||
for c=1, #cmds do
|
||||
local cmd = cmds[1]
|
||||
local cmd = cmds[c]
|
||||
-- Substitution successful?
|
||||
-- Split command string into command name and parameters
|
||||
local cmd_split = string.split(cmd, " ", false, 1)
|
||||
|
@ -120,15 +122,24 @@ local execute_command = function(itemstack, player, pointed_thing)
|
|||
local retval, msg = def.func(player_name, cmd_params)
|
||||
|
||||
-- Print return value and message
|
||||
if print_result then
|
||||
if retval == true then
|
||||
-- Command successfull
|
||||
minetest.chat_send_player(player_name, minetest.colorize("#00FF00", "["..S("OK").."] ".. cmd))
|
||||
elseif retval == false then
|
||||
-- Command failed
|
||||
minetest.chat_send_player(player_name, minetest.colorize("#FF0000", "["..S("FAIL").."] ".. cmd))
|
||||
elseif retval == nil then
|
||||
-- Command result unknown
|
||||
minetest.chat_send_player(player_name, minetest.colorize("#FF8800", "["..S("UNKN").."] ".. cmd))
|
||||
end
|
||||
end
|
||||
if msg ~= nil and msg ~= "" then
|
||||
minetest.chat_send_player(player_name, "> " .. msg)
|
||||
local out = msg
|
||||
if print_result then
|
||||
local out = "> " .. msg
|
||||
end
|
||||
minetest.chat_send_player(player_name, out)
|
||||
end
|
||||
else
|
||||
minetest.chat_send_player(player_name, minetest.colorize("#FF0000", S("Nothing pointed!")))
|
||||
|
@ -158,8 +169,8 @@ local open_command_configuration = function(itemstack, player, pointed_thing)
|
|||
end
|
||||
end
|
||||
local formspec =
|
||||
"size[6,6]"..
|
||||
"textarea[0.25,0;6,5;commands;"..F(S("Commands:"))..";"..F(commands_str).."]"..
|
||||
"size[12,6]"..
|
||||
"textarea[0.25,0.25;12,5;commands;"..F(S("Commands:"))..";"..F(commands_str).."]"..
|
||||
"button_exit[0.5,5;2,1;ok;"..F(S("OK")).."]"..
|
||||
"button_exit[3.5,5;2,1;cancel;"..F(S("Cancel")).."]"
|
||||
minetest.show_formspec(player_name, "cmdtool", formspec)
|
||||
|
@ -195,6 +206,7 @@ S([[Example 2:
|
|||
→ Teleports you to Y=9 without changing the X and Z coordinates, then gives you an apple.]]),
|
||||
inventory_image = "cmdtool_cmdtool.png",
|
||||
wield_imagee = "cmdtool_cmdtool.png",
|
||||
groups = { disable_repair = 1 },
|
||||
on_use = execute_command,
|
||||
on_place = open_command_configuration,
|
||||
on_secondary_use = open_command_configuration,
|
||||
|
|
1
mod.conf
1
mod.conf
|
@ -1 +1,2 @@
|
|||
name = cmdtool
|
||||
description = A programmable tool which, wheen used, executes a server command.
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
# If enabled, the command and the result of the command will be shown in chat whenever a command tool is used.
|
||||
cmdtool_print_result (Show command result) bool true
|
Loading…
Reference in New Issue