minetest.register_chatcommand

From Minetest Developer Wiki
(Redirected from register chatcommand)
Jump to: navigation, search

Contents

Syntax

minetest.register_chatcommand("cmd", {chatcommand definition})

Description

Registers a chat command.

Parameters

1: Name of the command

2: A list containing the following:

params - string - Parameter info (used in /help)

description - string - Command description (used in /help)

privs - optional list of booleans - Require special privileges to run

func - function - Function the command should execute: should return true for success and false for error along with a string message

Note that the first param of func, name, is not necessarily the name of a player on the server, this case may happen with the irc mod.

Examples

minetest.register_chatcommand("test1", {
	params = "",
	description = "Test 1: Modify player's inventory view",
	func = function(name, param)
		local player = minetest.get_player_by_name(name)
		if not player then
			return false, "Player not found"
		end
		player:set_inventory_formspec(
				"size[13,7.5]"..
				"image[6,0.6;1,2;player.png]"..
				"list[current_player;main;5,3.5;8,4;]"..
				"list[current_player;craft;8,0;3,3;]"..
				"list[current_player;craftpreview;12,1;1,1;]"..
				"list[detached:test_inventory;main;0,0;4,6;0]"..
				"button[0.5,7;2,1;button1;Button 1]"..
				"button_exit[2.5,7;2,1;button2;Exit Button]"
		)
		return true, "Done."
	end,
})
minetest.register_chatcommand("say", {
	params = "<text>",
	description = "Send text to chat",
	privs = {talk = true},
	func = function( _ , text)
		minetest.chat_send_all(text)
		return true, "Text was sent successfully"
	end,
})
Personal tools
Namespaces

Variants
Actions
Navigation
API
Toolbox