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

● ARCHIVED · READ-ONLY
Started by BishoujoHelper 5 posts View original ↗
  1. 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.

    working Common Event - one for each item!
    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.
  2. 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.
  3. 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 :)
  4. 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.
  5. @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!