Return # of equips of certain type?

Status
Not open for further replies.

ZServ

Veteran
Veteran
Joined
Jun 16, 2014
Messages
259
Reaction score
71
Primarily Uses
I.E., you have 5 helmets in your inventory. Is there a quick way to count how many there are, including duplicates? I'm pretty sure you can, but I'm not sure where to find the details on the various equip types in order to do such a thing.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,510
Reaction score
992
First Language
EN
Primarily Uses
RMMV
To count the number of one particular item in the database, you can use Control Variables > Game Data > Item|Weapon|Armor. Nice and easy~ ^_^

If not, then it's scriptin' time! First, note that there are three equippable item types on the Types tab in the database: Weapon Type, Armor Type, and Equipment Type. (The corresponding properties in the game code are wtypeId, atypeId, and etypeId.) If you don't mind ignoring equipped items, I think the following snippets should work in the Control Variables > Script box; just pick the one corresponding to the appropriate type and change the number at the start as needed:
  • Count possessed Weapons of Weapon Type #1:
    Code:
    var wtypeId = 1; $gameParty.weapons().reduce(function(t, w) { return t + (w.wtypeId === wtypeId ? $gameParty.numItems(w) : 0); }, 0)
  • Count possessed Armors of Armor Type #2:
    Code:
    var atypeId = 2; $gameParty.armors().reduce(function(t, a) { return t + (a.atypeId === atypeId ? $gameParty.numItems(a) : 0); }, 0)
  • Count possessed Armors of Equipment Type #3:
    Code:
    var etypeId = 3; $gameParty.armors().reduce(function(t, a) { return t + (a.etypeId === etypeId ? $gameParty.numItems(a) : 0); }, 0)
 

ZServ

Veteran
Veteran
Joined
Jun 16, 2014
Messages
259
Reaction score
71
Primarily Uses
Ah, perfect! This is incredibly helpful! Thank you a ton <3
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
12,710
Reaction score
13,107
First Language
English
Primarily Uses
RMVXA

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

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

Latest Threads

Latest Posts

Latest Profile Posts

I was planning to release a useless plugin for april fools, but then I thought I let it be.
Tfw every dev around me is using Live2D in their MV games and make me question my skills repeatedly.

Spending the day reworking my maps, especially the first "biome". This time it's not even in the dark. :LZSwink:
Activity on the forums has increased lately, probably because of people staying home. The amount of work for moderators has increased lol.

Forum statistics

Threads
95,522
Messages
929,783
Members
125,791
Latest member
Oersted_LAL
Top