Scripting => Releases => Topic started by: salar29 on February 05, 2017, 03:41:52 pm
Very simple script that clears your inventory whenever you type /clear. Also checks to see if you have already cleared your inventory, in which case it prints a message that, quite simply, there is nothing to clear. Might come in handy for some servers that don't have it. Feel free to download, I made this for the ATC server but I decided to put it up for anyone that wants it.
GitHub Download (https://github.com/salar29/clearinv)
If you have any suggestions on how to improve it, please comment below as it is appreciated.
Nice one, I always appreciate when people share stuff, it makes sense to have this on more servers. I needed this myself, was thinking of making it myself eventually and you saved me like 10 mins.
Glad to have helped!
Nice clean code actually, good job!
One mistake in it: the command gets printed to the chat. You need to do a "return false" between lines 9 and 10 to tell the chat not to send the actual command as a message.
If you want to satisfy the perfectionist in me: the first if clause from line 3 to 10 is indented one too far. The if and end should be on the same level as the local variable declaration in line 2.
Also, it s a best practice not to declare and assign variables before you need them in the code. In the code right now, you assign the inventory variable every time the player writes ANY chat message. You would want to put it behind the args.text == "/clear" check so it only assigns it when it is actually needed.
Alternatively, you can even remove the declaration in line 2 entirely and call the clear inventory function inside the table.count on line 4 like this: table.count(args.player:GetInventory())
Just some basic suggestions :)