Introducing the Commander command API!
Since updating my other mods is obviously overrated.
What is this mod even?
It's an API for creating chat commands.
Why do I need it?
Because you gotta have commands for everything, since fuck GUI controls, amirite?
How do I use it?
You can make commands in the following ways:
- By function:
Commands are handled as functions, to add a command by functions, just call Commander:Register(name, func), with name obviously being the name of your command, which is used to call it, and func being the actual function. The parameters after the command in the chat bar will be handed to your function as normal arguments. - By file:
This is pretty much the same as the above except instead of a function, you provide a string with the path to that file. Use Commander:LoadCommand(name,filepath).
It is recommended that you wrap the command registers in a hook function, here's an example:
Hooks:AddHook("OnCommanderInit","ChatManagerPostInit_CasualtiesCommandLoader", function(...)
Commander:LoadCommand("killcount", Casualties._path.."/command.lua")
end)
The arguments handed to the Hooks:AddHook function are as follows:
- The name of the hook (has to be OnCommanderInit)
- The ID of your hook element, which should describe from which mod it comes and for what command it is
- The actual function that is called when the API is done loading
What commands does this come with?
The API itself only has one command, do.
All it does is pack all the next arguments into one string, compile it into a function and then call the function in protected mode, displaying any error that might occur.
TL;DR: It runs the Lua code you write after it.
How do I even run a command ingame?
You have 2 options here:
- In normal chat by typing //(command name) (arguments)
- In TermChat by typing (command name) (arguments)
Changelog for V5:
- Fixed a compatibility issue with VELOSync (admittedly that mistake was really stupid)
- Added a 2 second delay for OnCommanderInit (eventually I will know of a proper way for doing this)
Also check out:
- Terminology - A small set of standard commands for the Commander API