Custom console commands

invTempestinvTempest Join Date: 2003-03-02 Member: 14223Members, Constellation, Squad Five Blue
How would one go about making custom server commands similar to how the ns2GmOvermind mod does it?

I looked in the consoleCommands_server.lua file and saw how it was done there but how would I create my own hook to listens for that command to be entered?

Comments

  • SewlekSewlek The programmer previously known as Schimmel Join Date: 2003-05-13 Member: 16247Members, NS2 Developer, NS2 Playtester, Squad Five Gold, Subnautica Developer
    edited August 2011
    Event.Hook("Console_addbot", OnConsoleAddBots)

    and this one i found in getWebApi

    .. ' <input type="submit" name="addbot" value="Add Bot" /> '

    another example: Event.Hook("Console_create", OnCommandCreate)

    so, you can simply add your own command to you NS2ConsoleCommands_Server.lua, but use the prefix "Console_", since I think it will be attached automatically somewhere.

    hope that helped a little bit
  • playerplayer Join Date: 2010-09-12 Member: 73982Members
    edited August 2011
    What Mr. Schimmel said. If you wish to have a custom console-command, say "my_console_command", to call a function called MyCustomCommand, this is needed:
    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->Event.Hook("Console_my_console_command", MyCustomCommand)<!--c2--></div><!--ec2-->
    Whenever that console-command is run, the engine calls the lua-function 'MyCustomCommand'.

    To this function a ServerClient-object is passed as the first parameter. This is the client that used the console-command. It is also possible that said console-command is run from the server-console or the web-admin, in which case there isn't a client to speak of, and the first parameter will be NIL. All parameters following the first one are arguments given to the console-command (they are seperated by spaces). So say "my_console_command" requires 2 parameters (let's run "my_console_command test1 test2"), the function will look like this:
    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function MyCustomCommand( Client, Parameter1, Parameter2 )
    -- Do something here
    end<!--c2--></div><!--ec2-->
    Parameter1 will be a string with the value "test1", and likewise Parameter2 "test2".
Sign In or Register to comment.