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,600
Reaction score
1,931
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,600
Reaction score
1,931
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
659
Reaction score
427
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 Posts

Latest Profile Posts

Recent threads, and my very poor algorithm for my minimap plugin have made me face the fact that I need to review algorithms and such.

Going through Cracking the Coding Interview now. I am so excited.
Kes
I've seen a reference to a Community Lighting plugin for MZ, but cannot find it. Is it still in beta?

Todo:
Add fog of war
Add enemy indicators
Make window draggable
Optimise map drawing algorithm (5 seconds to load the map you see, so it's a... poo-poo algorithm)

Any suggestions? :kaoblush:
bleh studio hell job haha at least they like it didnt had time to do much laundry tho ;w;'....YES I DO AT LEAST TAKE A SHOWER everyday!
Ami
--- Food Ingredients ---

Hero: Since the Chef are in Hospital,we can't eat his Dish in 3 Days.
F.Mage: What we have to Eat?
M.Healer: Don't worry,we can Eat the Food Ingredients.
Hero & F.Mage
: Really?

(3 Days Later)

Chef: Hi,Guys. I'm Ba---
(Entire Party Collapse After Eat Raw Meat)
Chef: Wha...WHAT GOING ON HERE!!!!!!

Forum statistics

Threads
102,913
Messages
995,918
Members
134,363
Latest member
Wilsonliz
Top