lose item by script call? VX ACE

remainderstudios

Villager
Member
Joined
Aug 13, 2019
Messages
23
Reaction score
3
First Language
english
Primarily Uses
RMVXA
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
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,602
Reaction score
1,933
First Language
English
Primarily Uses
RMMV
Just an item or including equipment?
 

remainderstudios

Villager
Member
Joined
Aug 13, 2019
Messages
23
Reaction score
3
First Language
english
Primarily Uses
RMVXA
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
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,602
Reaction score
1,933
First Language
English
Primarily Uses
RMMV
Code:
items = $game_party.items
random_item = items[rand(items.size - 1)]
$game_party.lose_item(random_item, 1)
 

remainderstudios

Villager
Member
Joined
Aug 13, 2019
Messages
23
Reaction score
3
First Language
english
Primarily Uses
RMVXA
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.
 

A-Moonless-Night

WINTER IS COMING
Veteran
Joined
Mar 17, 2012
Messages
666
Reaction score
431
First Language
English
Primarily Uses
RMVXA
Ruby:
items = $game_party.items.select { |i| !i.key_item? }
$game_party.lose_item(items.sample, 1)
 

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
285
Reaction score
70
First Language
English
Primarily Uses
RMXP
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.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,573
Reaction score
6,496
First Language
Indonesian
Primarily Uses
RMVXA
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?" :p
 

remainderstudios

Villager
Member
Joined
Aug 13, 2019
Messages
23
Reaction score
3
First Language
english
Primarily Uses
RMVXA
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?" :p
thanks to everyone
 

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
285
Reaction score
70
First Language
English
Primarily Uses
RMXP
@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.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,573
Reaction score
6,496
First Language
Indonesian
Primarily Uses
RMVXA
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)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

I am thinking about redoing my portfolio video...
Degica has great discounts now on Steam too. MV & MV DLCs, VX Ace & VX Ace DLCs, and some DLC for MZ with a 10% discount. So if you are missing something, you can catch up now.
I'm streaming @jasonzeno 's game called Moonfall
I've been trying out Fell Seal: Arbiter's Mark, and it has an interesting approach to consumable items - you get a limited inventory that is automatically refreshed to max limits (1 or 2 each, craft to expand + improve effect) at the start of each combat. It's a mechanic that goes against the common urge to hoard consumables.

Forum statistics

Threads
103,197
Messages
997,946
Members
134,672
Latest member
MassiMatte23
Top