JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 158 of 171 View original ↗
  1. Fionn23 said:
    Is there a way to append a '%' sign to the value of MP gauges? I'm using Visustella plugins.
    Per the first post in this thread, it's intended for asking for help learning JavaScript, not with specific plugins.

    There aren't plugin parameters in the menu core or battle status or whatever you're using that determine the layout?
  2. ATT_Turan said:
    Per the first post in this thread, it's intended for asking for help learning JavaScript, not with specific plugins.

    There aren't plugin parameters in the menu core or battle status or whatever you're using that determine the layout?
    Oops. Sorry.

    I'm trying to find the setting but if it does have any, I can't seem to find it. I'm also playing around with Sprite_Gauge, but some of the functions are obfuscated. I'll start a thread for this. Sorry again.
  3. Fionn23 said:
    I'm also playing around with Sprite_Gauge
    In the default engine, the function is
    Code:
    Sprite_Gauge.prototype.drawValue = function() {
        const currentValue = this.currentValue();
        const width = this.bitmapWidth();
        const height = this.textHeight();
        this.setupValueFont();
        this.bitmap.drawText(currentValue, 0, 0, width, height, "right");
    };

    So you would simply change the last line to have currentValue + '%'

    If VisuStella's plugins overwrite that, then there's either an area for it in the plugin parameters or their code is obfuscated and there's not much anyone else can say.
  4. ATT_Turan said:
    In the default engine, the function is
    Code:
    Sprite_Gauge.prototype.drawValue = function() {
        const currentValue = this.currentValue();
        const width = this.bitmapWidth();
        const height = this.textHeight();
        this.setupValueFont();
        this.bitmap.drawText(currentValue, 0, 0, width, height, "right");
    };

    So you would simply change the last line to have currentValue + '%'

    If VisuStella's plugins overwrite that, then there's either an area for it in the plugin parameters or their code is obfuscated and there's not much anyone else can say.
    Yup, they overwritten it. And can't seem to find the plugin parameters for this.
  5. Fionn23 said:
    Yup, they overwritten it. And can't seem to find the plugin parameters for this.
    I noticed the same… one can only guess what the “new” function name is… but perhaps the MV YEP plugins can provide some insight?
  6. what do you use to check the player's x and y screen position in a script? I can only find the code for the map one
  7. Braix said:
    what do you use to check the player's x and y screen position in a script? I can only find the code for the map one
    $gamePlayer.screenX and .screenY

    In pixels, by the way.
  8. Also, those are functions: you'd call them with (), e.g. $gamePlayer.screenX().

    Note that those values are available without scripting:
    • Control Variables -> Game Data -> Character -> Screen X|Y.
  9. Hello. I'm creating a fairly complex menu system using events and images, but I'm stuck on a problem. Is there a way to temporarily disable the navigation system in the status menu using pageup and pagedown? I mean changing the party member in the status menu using pageup and pagedown. I would like the player to be unable to do this while accessing the status menu from my custom system, however, I want the player to be able to do this when they access the status menu from the standard RPG Maker menu.

    In other words, I'm looking for a scriptcall that disables pageup and pagedown, and another scriptcall to enable them. I've looked through the list of script calls, but haven't found anything.

    Thanks in advance.
  10. Youre making the windows yourself right? you could use a game switch in whatever function youve bound the 'pageup/down' handlers to to not function when its on, no?

    otherwise, to remove a handler you could try
    Code:
    delete window._handlers['pageup']
    and
    Code:
    window.setHandler('pagedown', this.nextActor.bind(this));
    or whatever youre already doing within that scene to add it back - window being a reference to the active window and assuming youre running this off the scene
  11. @Robro33 Thanks for your answer, but it didn't work. I got the following error message:

    "Cannot convert undefined or null to object"

    I forgot to mention that I use RPG Maker MZ and I don't know if that makes a difference.

    Also, I failed to mention that both my custom menu and the default RPG Maker menu access the default status screen. From my custom menu, I use the following script call to access the status screen:

    $gameParty.setMenuActor($gameParty.members()[1]);
    SceneManager.push(Scene_Status);

    As you can see, I'm accessing the status menu for the second party member. The first is an invisible character used only to make my custom menu work. It's only when accessing the status screen from my custom menu that I don't want the player to be able to use pageup and pagedown to navigate to other party members.
  12. The core status scene cannot process event commands, e.g. script calls. Making a blanket ban on certain inputs, and storing the banned inputs for later reinstatement, is relatively complicated.

    SolonWise said:
    It's only when accessing the status screen from my custom menu that I don't want the player to be able to use pageup and pagedown to navigate to other party members.
    The simplest and cleanest solution for this problem is like Robro suggested: a plugin that blocks the "next/previous actor" response when, say, a switch is on. E.g. (untested):
    plugin code
    JavaScript:
    /*:
     * @target MV MZ
     * @plugindesc Disable changing actor in menu when a switch is on.
     * @author Caethyril
     * @url https://forums.rpgmakerweb.com/posts/1481918/
     * @help Free to use and/or modify for any project, no credit required.
     */
    ;void (function() {
    "use strict";
      /** Next/prev actor is blocked when this switch is on. @type {number} */
      const SWITCH_ID = 123;
    
      /** @returns {boolean} `true` iff next/prev menu actor is allowed. */
      const isOk = function() {
        return !$gameSwitches.value(SWITCH_ID);  // "switch is off"
      };
    
      const alias_next = Scene_MenuBase.prototype.nextActor;
      Scene_MenuBase.prototype.nextActor = function() {
        if (isOk()) alias_next.apply(this, arguments);
      };
    
      const alias_prev = Scene_MenuBase.prototype.previousActor;
      Scene_MenuBase.prototype.previousActor = function() {
        if (isOk()) alias_prev.apply(this, arguments);
      };
    
    })();
    Just edit the SWITCH_ID number as needed~
  13. @caethyril

    Thanks for your answer and your code, but unfortunately the game crashes without any error message when I press pageup and pagedown with the switch on.
  14. OK I just tested and it soft-locks for me (stops responding to key-presses). If it actually crashed your game instead (showed an error and/or closed the game app), then I don't know what's going on.

    It's because I forgot to re-enable the window after handling input. Second attempt:
    plugin code v2
    JavaScript:
    /*:
     * @target MV MZ
     * @plugindesc Disable changing status actor when a switch is on.
     * @author Caethyril
     * @url https://forums.rpgmakerweb.com/posts/1481927/
     * @help Free to use and/or modify for any project, no credit required.
     */
    ;void (function() {
    "use strict";
      /** Next/prev actor is blocked when this switch is on. @type {number} */
      const SWITCH_ID = 123;
    
      /** @returns {boolean} `true` iff next/prev menu actor is allowed. */
      const isOk = function() {
        return !$gameSwitches.value(SWITCH_ID);  // "switch is off"
      };
    
      const alias_next = Scene_MenuBase.prototype.nextActor;
      Scene_MenuBase.prototype.nextActor = function() {
        if (isOk())
          alias_next.apply(this, arguments);
        else
          this.onActorChange();
      };
    
      const alias_prev = Scene_MenuBase.prototype.previousActor;
      Scene_MenuBase.prototype.previousActor = function() {
        if (isOk())
          alias_prev.apply(this, arguments);
        else
          this.onActorChange();
      };
    
    })();
  15. @caethyril

    It worked perfectly! Thank you so much sir! I don't know what I would do without this community!
  16. How do I run a function if a target is hit with an elemental skill that is weak to (elemental rate > 100%)?
  17. if youre using a plugin that lets you run code during an action's execution like visustella's battle core or Tyran's Eval Tags, Game_Actions have a calcElementRate() function that returns the element rate for the action itself. You'd give it the skill's target as an argument and see if it's value is greater than 1
  18. Good night. Is there a easy way to make every attack in battle to cause a permanent decrease in Max HP calculated on 25% of the damage received? I.E. A green slime attacks my protagonist causing 100 damage, so imediately the protagonist lose 25 max HP. I searched on the forum and found this damage formula:

    x = a.atk * 4 - b.def * 2; b.add_param(0, -x / 4); x

    But it didn't work, maybe because it was on a thread of RPG Maker VX Ace, and I use MZ.

    Then, ChatGPT gave me this:

    var damage = a.atk * 4 - b.def * 2; b._maxHp -= damage * 0.25; b._hp = Math.min(b._hp, b._maxHp); return damage;

    But it also didn't work.

    It is possible to achieve it on damage formula alone or do I need a plugin? Thanks in advance.
  19. While it might be possible to do that in the damage formula, as has been mentioned several times by myself, and yanfly, do not do things like this in the damage formula. Adding scripts to the damage formula causes those scripts to happen unexpectedly during combat when AI controlled allies or enemies are trying to determine what skill to use. When skills have the same priority, some degree of randomness decides what they use, but sometimes the deciding factor is the amount of damage the skill would do, which is tested. The test would cause the script to happen, regardless of whether the skill ended up being used or not.

    You're going to want to use Yanfly's SkillCore, or the Visustella Skill Core plugins to achieve this effect via an <after damage eval> from the skills notetags.