Keystone

Warper
Member
Joined
Nov 6, 2018
Messages
3
Reaction score
0
First Language
English
Primarily Uses
RMMV
I am trying to create a system where armors can get a "set bonus" of sorts when the user equips multiple of the same type. So for example, let's say we have a Helmet of Fire (Armor Type: Fire) which grants +2 DEF and a Tunic of Flame (Also Armor Type: Fire) which grants +5 DEF. If the user equips both, then they will get an additional +10 ATK on top of the +7 DEF from their default stats.

I feel like I'm close to figuring this out but I need some pointers on finishing up the code I wrote to achieve this. Here's what I have (Note: I am using Yanfly's Equip Core):

Code:
<Custom Parameters>
user.equips().forEach(function(item) { if (item !== null) { if (item.atypeId === 7 && item.id !== 4) { atk = 10; }}});
</Custom Parameters>

What this does is it parses through the user's equipment and checks the armor type ID of each equipment (in this case, the Fire armor type is ID = 7. Now, I don't want this to activate when I equip only one of the required items, so I am also checking to make sure the item.id is not the item this code is on, in this case the item that this script is attached to has ID = 4.

I don't like the fact that I have to hardcode the item.id check; I'd much prefer something like item.id !== this.id, but I can't do that since "this" refers to the actor equipping the armor, not the armor itself. I am curious to see if anyone can come up with a better solution than this.
 

Sakusphere

Warper
Member
Joined
Nov 12, 2018
Messages
1
Reaction score
0
First Language
English
Primarily Uses
RMMV
I hope this is what you were asking.
You should be able to compare the item to itself if you set the item to a variable prior to the start of the function. I modified it slightly to add attack for every piece so it was easier to verify how it took affect.

Code:
<Custom Parameters>
var checkUsingThis = item;
user.equips().forEach(function(item) {
  if (item !== null) {
    if (item.atypeId === 7
         && item !== checkUsingThis) {
      atk += 10;
    }
  }
});
</Custom Parameters>

I put this code on one piece of gear with armor type 7 then equipped it. My attack was not changed because the item === checkUsingThis. I equipped another 2 pieces with armor type 7 and my attack was increased by 20. When I removed the piece with this code, my attack went back to normal since it was the piece getting the attack bonus for having more of the armor type equipped.
 

Keystone

Warper
Member
Joined
Nov 6, 2018
Messages
3
Reaction score
0
First Language
English
Primarily Uses
RMMV
Yup, this is exactly what I was looking for! Thanks a ton!
 

Latest Threads

Latest Posts

Latest Profile Posts

I got the pause Icon to use 6 frames instead of 4, PLUS it goes: top 1-2-3, bottom 1-2-3. And everything just by playing around with the code & i think i've figured the important parts out now <3
eUuH09A.gif

ps. the animation isn't as "wonky" in RL, stupid recording -.-
Friendly reminder: Make a back up of your project! ;3 I just did one and recognized I would have lost a week worth of work.
Why is there undo but not a redo like every other software in existence? :blink:
Chili: Evolved to taste spicy so no animal would eat them.

Humans: "Jokes on you ..."

Forum statistics

Threads
113,716
Messages
1,076,872
Members
147,739
Latest member
ComicTM
Top