Compare commits

...

5 Commits

Author SHA1 Message Date
Wuzzy 696dacf435 Remove description.txt 2020-11-24 02:00:29 +01:00
Wuzzy c78f609e10 Fix always executing 1st command in list only 2020-11-23 19:43:49 +01:00
Wuzzy ca62e50f38 Can disable command result printing 2020-11-18 15:53:55 +01:00
Wuzzy 9152e07b60 Enlarge formspec 2020-11-18 15:39:09 +01:00
Wuzzy 4c79740827 Disable repair recipe 2020-11-18 15:34:06 +01:00
4 changed files with 25 additions and 11 deletions

View File

@ -1 +0,0 @@
A programmable tool which, wheen used, executes a server command.

View File

@ -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 retval == true then
minetest.chat_send_player(player_name, minetest.colorize("#00FF00", "["..S("OK").."] ".. cmd))
elseif retval == false then
minetest.chat_send_player(player_name, minetest.colorize("#FF0000", "["..S("FAIL").."] ".. cmd))
elseif retval == nil then
minetest.chat_send_player(player_name, minetest.colorize("#FF8800", "["..S("UNKN").."] ".. cmd))
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,

View File

@ -1 +1,2 @@
name = cmdtool
description = A programmable tool which, wheen used, executes a server command.

2
settingtypes.txt Normal file
View File

@ -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