How to clear inventory by script?

Discussion in 'RPG Maker MV' started by watermark, Jan 21, 2019.

  1. watermark

    watermark Veteran Veteran

    Messages:
    546
    Likes Received:
    481
    First Language:
    English
    Primarily Uses:
    RMMV
    How can I quickly empty the party inventory?

    I am working on a puzzle game where the player needs to reset his items (such as keys left over from a previous level) when he enters a new level, and removing them one by one using "Change Items" is terribly inefficient.

    Thanks!
     
    #1
  2. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,600
    Likes Received:
    1,005
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    This as a script call will completely delete all items the party has.

    Code:
    $gameParty._items = {};
    If you want to restore the items later, you have to save it to a variable first.

    Code:
    $gameVariables.setValue(7, $gameParty._items);
    $gameParty._items = {};
    
    // to restore the items
    $gameParty._items = $gameVariables.value(7);
     
    #2
    watermark and Eliaquim like this.
  3. watermark

    watermark Veteran Veteran

    Messages:
    546
    Likes Received:
    481
    First Language:
    English
    Primarily Uses:
    RMMV
    @Aloe Guvner Thanks so much! This is very useful.

    Is there a way to get rid of a specific block of items too? For example I want to remove just items 10-23 (the keys for example), but have the party keep some of the other stuff between levels.
     
    #3
  4. Zevia

    Zevia Veteran Veteran

    Messages:
    622
    Likes Received:
    327
    First Language:
    English
    Primarily Uses:
    RMMV
    Code:
    for (var i = 10; i <= 23; i++) {
      delete $gameParty._items[i];
    }
    
    or
    Code:
    [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23].forEach(function(itemId) {
      delete $gameParty._items[itemId];
    });
    
     
    Last edited: Jan 27, 2019
    #4
    watermark likes this.

Share This Page