Random Item Selection

I need a plugin that can pick an item from the player's inventory at random, and store it's ID in a variable.
You can do it with a script call


var variableId = 5; // change 5 to whatever you want
var items = $gameParty.items();
var diceRoll = Math.floor(Math.random() * items.length);
$gameVariables.setValue(variableId, items[diceRoll].id);


Note this only works with regular items. If you want to include equipment it'll get a little more complicated. Just say if you need to thogh
 I do believe this is exactly what I needed.


Thank you very much.


Edit:  Upon further testing, this script call works on the map, but only ever returns item #1 when used in battle.


I cannot figure out why.

Original thread: https://forums.rpgmakerweb.com/threads/random-item-selection.65572/