SOLVED: get ID of selected/used item in Common Event?

BishoujoHelper

Veteran
Veteran
Joined
May 6, 2017
Messages
54
Reaction score
46
First Language
English
Primarily Uses
RMMV
So, there's some deliberately useless items that the party can accumulate. In the original game that I'm creating a conversion of, there was a menu command to (D)rop an item, then select the # of the item in the inventory list. In RMMV, it's going the other way, and in the Items screen you select the item, then for the useless ones it calls a Common Event in the Item's "Effects" section that lets you choose to drop some amount of that type. The problem is that so far, I can't see how to avoid having a separate Common Event for each kind of item you'd want to drop, because I've yet to find how to access the selected/used item's ID through scripting. Each CE looks very much like the code below, and works. Just trying to find a more elegant way to do this for multiple types of items in only one CE.

Code:
◆Comment:Lets you choose to throw away a useless item upon Use
:       :(clicked in Items screen) or keep it.
:       :Until I learn how to get the itemID that sent us here,
:       :need a CE for each item to throw away!
:       :(using two temporary variables)
◆Control Variables:#0002 temp = The number of Bottle
◆Text:None, Window, Middle
:    :You have \V[2] \I[176]\C[4]Bottle\C[0],
:    :how many do you want to throw away permanently?
◆Input Number:RandomPercent, 1 digit
◆If:RandomPercent > temp
  ◆Control Variables:#0001 RandomPercent = temp
  ◆
:End
◆Change Items:Bottle - {RandomPercent}

I don't want to do this with "Select Item" because then I'd either need a plugin to filter for only the kinds of items that can be dropped, or I'd have a much larger list of items that the CE has to check for and say "you can't drop that." There's also no stores or NPCs that buy/take items from you besides quest key items, so I can't get rid of them that way, plus the original functionality is to be able to look at the inventory anytime outside combat and clean house. And these aren't Consumable=Yes items, really; the Bottle is empty and created after consuming a Wine Bottle, and another is literally a "useless pile of rodent feces", so the Consumable route doesn't feel right.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
32,352
Reaction score
8,080
First Language
German
Primarily Uses
RMMV
1) One way to try this is to use the damage formula on the item to store its ID into a variable, and then check that variable on the common event
it looks as if you hadn't realised yet, but the damage formula used by skills and items is evaluated as full javascript code, which means you can put multiple commands and do other things in there with javascript code.

2) alternatively, if those items are really useless and only need to be dropped, then you simply can set them as consumable and give them no effect (for example applying an invisible state that does nothing) and they vanish "on use"

3) third way to get rid of them would be to create events like garbage cans on the maps, and those ask by select item which things to drop.
This can be done without plugins, because the select item command stores the ID into a variable as well and you can then check that with conditional branches.
And no, that does not increase the list as you can use labels to skip to the end after the branches, and if no branch is selected (not a valid ID) the last command before the label will read "you can't drop that" as a single line for all other items.
 

BlueMoon

Nebula Games Leader
Veteran
Joined
Jan 10, 2017
Messages
349
Reaction score
475
First Language
Italian
Primarily Uses
RMMZ
Mmm... If I understood correctly what are you trying to do, you can reach your result using the last selected item in the Game Party class.
Do you want that the last item used/selected should be recognized in the event right?

Well, try to do set the event this way, you have to use a little scripting, but It's very simple and this way you will need only one event for all!
Code:
◆Comment:Lets you choose to throw away a useless item upon Use
:       :(clicked in Items screen) or keep it.
:       :Until I learn how to get the itemID that sent us here,
:       :need a CE for each item to throw away!
:       :(using two temporary variables)
◆Control Variables:#0002 temp = (Script)  $gameParty.numItems($gameParty.lastItem())
◆Control Variables:#0003 ICON = (Script)  $gameParty.lastItem().iconIndex
◆Control Variables:#0004 NAME = (Script)  $gameParty.lastItem().name
◆Text:None, Window, Middle
:    :You have \V[2] \I[\V[3]]\C[4]\V[4]\C[0],
:    :how many do you want to throw away permanently?
◆Input Number:RandomPercent, 1 digit
◆If:RandomPercent > temp
  ◆Control Variables:#0001 RandomPercent = temp
  ◆
:End
◆ SCRIPT:
var item = $gameParty.lastItem();
var amount = $gameVariables._data[1];
$gameParty.loseItem(item, amount);

This way you'll reach the effect you want :)
 

JGreene

Veteran
Veteran
Joined
Oct 24, 2015
Messages
437
Reaction score
336
First Language
English
Primarily Uses
RMMV
One way to accomplish the "garbage can" method that @Andar described, is to use the PH Warehouse plugin and create a warehouse that deletes itself after you exit the menu.
 

BishoujoHelper

Veteran
Veteran
Joined
May 6, 2017
Messages
54
Reaction score
46
First Language
English
Primarily Uses
RMMV
@Gamefall Team That's exactly what I needed! The .lastItem() is the part that I couldn't seem to find. I'm also more familiar with using $gameVariables.value(1) in the next-to-last line instead of the ._data[1] way, but it seems to work either way. You're going in my credits list!
 

Latest Threads

Latest Posts

Latest Profile Posts

Definitely glad I haven't released a few of my plugins that are technically done. As I learn more, I find ways to make my code more efficient, and in one case so far, discovered an existing function that did EXACTLY what I created my own function to do.
So I was kinda recommended a manga to learn a few drawing tips, I dunno if it will actually work, but I'm liking the story lol
M745veO.jpg
RPG Maker News #12 | Control Zooming, Customize Bush Effect, Causality & Happy Bones on Steam
Episode 16 let's go! We're making an RPG in RPG Maker MZ! This week... even more mapping, we're almost done with all the mapping for our first dungeon!

I have big news. I just got hired at a Mexican restaurant! They're like Chipotle but a bit different... and my job will be taking orders some days, delivering food other days, and of course, making customers happy. My orientation is on Tuesday. Once I start, I might disappear from here sometimes, but I'll always try to come back!

Forum statistics

Threads
110,448
Messages
1,053,387
Members
143,526
Latest member
ZakkWylde86
Top