Adding help to a Lua command?

Status
Not open for further replies.
I'm trying to make a console command thing through Lua. It works fine, but... is there a way to make the "help" command spit out info about it? I'd rather have "help test" than "test help", for the sake of mimicking vanilla console commands.

Edit: And nope, adding a console command called "help test" through Lua doesn't do the trick, unless one was to type it with quotes in the console.
 
You need arguments in your command. This is more or less how I did it in SkyLua's help center:
Code:
-- Command: gives help.

-- Table of help stuffs to pick from
local helplist = {
test = "Press the A button to jump!",
anothertest = "Press forward to move!"
}

-- Function for the command that will read from the above table based on arguments
local function helpme(player, arg1)
    local information = "Hi there." // Default information printout.

    local typehelp = "Invalid topic."

    if helplist[arg1] // If arg1 is something from the helplist table...
        information = helplist[arg1] // the information printout becomes that helplist item.
    elseif not helplist[arg1] // Otherwise if it's not an item from the helplist table...
    and arg1!=nil // But it's not nothing...
        information = typehelp // Let's help the player out with a message, specified above.
    end

    CONS_Printf(player, information) // Print information for the player. information is modified above.
end

-- Add the above function as a command
COM_AddCommand("help", helpme)
This would do the trick. Inputting "help test" or "help anothertest" without quotation marks works with this method.
 
You need arguments in your command. This is more or less how I did it in SkyLua's help center:
-snip-
This would do the trick. Inputting "help test" or "help anothertest" without quotation marks works with this method.
Well, the reason I didn't do that sort of thing in the first place was because I didn't want it to replace the help command, making it unusable for other commands. But thanks, I'll try that, and see if it works.
Edit: Nope, both my own, simpler version of it, and your table version replace help and it's variables. *Shrug*
 
Last edited:
I don't think that's possible without replacing the help command.
You could possibly give a quick help when the first argument is nil, however.
 
I don't think that's possible without replacing the help command.
You could possibly give a quick help when the first argument is nil, however.
Nope, if the argument is nil, it executes something, and I want it to keep doing that. However, using a wrong argument (less than 0 or not a number) says "type command-name help for help".

Guess I'll just keep it as command-name help, rather than help command-name.

But thanks for the suggestion, though.
 
Status
Not open for further replies.

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top