Modding Help Custom Commands in 1.0

Discussion in 'Starbound Modding' started by Kappalones, Nov 24, 2016.

  1. Kappalones

    Kappalones Void-Bound Voyager

    Alright, I hope this is the right forum for this. For some time I have tried to wrap my head around the custom commands, looked everywhere for a hint on how they could work but only found pre-1.0 stuff like this thread. But none of that works for 1.0 or later, so what exactly changed?

    I'm sorry if this is a duplicate thread or if this has already been asked/answered before, but right now I'm very confident (because I have swept over every inch of the forum and reddit about this topic) that there is no explanation to this on the forums yet
  2. Kappalones

    Kappalones Void-Bound Voyager

    I got help from @Apple Juice and didn't want to leave this thread unsolved in case someone else needs help with this.

    The new format for making commands is
    function command(commandName, clientId, args)
      # Do things here
      return "This is what is returned privately to the player"
    commandName is the command executed by the client. For example, when typing /test, the commandName would be the string test.
    clientId is the.. clientId, duh.
    args is a table of arguments that are supplied by the client. For example, /test "123" 1 2 3 "5" would output the table {"123,"1","2","3","5"}

    Getting the scripts into the game is the same as it was before with using the patch method to apply it to the universe_server.config
      "op": "add",
      "path": "/commandProcessorScripts/-",
      "value": "/serverCommands.lua"
    This gives some interesting new flexibility in my opinion
    Last edited: Nov 29, 2016
    bk3k, magewish4 and Errors4l like this.
  3. TheElderScroller

    TheElderScroller Pangalactic Porcupine

    This doesn't work for me. I also don't really understand this format...
    A function name AND a command name, separated...

    Anyways, it only says that the command doesn't exist. Tried on a local server and singleplayer,
    and a few commands
  4. Kappalones

    Kappalones Void-Bound Voyager

    I'm pretty sure you misunderstood the format.
    The function must be command(...) and not test(...) or customCommand(...).

    For example, what I use looks like this:
    function command(commandName, clientId, args)
        if commands[commandName] ~= nil then
            user = universe.clientNick(clientId)
            return commands[commandName](clientId, user, args)
            return "The command ^blue;"..commandName.."^reset; does not exist"
    This allows me easily to introduce additional commands like this:
    commands = {}
    function commands.d20(clientId, user, args)
        local result = math.random(20)
        universe.adminBroadcast("^red;"..user.."^reset; rolled a ^red;1d20^reset; and got ^red;"..result.."^reset;")
        return "You rolled a ^red;"..result.."^reset;"
    TheElderScroller and Errors4l like this.
  5. TheElderScroller

    TheElderScroller Pangalactic Porcupine

    Now I got it, seems like I forgot to make the functions return a value... hehe

Share This Page