Creating Console Commands

From CryWiki

Jump to: navigation, search


About
Author Not specified.
Skill Level Not specified.
Compatibility All
Requirements Not specified.
Date Added Not specified.
Last Modified Not specified.

In this tutorial, we are going to create a console command in Crysis using Lua.

Contents

Creating a Console Command with No Parameters

Creating the Lua Function

First, we will need a Lua function which is going to be called by the console command. Let's create a sample function called sayhellofunc:


Lua
function sayhellofunc()
     Log("hello")
end


Binding a Console Command to the Lua Function

System.AddCCommand binds a console command to a lua function.


Lua
System.AddCCommand("sayhello", "sayhellofunc()", "Say Hello");


The first argunemt ("sayhello") is the name of the console command. The second argument ("sayhellofunc()" is the name of the Lua function. The third argument is the description of the console command.

Creating a Console Command with Parameters

Creating the Lua Function

First, we will need a Lua function with parameters. Lets make a function that echos the parameters.


Lua
function echofunc(textToEcho)
     Log(textToEcho)
end


Binding a Console Command to the Lua Function

Now lets bind it.


Lua
System.AddCCommand("echo", "echofunc(%line)", "Echo the parameters");


In this code, %line is the parameter to the console command. Thus whatever was passed in as a argument is also passed into the Lua function.

Test it out

Typing echo hello world into the console and it should print "<Lua>hello world".

See also

Personal tools