[RPGMV] Item detection

spineraker

Warper
Member
Joined
Jan 19, 2013
Messages
1
Reaction score
0
First Language
English
Primarily Uses
I would really appreciate any help on this, as I've spent all day trying to figure it out with no success. Basically, I need to have a way of coding detection of the inventory the party currently has, then detect each of the items in that inventory and post the item's icon to a window.


The difficulty I am having here is I don't know how to properly load the items.JSON file from Database and parse the lines so I can just tell it "If party has item X, then load iconIndex Y as sprite to window".


If there is another way to do this that I am just not seeing (as in, the JSON involvement isn't necessary or something), I'm all ears.
 

Kino

EIS Game Dev
Veteran
Joined
Nov 27, 2015
Messages
556
Reaction score
795
First Language
English
Primarily Uses
RMMV
@spineraker


The JSON data isn't necessary. There is a function that returns all items the party currently has. Create an observer to monitor changes.


This is an example of an observer that will tell you if there are any changes to the items in the player inventory vs the list in the observer. Here's a link to the raw file : ObserverPattern.js ; Add code as necessary in the monitor changes method to do things like draw icons to a window.

Code:
//=============================================================================
// Observer Pattern                                                             
//=============================================================================


//This creates an observer in RPGMaker MV
//This is an example of checking whether an item exists on an observer


(function() {

  var parameters = PluginManager.parameters("ObserverPattern");
  
  function Setup() {
    'use strict';
    //Static class for monitoring items
    class ItemObserver {

      static startObserver() {
        this._itemList = [];
        this.update();
      }

      static update() {
        this.monitorUpdates();
        this.requestUpdate();
      }

      static requestUpdate() {
        requestAnimationFrame(this.update.bind(this));
      }

      static monitorUpdates() {
        if(!this.listMatch()) {
          console.log("Item List Updated");
          this.itemList = $gameParty.allItems();
        }
      }

      static listMatch() {
        if($gameParty !== null) {
          let items = $gameParty.allItems();
          for(let i = 0; i < items.length; i++) {
            if(this.itemList[i] === undefined  || this.itemList[i] !== items[i])
              return false;
          }
          return true;
        }
        return true;
      }

      static set itemList(itemList) {
        this._itemList = itemList;
      }

      static get itemList() {
        return this._itemList;
      }
    }

    //Start Observer Update Method
    ItemObserver.startObserver();
  }
  Setup(); 
})();
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,038
Messages
1,018,466
Members
137,821
Latest member
Capterson
Top