lose item by script call? VX ACE

Hi all.

I was looking for a script for the player to lose an item randomly when an event occurs but I can't find the script call.

Does anyone know how to do it?

Thank you
Just an item or including equipment?
Just an item or including equipment?

item, but item player has on inventory, because if it's a random item, the script might remove something the player doesn't own
Code:
items = $game_party.items
random_item = items[rand(items.size - 1)]
$game_party.lose_item(random_item, 1)
Code:
items = $game_party.items
random_item = items[rand(items.size - 1)]
$game_party.lose_item(random_item, 1)

thanks, it works great!
Code:
items = $game_party.items
random_item = items[rand(items.size - 1)]
$game_party.lose_item(random_item, 1)

excuse me,

Is there a way to make the script not remove the key items?

Thank you.
Ruby:
items = $game_party.items.select { |i| !i.key_item? }
$game_party.lose_item(items.sample, 1)
Code:
items = $game_party.items.reject {|i| i.key_item? }
$game_party.lose_item(items.sample, 1)
Just an alternative version which means it does the same job as the previously posted solution. In both cases you'd need to include the random item part of the code they've provided some days ago.
Code:
keep_item = [1,2,3,4,5,6,7,8] # Specific item ID you don't want to remove
items = $game_party.items.reject {|i| i.key_item? || keep_item.include?(i) }
$game_party.lose_item(items.sample, 1)
Just an alternative version in case you come back and asking "Okay, but what if I don't want to lose key items AND specific item that is not key item?" 😛
Code:
keep_item = [1,2,3,4,5,6,7,8] # Specific item ID you don't want to remove
items = $game_party.items.reject {|i| i.key_item? || keep_item.include?(i) }
$game_party.lose_item(items.sample, 1)
Just an alternative version in case you come back and asking "Okay, but what if I don't want to lose key items AND specific item that is not key item?" 😛

thanks to everyone
@TheoAllen Are you sure it will work? if the i variable is equal to any item or key item, it shouldn't be compared with a simple item ID for they're obviously different objects.
You're right. Here is the fixed version.
Code:
keep_item = [1,2,3,4,5,6,7,8] # Specific item ID you don't want to remove
items = $game_party.items.reject {|i| i.key_item? || keep_item.include?(i.id) }
$game_party.lose_item(items.sample, 1)

Original thread: https://forums.rpgmakerweb.com/threads/lose-item-by-script-call-vx-ace.124905/