Skip to content

How to create user command

vasyahuyasa edited this page Jan 21, 2015 · 3 revisions

Introduction

At start, if you want to create scripts for remod you should know cubescript, you can find good manual here http://www.sandboxgamemaker.com/wiki/index.php?title=Cubescript.

Listing of our example command

// our callback function command
cmd_example = [
	// $arg1 - caller cn
	// $arg2 - 1st parameter 

	// get player name
	pname = (getname $arg1)

	// make formated and colored string
	fstring = (format "Player ^f0%1 ^f7type ^f0%2" $pname $arg2)

	// show string
	say $fstring
]
// register our command
registercommand "example" cmd_example 1 "s" "example [msg] ^f1Command example"

Details

At start we defined cube script function which will be executed when player type #example test. This function can have any name but for not confuse us in future we name it cmd_example. When player type comand some parameters passed to our function. For us $arg1 is player cn and $arg2 is parameter which player typed after command.

After we wrote function we should register it as player command:

registercommand "example" cmd_example 1 "s" "example [msg] ^f1Command example"

Explanation of each parameter:

registercommand – function which register our command

"example" – command name which user should type

cmd_example – function which executes when user call command

2 – who can use that function (1 - any player, 2 -- masters, 3 - admins only)

s – parameters what user should pass (s - string, for full list of parameters mnemonics see /docs/guide.html)

"example [msg] ^f1Command example" – help string which user see whn type #help example.

If you want unregister that player command you can use unregistercommand "example" in other script.