Scripting => Releases => Topic started by: salar29 on February 05, 2017, 03:41:52 pm

Title: [RELEASE] Clear Inventory
Post 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.

EDIT 07/07/17: New version, shortened it a bit, took advice, updated some stuff, no big deal. Just a bit cleaner ;)
Title: Re: [RELEASE] Clear Inventory
Post by: Urik on February 06, 2017, 02:39:08 pm
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.
Title: Re: [RELEASE] Clear Inventory
Post by: salar29 on February 12, 2017, 03:58:19 pm
Glad to have helped!
Title: Re: [RELEASE] Clear Inventory
Post by: DaAlpha on April 07, 2017, 08:00:13 pm
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 :)
Title: Re: [RELEASE] Clear Inventory
Post by: salar29 on July 07, 2017, 10:38:03 pm
Thanks for the feedback, Alpha!
I'll take it into consideration and try to improve it :)