Currently the developers are putting their own money into JC2-MP to keep the servers online.

Please take a few seconds of your time and disable your AdBlock plugin for our website.

Ad revenue is not going to developers, it is used purely for covering our hosting costs.

 

You are also free to donate, which removes all ads from our website!

RT @NOdab88: Just Cause Pro Skater 2... has it been 3 years already? #THPS #JustCause @tonyhawk @justcause @PlayStation @jc2mpdev https://t…

6 months ago

April 29, 2017, 07:33:53 pm

Author Topic: [RELEASE] Clear Inventory  (Read 454 times)

salar29

  • Newbie
  • *
  • Posts: 3
    • View Profile
[RELEASE] Clear Inventory
« 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

If you have any suggestions on how to improve it, please comment below as it is appreciated.

Urik

  • Donator
  • Full Member
  • *****
  • Posts: 119
    • View Profile
Re: [RELEASE] Clear Inventory
« Reply #1 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.
 :)

salar29

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: [RELEASE] Clear Inventory
« Reply #2 on: February 12, 2017, 03:58:19 pm »
Glad to have helped!

DaAlpha

  • Donator
  • Jr. Member
  • *****
  • Posts: 51
    • View Profile
Re: [RELEASE] Clear Inventory
« Reply #3 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 :)