[Question] YEP Equip Core - Conditional Stat Boosts based on Armor Type

Discussion in 'Javascript/Plugin Support' started by Keystone, Nov 6, 2018.

  1. Keystone

    Keystone Warper Member

    Messages:
    2
    Likes Received:
    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.
     
    #1
  2. Sakusphere

    Sakusphere Warper Member

    Messages:
    1
    Likes Received:
    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.
     
    #2
  3. Keystone

    Keystone Warper Member

    Messages:
    2
    Likes Received:
    0
    First Language:
    English
    Primarily Uses:
    RMMV
    Yup, this is exactly what I was looking for! Thanks a ton!
     
    #3

Share This Page