How to randomly remove an item from a player's inventory in a common event?!

Okay so I'm trying to make a skill that ejects a random item from the player's inventory.
I'm relatively new to this and I have no idea on how scripting even works so if someone could explain to me a way on doing it that would be great!
use this in script call event:
$gameParty.loseItem($dataItems[Math.randomInt($dataItems.length)], 1)
Event command > Party (upper right corner) > change items. You might need to look up tutorials before you tackle making a game though.
use this in script call event:
$gameParty.loseItem($dataItems[Math.randomInt($dataItems.length)], 1)
where do i type it though
sorry for asking basic questions btw
like he said in script call event command
I'd suggest this instead (e.g. in a Script command):
JavaScript:
var items = $gameParty.allItems();
var count = items.length;
if (count) $gameParty.loseItem(items[Math.randomInt(count)], 1);
I.e. "if the party has any Items, Weapons, and/or Armors in their inventory, pick one randomly and remove it".
where do i type it though
sorry for asking basic questions btw
The script call event command is on page 3 of the Event Commands, under "Advanced"!
1632070590808.png
Thank you so much for everyone's help, it works!!!
$gameParty.loseItem($dataItems[Math.randomInt($dataItems.length)], 1)
Could that end up trying to lose $dataItems[0]? Does it need to be +1?
@Shaz In this form, it might, but Math.randomInt() has a nice trick to avoid it:

Math.randomInt(size, min, max)
Math.randomInt(size, min, max)
This is not something that is defined in the core scripts. Instead you can use:
  • min + Math.randomInt(1 + max - min)
This should return a random integer in the range [min, max].
@caethyril - but it works in MV quite well


use this in script call event:
$gameParty.loseItem($dataItems[Math.randomInt($dataItems.length)], 1)
The other problem with this method is that you're selecting a random item from the database without any reason to believe the party has one to lose. Unless you're late in the game and a hoarder, there's every chance that this will get called and simply do nothing. Caethyril's method of using the $gameParty containers assures that something will be lost when the function is called.

Math.randomInt(size, min, max)
What is "size" supposed to represent in that? In your own example, you call it with the supposed min and max being 2-20, and you get a result of 157. So...how is it "working quite well"? 😛

You can see the code in rpg_core.js, and it only takes one argument. In JavaScript you can overload a function call with additional arguments and not get an error, but neither does it do anything with them.
@ATT_Turan - I found it here - https://mathjs.org/docs/reference/functions/randomInt.html
RPG Maker MV doesn't use that library. Notice how all of its references and examples are written with "math," lower case? If you type anything from that page into your MV console, you'll get an error.

Heck, if it did work according to that page, the examples you typed into your console would not have shown those results, because you were asking for a 255-element-long array every time!

In MV, you have access to the Math object that's built into JavaScript, which provides some functions like random and floor; but the randomInt function was written by the MV programmers, it takes one argument, and you can see the code exactly where I told you it was.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-randomly-remove-an-item-from-a-players-inventory-in-a-common-event.140590/