lose item by script call? VX ACE

remainderstudios

Villager
Member
Joined
Aug 13, 2019
Messages
24
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,604
Reaction score
1,948
First Language
English
Primarily Uses
RMMV
Just an item or including equipment?
 

remainderstudios

Villager
Member
Joined
Aug 13, 2019
Messages
24
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,604
Reaction score
1,948
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
24
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
675
Reaction score
437
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
287
Reaction score
71
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,499
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
24
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
287
Reaction score
71
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,499
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

Dev stream today, come on by and ask questions about rpg maker!
Fun fact: If your story introduces a variety of different races, the "human race" will automatically become the most corrupt race in general.
Finally finished my late start entry for the jam. Now. I. Sleep.
Just made 3 easy, simple and small MZ plugins today(12 hours straight), and I never thought I could ever do this.
Now I feel myself being very productive, even though I know I'm just utterly flattering myself lol
Mind: "I have cool ideas! Let's make it real!

Body: "You wanna make sumthin? I'm in."

Eyes: "Go to sleep, go to sleep."

*Sleep*

Forum statistics

Threads
104,644
Messages
1,007,807
Members
136,132
Latest member
A87
Top