Hello, I am trying to add a few server commands for players to use. But It seems like the API has changed and all info I found on this seems to be outdated. The Lua API Docs also seem to be down and I can't seem to get any info whatsoever on this. Any help will be appreciated. What I tried was this: http://community.playstarbound.com/...-mod-with-commandprocessorscripts-conf.98265/
Since I'm too lazy busy to look up a proper post that must be around somewhere, I'm going to post this simple example that should help you set up your own command processor script. Instead of having functions that can be called as commands, there's one function "command" that is called for each custom command. The first parameter passed to this function is the command name, followed by the client id and command arguments. To keep things organized, I suggest putting all your custom commands in a table. If the called command is present in the table; call it. This can also be seen in the below example, even though it only offers one command. http://community.playstarbound.com/threads/request-rng-dice.129333/#post-3098001
Is there a way to access the global "world" table from the script? I thought "requiring" it but I can't seem to find the definition of the table anywhere within /scripts
I'm afraid that's not something the command processor is capable of. The command processor has nothing to do with worlds or what's in them.
I see. And is there a way to call one of the regular commands from within the script and get the results? Such as /list or /spawnitem or something in that nature. I would just like to add a /who command that would list the player names, since I can't seem to be able to do much else without the tables.
Pretty sure the command function is only called for non-vanilla commands. You can always try for yourself, though.
I figured it out. Wasn't able to implement exactly what I wanted but at least I got the /who command working so I am posting it here if anybody else wants to implement this. It was a lot simpler than I thought initially. Code: function commands.who(id, args) local who_result = string.format("There are currently %s people online:\n", universe.numberOfClients()) for _, client_id in pairs(universe.clientIds()) do who_result = who_result .. universe.clientNick(client_id) .. "\n" end return who_result end
When you start making more advanced commands, it is important to make sure the script will never throw errors regardless of user input. Best way to do this is to check each argument given by the user, before executing any code. Any errors cause the command processor to break until the server is reloaded using /serverreload, or restarted completely.
I am aware of lua script errors breaking commands. I broke it quite a few times Thanks for the heads up though
This method is currently pretty iffy, since every command processor script seems to share a context, meaning that only the init() and command() functions from last mod to load will actually work. It's still viable if all mods use an identical command() function, no init() function and declare commands as Code: commands = commands or {} rather than a local but it all falls over if anyone doesn't play by those rules, so it's not ideal.