Yanfly's Status Menu Core: Tweaking the Elements menu?

Discussion in 'Javascript/Plugin Support' started by Dirge, Jul 23, 2017.

  1. Dirge

    Dirge Sound Engineer Veteran

    Messages:
    413
    Likes Received:
    281
    Location:
    Canada
    First Language:
    English, German
    Primarily Uses:
    N/A
    Hey all. Unfortunately I'm a JS noob, so I have no idea how to do this...

    I want the Elements tab, exactly as it is now, except I want it to display the outgoing elemental damage rate. Specifically I'm using his Elements Core to amplify outgoing elemental damage based on equips and I want the player to be able to see how much outgoing damage of each element they have.

    The parameter should exist, since <Element Amplify> has to impact something, right?

    Is it possible to go in and tweak it so the "Elements" page shows outgoing elemental damage rates instead of elemental damage resistance rates? What exactly would I change? This soooouuuunds like it would be a fairly easy thing to swap, since it's also a rate and it would display exactly the same, so it really should be a matter of swapping out the reference to "elemental resistance" to "elemental damage"... I would think... but I don't exactly know.

    EDIT: I thiiiiiiiiiiink I may have found the right section of the Status Menu Core?
    Code:
    Window_StatusInfo.prototype.drawElementData = function(eleId, dx, dy, dw) {
        eleId = parseInt(eleId);
        var eleName = $dataSystem.elements[eleId];
        var eleRate = this._actor.elementRate(eleId);
        dx += this.textPadding();
        dw -= this.textPadding() * 2;
        this._bypassResetTextColor = true;
        this.changeTextColor(this.systemColor());
        this.drawTextEx(eleName, dx, dy);
        this._bypassResetTextColor = false;
        this.setRateColor(eleRate);
        var text = (eleRate * 100).toFixed(Yanfly.Param.StatusEleDec) + '%';
        this.drawText(text, dx, dy, dw, 'right');

    I think I'd have to change "this._actor.elementRate(eleId);" to whatever parameter references outgoing damage instead of resistance, but I have no idea what that might be..
     
    Last edited: Jul 23, 2017
    #1
  2. Poryg

    Poryg Dark Lord of the Castle of Javascreeps Veteran

    Messages:
    3,918
    Likes Received:
    9,891
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    In order to get the element amplify rate, you can put a line
    $gameVariables.setValue (300+elementId+number of elements*(this.actor().actorId-1), 100+rate)
    with 300 and number of game elements changeable according to your game.
    inside the Element's core plugin inside
    Game_Actor.prototype.elementAmplifyRate = function (element Id) {
    }
    . Put it inside this function before the return rate line.
    Then edit the statusmenu in the exact passage you found in the earlier post and replace this._actor.elementRate(eleId) with
    $gameVariables.value (300+elementId+number of elements*($gameActors.actor().actorId-1))

    Hopefully it works.
     
    #2
    Jeremiah Eastman likes this.
  3. Dirge

    Dirge Sound Engineer Veteran

    Messages:
    413
    Likes Received:
    281
    Location:
    Canada
    First Language:
    English, German
    Primarily Uses:
    N/A
    I...um..almost get it? I think? Haha. Let me make sure I'm understanding this correctly:

    So, in the Element Core, I need to find:
    Code:
    Game_Actor.prototype.elementAmplifyRate = function (element Id) {
    }
    And, inside it, add (before the return rate line):
    Code:
    $gameVariables.setValue (300+elementId+number of elements*(this.actor().actorId-1), 100+rate)
    With "300" and "number of elements" changed according to my game. "Number of elements" is fairly obvious I guess, that's the total number of elements I have in my game, right? But what is the "300" for, and what do I change it to?

    After that's done, I open up the status menu plugin, and go to the passage I found and replace "this._actor.elementRate(eleId)" with "$gameVariables.value (300+elementId+number of elements*($gameActors.actor().actorId-1))" ... I'm pretty sure I understand that, at least!

    I'm gonna give this a try now and see if it works. Will update either way.

    EDIT: Plugged it in, just left the "300" how it was 'cause I don't know what to change it to, and changed "number of elements" to "10" (having plugged in 10 elements in the database of course). When I go to the Elements status menu page, it crashes with the error "elementId is not defined", so I guess the "elementId" portion needs to be defined too but I'm not sure how to do that.
     
    Last edited: Jul 24, 2017
    #3
  4. Poryg

    Poryg Dark Lord of the Castle of Javascreeps Veteran

    Messages:
    3,918
    Likes Received:
    9,891
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    My mistake, I made one error there.

    Explanation of the code is simple:
    $gameVariables.setValue (variableId, value):
    $gameVariables.setValue takes two variables. One of them is the variable ID we want to edit, the other one is value of the variable.

    We want to have the values accessible any time though, so in order to do so we have to make sure we achieved different variables, we have to make sure we have different variables. And for the simplicity we are reserving as many variables as there are actors x elements in the game. This is why there is that strange formula.

    300+elementId+number of elements*($gameActors.actor().actorId-1)

    300 is a static number and it is the first variable it will be using. Number of elements multiplied by number of actors the game has means how many variables the game will be using. So if we have 10 elements and 4 actors, then the game will be using 40 variables, since 10x4 is 40.
    Going from the first one, which we set as 300, we will use variables 300-339 for this process.
    If you are already using variables 300-339 for a different thing, then simply you can change the 300 to something where you don't use 40 consecutive variables. Just mark those variables properly so you don't use them in anything else.

    The code in the Element core should be fine. Just for the checkup I'll provide full code implementing your 10 elements so that you can copy paste it just in case.

    Game_Actor.prototype.elementAmplifyRate = function(elementId) {
    var rate = Game_Battler.prototype.elementAmplifyRate.call(this, elementId);
    var length = this.equips().length;
    for (var i = 0; i < length; ++i) {
    var obj = this.equips();
    rate += this.getObjElementAmplifyRate(obj, elementId);
    }
    rate += this.getObjElementAmplifyRate(this.actor(), elementId);
    rate += this.getObjElementAmplifyRate(this.currentClass(), elementId);
    $gameVariables.setValue (300+elementId+10*(this.actor().actorId-1), 100+rate)
    return rate;
    };
    with 300 in bold, because it is changeable if necessary. The rest is not changeable.
    However, I screwed up in the status menu.

    elementId is defined inside the function
    Game_Actor.prototype.elementAmplifyRate = function (elementId) {
    }, so there is no problem with that. However, I completely forgot that inside the status menu it isn't ElementId, but eleId. So I corrected the code and also simplified it. In the spoiler you'll again find the whole function. Should work now.

    Window_StatusInfo.prototype.drawElementData = function(eleId, dx, dy, dw) {
    eleId = parseInt(eleId);
    var eleName = $dataSystem.elements[eleId];
    var eleRate = $gameVariables.value (300+eleId+10*(this._actor._actorId-1)
    dx += this.textPadding();
    dw -= this.textPadding() * 2;
    this._bypassResetTextColor = true;
    this.changeTextColor(this.systemColor());
    this.drawTextEx(eleName, dx, dy);
    this._bypassResetTextColor = false;
    this.setRateColor(eleRate);
    var text = (eleRate * 100).toFixed(Yanfly.Param.StatusEleDec) + '%';
    this.drawText(text, dx, dy, dw, 'right');
     
    #4
  5. Dirge

    Dirge Sound Engineer Veteran

    Messages:
    413
    Likes Received:
    281
    Location:
    Canada
    First Language:
    English, German
    Primarily Uses:
    N/A
    Hmm. Now it seems to have disabled the Status Menu Core plugin completely.

    I've uploaded my edited version of the plugin here. Maybe you'll be able to see what I did wrong? I'm just getting the default status menu now.
     
    #5
  6. Poryg

    Poryg Dark Lord of the Castle of Javascreeps Veteran

    Messages:
    3,918
    Likes Received:
    9,891
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    Jesus Christ, I missed a bracket.
    ......._actorId-1)) is right.
     
    #6
  7. Dirge

    Dirge Sound Engineer Veteran

    Messages:
    413
    Likes Received:
    281
    Location:
    Canada
    First Language:
    English, German
    Primarily Uses:
    N/A
    Okay! The menu is appearing now :D

    However, equipping items with the <Element Amplify> tag doesn't seem to actually be changing the menu (or the actual damage output). I suppose that's for a different support thread though. Thank you Poryg, you are a gem <3
     
    #7
  8. Poryg

    Poryg Dark Lord of the Castle of Javascreeps Veteran

    Messages:
    3,918
    Likes Received:
    9,891
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    Nevermind, I understood the command wrong. Apparently it takes a while before it updates itself.
     
    Last edited: Jul 24, 2017
    #8
  9. Dirge

    Dirge Sound Engineer Veteran

    Messages:
    413
    Likes Received:
    281
    Location:
    Canada
    First Language:
    English, German
    Primarily Uses:
    N/A
    @Poryg Okay I just figured out why the actual damage wasn't working, I was being stupid and had forgotten a character in the notetag.

    Buuuuut... the element status menu isn't updating, even after a couple minutes of waiting. It's still showing 0.00% for all elements.
     
    #9
  10. Poryg

    Poryg Dark Lord of the Castle of Javascreeps Veteran

    Messages:
    3,918
    Likes Received:
    9,891
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    That is because I am stupid too. This function Game_Actor.prototype.elementAmplifyRate is a function that is used only in battle. I am trying to look at it now and see if there is a way to activate it sooner, but so far it's been throwing errors at me.
     
    #10
  11. Dirge

    Dirge Sound Engineer Veteran

    Messages:
    413
    Likes Received:
    281
    Location:
    Canada
    First Language:
    English, German
    Primarily Uses:
    N/A
    Ooooooooooh, that does put a barrier on it. Perhaps there's a way to scan equipment for amplify notetags, then just put the sum total into a variable and display that in the menu? I've no idea, as always, how feasible the ideas I say are...
     
    #11
  12. Poryg

    Poryg Dark Lord of the Castle of Javascreeps Veteran

    Messages:
    3,918
    Likes Received:
    9,891
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    I've got it!!!!!!

    And without using any variables too :D
    One of them is edited drawElementData function. The two remaining are transformed functions from element core to work under status menu core. You'll need to add them all to the status menu core... Or if you want, you can use it as a separate plugin, but be sure to put it under status menu core.

    Window_StatusInfo.prototype.getObjElementAmplifyRate = function(obj, elementId) {
    if (!obj) return 0;
    if (!obj.elementAmplify) return 0;
    return obj.elementAmplify[elementId] || 0;
    };

    Window_StatusInfo.prototype.elementAmplifyRate = function(elementId) {
    var rate = 0;
    var length = this._actor._states.length;
    for (var i = 0; i < length; ++i) {
    var obj = this._actor._states;
    rate += this.getObjElementAmplifyRate(obj, elementId);
    }
    var length = this._actor._equips.length;
    for (var i = 0; i < length; ++i) {
    var obj = this._actor._equips;
    rate += this.getObjElementAmplifyRate(obj, elementId);
    }
    rate += this.getObjElementAmplifyRate(this._actor._actorId, elementId);
    rate += this.getObjElementAmplifyRate(this._actor._classId, elementId);
    console.log(rate)
    return rate;
    return rate;
    };

    Window_StatusInfo.prototype.drawElementData = function(eleId, dx, dy, dw) {
    eleId = parseInt(eleId);
    var eleName = $dataSystem.elements[eleId];
    var eleRate = Window_StatusInfo.prototype.elementAmplifyRate.call (this, eleId);
    console.log(this._actor)
    console.log(eleRate)
    dx += this.textPadding();
    dw -= this.textPadding() * 2;
    this._bypassResetTextColor = true;
    this.changeTextColor(this.systemColor());
    this.drawTextEx(eleName, dx, dy);
    this._bypassResetTextColor = false;
    this.setRateColor(eleRate);
    var text = (eleRate * 100).toFixed(Yanfly.Param.StatusEleDec) + '%';
    this.drawText(text, dx, dy, dw, 'right');
    };

    If it works, feel free to delete that extra line in element core, because you won't need it anymore.
    Note that this shows only the boosts.
     
    #12
  13. Dirge

    Dirge Sound Engineer Veteran

    Messages:
    413
    Likes Received:
    281
    Location:
    Canada
    First Language:
    English, German
    Primarily Uses:
    N/A
    I can't seem to get it to work/do anything - but this is veeeeery likely just me being silly.

    I tried pasting all of that into the status menu core plugin, below the section I edited previously. I also tried replacing that section entirely and just pasting this whole block in its place. Aaaand I tried making a new .js file with just your code and adding that as a plugin directly below StatusMenuCore, and none of it seems to have changed anything haha
     
    #13
  14. Poryg

    Poryg Dark Lord of the Castle of Javascreeps Veteran

    Messages:
    3,918
    Likes Received:
    9,891
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    dayum it... I guess I'm gonna throw in the towel.
    Sorry.
     
    #14
  15. Dirge

    Dirge Sound Engineer Veteran

    Messages:
    413
    Likes Received:
    281
    Location:
    Canada
    First Language:
    English, German
    Primarily Uses:
    N/A
    Aww, it's okay. I appreciate all the effort!
     
    #15
  16. Dirge

    Dirge Sound Engineer Veteran

    Messages:
    413
    Likes Received:
    281
    Location:
    Canada
    First Language:
    English, German
    Primarily Uses:
    N/A
    Actually....hang on a second @Poryg ... just had a thought. I could have each of the items add their amplify % to a variable, right?

    For example... I'm using Yanfly's Attachable Augments plugin. Which supports the following sort of Lunatic Mode tags, as an example:
    <Augment Attach Eval: type>
    item.price += $gameParty.highestLevel();
    item.params[0] += $gameParty.highestLevel();
    </Augment Attach Eval: type>

    Wouldn't it be possible to have a variable assigned to each element type and each actor (the same way you were doing it in the script), and just add that in with an if/else chain?

    So... it would look like this in total for notetags (but with actual JS that I can't figure out lol)
    <Amplify Element 3: +10%>
    <Augment Attach Eval: type>
    If actorId=1, variable 300 +10,
    else if actorId=2, variable 301 +10
    else if actorId=3, variable 302 +10
    else if actorId=4, variable 303 +10
    </Augment Attach Eval: type>

    Then in the status menu, for actor 1, display the value of variable 300 with the element Id of element 3.

    It would require more manual work for notetagging but that's okay (i've already got a billion things to notetag already, what's one more...)
     
    #16
  17. Poryg

    Poryg Dark Lord of the Castle of Javascreeps Veteran

    Messages:
    3,918
    Likes Received:
    9,891
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    This runs into one huge problem...

    <Amplify element x: +y%> is a notetag usable only for actor, class, skill, weapon, armor and state. Not for an item.
     
    #17
  18. Dirge

    Dirge Sound Engineer Veteran

    Messages:
    413
    Likes Received:
    281
    Location:
    Canada
    First Language:
    English, German
    Primarily Uses:
    N/A
    Ah, yeah, I ran into that already. I got around that by having the augment, when attached, apply a passive state, and in turn having that state apply the amplify element notetag.
     
    #18
  19. Poryg

    Poryg Dark Lord of the Castle of Javascreeps Veteran

    Messages:
    3,918
    Likes Received:
    9,891
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    In that case it is possible, although I wanted to avoid hardcoding.

    Alright, you can use this attach eval (I changed 300,301,302,303 into 300,310,320,330, because if we have it like this - one actor's 10 element rates, then another one's 10 element rates, then another one's element rates, etc., it's easier to code the formula).
    <Augment Attach Eval: type>
    if (user.actorId == 1) {
    $gameVariables.setValue (300, $gameVariables.value (300)+10)
    }else if (user.actorId == 2) {
    $gameVariables.setValue (310, $gameVariables.value (310)+10)
    }else if (user.actorId == 3) {
    $gameVariables.setValue (320, $gameVariables.value (320)+10)
    }else{
    $gameVariables.setValue (330, $gameVaruables.value (330)+10)
    }
    </Augment Attach Eval: type>
    <Augment Detach Eval: type>
    if (user.actorId == 1) {
    $gameVariables.setValue (300, $gameVariables.value (300)-10)
    }else if (user.actorId == 2) {
    $gameVariables.setValue (310, $gameVariables.value (310)-10)
    }else if (user.actorId == 3) {
    $gameVariables.setValue (320, $gameVariables.value (320)-10)
    }else{
    $gameVariables.setValue (330, $gameVaruables.value (330)-10)
    }
    </Augment Detach Eval: type>

    And then the status menu thing would look like this.

    Window_StatusInfo.prototype.drawElementData = function(eleId, dx, dy, dw) {
    eleId = parseInt(eleId);
    var eleName = $dataSystem.elements[eleId];
    var eleRate = $gameVariables.value (300 + (eleId -1) + 10 * (this._actor._actorId - 1))
    dx += this.textPadding();
    dw -= this.textPadding() * 2;
    this._bypassResetTextColor = true;
    this.changeTextColor(this.systemColor());
    this.drawTextEx(eleName, dx, dy);
    this._bypassResetTextColor = false;
    this.setRateColor(eleRate);
    var text = (eleRate).toFixed(Yanfly.Param.StatusEleDec) + '%';
    this.drawText(text, dx, dy, dw, 'right');

    Note: It shows only the bonuses. If you wish to use the complete percentage, then simply add
    eleRate += 100
    under the var eleRate line.
     
    #19
  20. Dirge

    Dirge Sound Engineer Veteran

    Messages:
    413
    Likes Received:
    281
    Location:
    Canada
    First Language:
    English, German
    Primarily Uses:
    N/A
    I've got the menu appearing, but when I go in and attach the augment, I get this error:
    Image Link

    I did go in and correct the "varuable" type in the notetag, also. Haha

    EDIT: I created a quick event to test it and the menu itself is working, but the numbers themselves are red. How would I change that to be green?
     
    Last edited: Jul 24, 2017
    #20

Share This Page