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

I started really going in on my project April of last year... I'm just now making starting the actual game... making assets (and not even all of them), whoooo... TIME SINK.


Imagine being a pleb and using --------------------.js :LZSwink:
Ami
--- Survival For RPGist Part 2 ---

Survivalist: Now,I going to Test you: Fishing with Spear
M.Spear Knight: Leave it to me.
(M.Spear Knight Spearing the Fish with His Battle Spear)
M.Spear Knight: How it is?
Survivalist: I know you did it,but...Is that the Spear for Battle,not for Fishing?
M.Spear Knight: But,is that same?
Survivalist: (Sigh)...Whatever

Forum statistics

Threads
102,943
Messages
996,171
Members
134,407
Latest member
ImaClownnn
Top