Command Guide
LeviLamina provides an easy-to-use command registration system, divided into compile-time and runtime registration. This guide only introduces the compile-time command registration system. If you want to implement your own scripting engine, runtime command registration might be useful for you. Before this guide includes a section on runtime command registration, you can refer to the implementation of LegacyScriptEngine or the CommandTest in LeviLamina. Additionally, LegacyScriptEngine is a scripting engine that has existed since LiteLoaderBDS v1, and many of its approaches are now outdated.
Usage
- Include the necessary header files:
C++ 1 2
#include "ll/api/command/CommandHandle.h" #include "ll/api/command/CommandRegistrar.h"
- Call the
CommandRegistrar::getInstance().getOrCreateCommand
method to obtain or create a command and assign it toauto& command
. - Call
command.overload
to overload the command. If you don't need a command that accepts parameters, you can omit the template parameters, for example:command.overload()
. - Use the
required
method to add a mandatory parameter. This method and theoptional
method require passing the variable names from the corresponding structure. Use theoptional
method to add an optional parameter, but ensure to check whether the user has provided it. Calltext
to add a subcommand. Other methods can be referenced inll/api/command/Overload.h
and through Intellisense. - Call
execute
to pass in the command's callback function. The callback function parameters can be referenced in the example below.
Example
C++ | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
In this example, we define a structure named NewCommand
, which stores the command parameters. Using the
getOrCreateCommand
method, we create a command named new. Through overload
method, we overload a subcommand
named text,
along with an enumeration, a string, and an integer parameter. The in-game usage appears as follows:
Text Only | |
---|---|
1 |
|