JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 138 of 171 View original ↗
  1. Hi, I'm trying to add a function that gets called after the party formation is changed. How can I append it to the existing function for formation editing? (I'm using MZ.)
  2. @sunner - the method is Scene_Menu#onFormationOk. I'd suggest something like this (untested):
    plugin code
    JavaScript:
    /*:
     * @target MV MZ
     * @plugindesc Description
     * @author Author
     * @url https://forums.rpgmakerweb.com/posts/1410617/
     * @help Free to use and/or modify for any project, no credit required.
     */
    ;void (() => {
    'use strict';
      // store current method
      const alias = Scene_Menu.prototype.onFormationOk;
      // replace method
      Scene_Menu.prototype.onFormationOk = function() {
        // invoke stored method
        alias.apply(this, arguments);
        // if there is no actor waiting to be swapped
        if (this._statusWindow.pendingIndex() === -1) {
          alert("your code here!");
        }
      };
    })();

    [Edit: tested it, should work OK to catch formation changes from the pause menu. If you want to catch them from anywhere, try replacing both instances of Scene_Menu.prototype.onFormationOk with Game_Party.prototype.swapOrder.]
  3. Is there a way to call a specific damage popup? Like if i wanted to us js to call the Miss popup or even a custom word.
  4. Oggy said:
    Is there a way to call a specific damage popup? Like if i wanted to us js to call the Miss popup or even a custom word.
    No, there's not an easy way.

    The damage popups are based on the action results, so to just randomly call something would involve you creating a fake action, populating the results, attaching it to the actor, calling the sprite.

    If you're asking for your block plugin, the best practice would be to create a new property of action results to represent blocked, then make a function to draw that text and modify Sprite_Damage.setup() to call it.
  5. Hi. I have my player character on the left side of the screen, with the enemy placed on the right side. It feels more natural to me. To reposition the player character, I use SVActorPosition, which I believe comes with MV. To perfectly position the enemy, I use MrTSEnemyPositions. However, both plugins merely allow the repositioning of the entities, they are still facing the wrong directions. The player is looking left, the enemy is looking right. Now, for the player, I have this script I got from a reddittor (I don't remember who :T):

    JavaScript:
    var _leftSide_Sprite_Actor_createMainSprite = Sprite_Actor.prototype.createMainSprite;
    Sprite_Actor.prototype.createMainSprite = function() {
        _leftSide_Sprite_Actor_createMainSprite.call(this);
        this.scale.x = -1;
        
    };
    
    Sprite_Actor.prototype.updateTargetPosition = function() {
        if (this._actor.isActing()) {
            this.stepBack();
        } else if (this._actor.canMove() && BattleManager.isEscaped()) {
            this.retreat();
        } else if (!this.inHomePosition()) {
            this.stepForward();
        }
    };

    It fixes the issue of the player facing left. The player starts the battle facing the enemy, who is sitting on the right corner of the screen. That doesn't work for the enemy, though. The enemy ALWAYS start the battle looking to the right, they only turn to the left after the first turn.

    So, is there any simple piece of code I could add to the code above to fix the issue with the enemy?

    Thank you!
  6. Nah not for my plugin, i alreadymade new action resutls. I was just curious because I know you can call motions easily so I wasn't sure if there was a thing for popups in a similar fasion. Thanks for the response.
  7. @DrBuni - I wrote a small plugin for this a while ago, in case you want to try it:
    plugin code in case of link rot
    JavaScript:
    /*:
     * @plugindesc Horizontally mirror sideview actor sprites etc.
     * @author Caethyril
     * @help Terms of use:
     *    Free to use and/or modify~
     */
    
    (function(alias) {
        // Horizontally mirror movement offsets
        Sprite_Actor.prototype.startMove = function(x, y, duration) {
            alias.call(this, -x, y, duration);
        };
    })(Sprite_Actor.prototype.startMove);
    
    (function(alias) {
        // Mirror X value when setting actor home position
        Sprite_Actor.prototype.setHome = function(x, y) {
            alias.call(this, Graphics.boxWidth - x, y);
        };
    })(Sprite_Actor.prototype.setHome);
    
    (function(alias) {
        // Horizontally mirror actor battler sprite immediately after creation
        Sprite_Actor.prototype.createMainSprite = function() {
            alias.apply(this, arguments);
            this._mainSprite.scale.x *= -1;
        };
    })(Sprite_Actor.prototype.createMainSprite);
    
    (function(alias) {
        // Horizontally mirror/reposition weapon sprite immediately after creation
        Sprite_Weapon.prototype.initMembers = function() {
            alias.apply(this, arguments);
            this.scale.x *= -1;
            this.x *= -1;
        };
    })(Sprite_Weapon.prototype.initMembers);
  8. caethyril said:
    @DrBuni - I wrote a small plugin for this a while ago, in case you want to try it:
    plugin code in case of link rot
    JavaScript:
    /*:
     * @plugindesc Horizontally mirror sideview actor sprites etc.
     * @author Caethyril
     * @help Terms of use:
     *    Free to use and/or modify~
     */
    
    (function(alias) {
        // Horizontally mirror movement offsets
        Sprite_Actor.prototype.startMove = function(x, y, duration) {
            alias.call(this, -x, y, duration);
        };
    })(Sprite_Actor.prototype.startMove);
    
    (function(alias) {
        // Mirror X value when setting actor home position
        Sprite_Actor.prototype.setHome = function(x, y) {
            alias.call(this, Graphics.boxWidth - x, y);
        };
    })(Sprite_Actor.prototype.setHome);
    
    (function(alias) {
        // Horizontally mirror actor battler sprite immediately after creation
        Sprite_Actor.prototype.createMainSprite = function() {
            alias.apply(this, arguments);
            this._mainSprite.scale.x *= -1;
        };
    })(Sprite_Actor.prototype.createMainSprite);
    
    (function(alias) {
        // Horizontally mirror/reposition weapon sprite immediately after creation
        Sprite_Weapon.prototype.initMembers = function() {
            alias.apply(this, arguments);
            this.scale.x *= -1;
            this.x *= -1;
        };
    })(Sprite_Weapon.prototype.initMembers);
    Thank you so much. I gave it a try, with and without the other two plugins set to ON, but the problem of the enemy facing the wrong side of the screen (at least during the first turn) persists. Which makes me wonder if there isn't some other plugin affecting the enemy, and figuring that out is my next step into solving this issue.
  9. @DrBuni - ah, sorry. actorsOnLeft doesn't affect enemies unless they inherit from Sprite_Actor (some animated-enemy plugins may do that). I also missed the main point: you are using a plugin that mirrors enemy sprites mid-battle. Perhaps YEP Battle Engine Core or something.

    Consider starting a new thread in Plugin Support, and mention which plugins you're using~
  10. hello, it me again Happy new year.

    I have a rain heal skill that heals X amount of HP and removes Burn to 1 ally but what i am looking for is to also do the same to all allies in the party with a specific state 'Wet'

    found this to check if an actor in battle has the state but not sure how to implement in my <After Eval>

    Code:
    $gameParty.battleMembers().some(actor => actor.isStateAffected(X))

    Im using YEP_SkillCore and YEP_BuffsStateCore to make this work like always.

    Thanks for your time!
  11. you dont want to use some() if you want the effect to happen on every element in the array that meets some condition. you use it if you want the thing to happen if any element meets the condition. you'd usually filter() and forEach(), or forEach and some conditional statement for that, but <After Eval> gets ran on every target within the scope anyways. something like
    JavaScript:
    if (target.isStateAffected(wet)){
        target.gainHp(99);
        target.removeState(burn);
    }
    would work in an all allies scope
  12. Robro33 said:
    you dont want to use some() if you want the effect to happen on every element in the array that meets some condition. you use it if you want the thing to happen if any element meets the condition. you'd usually filter() and forEach(), or forEach and some conditional statement for that, but <After Eval> gets ran on every target within the scope anyways. something like
    JavaScript:
    if (target.isStateAffected(wet)){
        target.gainHp(99);
        target.removeState(burn);
    }
    would work in an all allies scope
    While this will help me a lot with other skills (thank you), this rain skill only targets one ally to heal them even if that ally doesnt have the state, then it will check the party to see if any of them have the state so it can heal those who have it.

    Sorry if i didnt explain myself correctly at first
  13. SnakeBD said:
    While this will help me a lot with other skills (thank you), this rain skill only targets one ally to heal them even if that ally doesnt have the state, then it will check the party to see if any of them have the state so it can heal those who have it.
    ah. ok. that changes things. so it heals one target and removes burn, but also if anyone in the party is wet, itll heal them and remove their burns as well?

    Code:
    <Post-Damage Eval>
    user.friendsUnit().aliveMembers().forEach(ally => {
        if (ally.isStateAffected(wet)){ 
            ally.removeState(burn)
            ally.gainHp(value);
        };
    })
    <Post-Damage Eval>
    Use the editor's formula box and effects pane to handle healing the target and curing the burn
    id change the tags from <After Eval> to <Post-Damage Eval> just so id be able to directly use the value of the initial heal to determine the rest, but if you need to use the <After Eval> for whatever reason, youll have to put in your health calculation in
  14. How do I check if an actor has a special flag: auto battle?
  15. Fionn23 said:
    How do I check if an actor has a special flag: auto battle?
    JavaScript:
    actor.isAutoBattle()
    with actor being the object of the actor that you want to check. How to get that object depends on where you're using this and what you're trying to do.
  16. Robro33 said:
    ah. ok. that changes things. so it heals one target and removes burn, but also if anyone in the party is wet, itll heal them and remove their burns as well?

    Code:
    <Post-Damage Eval>
    user.friendsUnit().aliveMembers().forEach(ally => {
        if (ally.isStateAffected(wet)){
            ally.removeState(burn)
            ally.gainHp(value);
        };
    })
    <Post-Damage Eval>
    Use the editor's formula box and effects pane to handle healing the target and curing the burn
    id change the tags from <After Eval> to <Post-Damage Eval> just so id be able to directly use the value of the initial heal to determine the rest, but if you need to use the <After Eval> for whatever reason, youll have to put in your health calculation in
    sorry to bother again, but this only worked on the caster of the skill and nobody else on the team.

    probably because im missing a pluglin for this?
  17. SnakeBD said:
    sorry to bother again, but this only worked on the caster of the skill and nobody else on the team.

    probably because im missing a pluglin for this?
    You said you're using Yanfly plugins, so @Robro33 gave you notetags from the Buffs & States Core.

    However, there's a typo and the notetag is not closed correctly: </Post-Damage Eval>
    (see, we get each other's typos!)

    If you're still having trouble getting it to work, you should start a thread about it (this thread is really not supposed to be for help with plugins, per the first post).
  18. How can I change the font size inside Window_BattleStatus?
  19. Fionn23 said:
    How can I change the font size inside Window_BattleStatus?
    Windows have a contents.fontSize property.

    So I'd try copying/aliasing the Window_BattleStatus.prototype.initialize() method and adding a line that sets this.contents.fontSize equal to your desired size.
  20. ATT_Turan said:
    Windows have a contents.fontSize property.

    So I'd try copying/aliasing the Window_BattleStatus.prototype.initialize() method and adding a line that sets this.contents.fontSize equal to your desired size.
    It isn't working for me. The values inside this.contents do change. But the Window_BattleStatus still remains the same. I do have VS Battle Core installed though. Here's my code:
    JavaScript:
     Window_BattleStatus.prototype.initialize = function(rect) {
        Window_StatusBase.prototype.initialize.call(this, rect);
        
        this.frameVisible = false;
        this.openness = 0;
        this._bitmapsReady = 0;
        this.contents.fontSize = 8;//inserted code
        this.contents.fontBold = true; //inserted code
        this.contents.textColor = '#0000FF'; //inserted code
        console.log(this.contents); //inserted code
        this.preparePartyRefresh();
        
    };