Counting Equipped Weapons and Armors

jojarth

Villager
Member
Joined
Oct 16, 2012
Messages
9
Reaction score
1
First Language
English
Primarily Uses
One part of a script I'm working on includes counting the number of weapons and armors that all party members are equipped with, and for some reason I am having the hardest time getting this count. Please note I am very new to coding, and javascript, so I apologize if I'm not clear. 


Example: Equipment count is 0, and our adventuring group finds a chest. In the chest is 2 long swords and leather armor. Character A equips a long sword, Equipment counts goes to 1. Character B also equips a long sword, Equipment count goes to 2. 


Later on, character B finds he likes fighting with his fist, so he unequips his weapon, Equipment count goes back to 1. Then character 1 remembers they found the leather armor and equips it, having the Equipment count go back up to 2. Finally, character c equips the longsword character b didn't want, and Equipment count goes up to 3. 


About the closest thing I can find is too go through $gameParty.members and loop through .hasWeapon($dataWeapons), but I would have to script it for each character, and for each weapon, then count the boolean trues that come out of the script, but I'm even having a problem figuring out how to do that. 


Is there an easier way to do this? Am I making this harder than it really is? 


Thanks ahead of time for all help provided. 
 
Last edited by a moderator:

jojarth

Villager
Member
Joined
Oct 16, 2012
Messages
9
Reaction score
1
First Language
English
Primarily Uses
Additional information:


Here is the snippet of code that I was using to attempt to count if a weapon was equipped or not (this doesn't count armor yet).


var member0weapon = 0;
var i = 0;
while (i < 999){
var member0weapontest = Boolean($gameParty.members()[0].hasWeapon($dataWeapons));
if (Boolean(member0weapontest)); {
var member0weapon = 1;
};
i++
};


The problem I ran into is that the above code will always return "1", regardless of if member 0 is equipped with a weapon or not.


The reason I did it this way, is if I do the following: console.log($gameParty.members()[0].hasWeapon($dataWeapons[1])) and member 0 is equipped with weapon 1, it returns true. If member 0 is equipped with anything else, nor nothing at all, it returns false. 


Again, if there is an easier way to do this, please let me know! If I'm on the right track, but just need tweaks, let me know as well.


I should probably note that I am using Yanfly's EquipCore. 


Thanks again for your help!
 
Last edited by a moderator:

Clock Out

Veteran
Veteran
Joined
Jun 14, 2016
Messages
92
Reaction score
45
First Language
English
Primarily Uses
RMMV
Try using the weapons() and armors() methods. They return arrays of equipped weapons/armors for a given party member. Sum the length properties and you're good to go.


Here's an example for a function that returns the sum of weapons equipped.

Code:
function partyWeaponCount() {
    return $gameParty.members().reduce(function (sum, member) {
        return sum += member.weapons().length;
    }, 0);
}
 
Last edited by a moderator:

jojarth

Villager
Member
Joined
Oct 16, 2012
Messages
9
Reaction score
1
First Language
English
Primarily Uses
Try using the weapon() and armors() methods. They return arrays of equipped weapons/armors for a given party member. Sum the length properties and you're good to go.


Here's an example for a function that returns the sum of weapons equipped.



function partyWeaponCount() {
return $gameParty.members().reduce(function (sum, member) {
return sum += member.weapons().length;
}, 0);
}




Thank you so much! This is working perfectly! I really really appreciate your help! 
 
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