JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 169 of 171 View original ↗
  1. Would my HTML code in JavaScript, created for my Blogger blog, work as a script in RPG Maker MV?
  2. Harken_W said:
    Hope my question make sense. I'm looking for a script call that's asking 'If the user that is currently acting has X state do XYZ'
    This is context-dependent. My first suggestions, without plugins, would be:
    • BattleManager._subject - battler who is currently acting (action phase).
    • BattleManager.actor() - actor who is currently inputting (input phase).
    Harken_W said:
    For even more detail, i'm using SRD Timed attack core, and just want the bar to move slower if the user casting has slow state for example.
    That plugin seems to permit JS evals in its Speed field, so you could try something like:

    Speed: BattleManager._subject.isStateAffected(123) ? 10 : 100
    I.e. "if the acting battler has state ID 123, the value is 10, otherwise 100". :kaohi:

    Otherwise you might want to start a new thread in Plugin Support.


    Drackus78 said:
    Hi all, I would like to know if there is a tutorial for the scrollable Windows MZ.
    Depends on exactly what you want from it. Seems like it would be worth starting a thread in Learning JavaScript for this? As a quick summary...

    The windows are defined in rmmz_windows.js and the scenes (which create, and assign handlers to, new instances of windows) are in rmmz_scenes.js. Window_Scrollable is a basis for creating display objects with scrollable content, but usually it's Window_Selectable or Window_Command that people want to build on. That way, you only really need to define the item/row/column count, selection handlers, and either drawItem or makeCommandList method, respectively: all the scroll/paint logic is done for you~


    Eternidade_1 said:
    Would my HTML code in JavaScript, created for my Blogger blog, work as a script in RPG Maker MV?
    JavaScript lets you manipulate HTML elements, and RPG Maker MV creates HTML games. Would your mystery JS work as-is in RPG Maker MV? You're in a much better position than anyone else to answer that question: try it and see!
  3. caethyril said:
    This is context-dependent. My first suggestions, without plugins, would be:
    • BattleManager._subject - battler who is currently acting (action phase).
    • BattleManager.actor() - actor who is currently inputting (input phase).

    That plugin seems to permit JS evals in its Speed field, so you could try something like:

    Speed: BattleManager._subject.isStateAffected(123) ? 10 : 100

    I.e. "if the acting battler has state ID 123, the value is 10, otherwise 100". :kaohi:

    Otherwise you might want to start a new thread in Plugin Support.



    Depends on exactly what you want from it. Seems like it would be worth starting a thread in Learning JavaScript for this? As a quick summary...

    The windows are defined in rmmz_windows.js and the scenes (which create, and assign handlers to, new instances of windows) are in rmmz_scenes.js. Window_Scrollable is a basis for creating display objects with scrollable content, but usually it's Window_Selectable or Window_Command that people want to build on. That way, you only really need to define the item/row/column count, selection handlers, and either drawItem or makeCommandList method, respectively: all the scroll/paint logic is done for you~



    JavaScript lets you manipulate HTML elements, and RPG Maker MV creates HTML games. Would your mystery JS work as-is in RPG Maker MV? You're in a much better position than anyone else to answer that question: try it and see!

    Thank you for your response, I've open a thread in the learning Javascript.
  4. How would one call the actor a particular piece of equipment is equipped to?
    I'm trying to create an accessory which has an effect that uses the wearer's current hp in a formula in the notes. Edit: I may have figured out a workaround, but this would still be useful to know.
  5. Rethy said:
    How would one call the actor a particular piece of equipment is equipped to?
    I'm trying to create an accessory which has an effect that uses the wearer's current hp in a formula in the notes. Edit: I may have figured out a workaround, but this would still be useful to know.

    $gameParty.members().some(actor => actor.hasArmor($dataArmors[1]))
    to check whether any actor has this piece of armour

    $gameParty.members().find(actor => actor.hasArmor($dataArmors[1])).hp
    to get this actor's HP
  6. Hopefully a quick one, using a state in MV with Yanfly States.

    It works exactly as I want it to (gives 5 HP at turn end to all allies), but I've tried numerous things to get a damage pop-up to also trigger on everyone, but it always seems to not actually show.
    Code:
    <Custom Turn End Effect>
    var cantorheal = 5;
    user.friendsUnit().aliveMembers().forEach(ally => ally.gainHp(cantorheal));
    user.friendsUnit().aliveMembers().startDamagePopup();
    user.friendsUnit().aliveMembers().clearResult();
    </Custom Turn End Effect>
    How do I get the popup to happen? (I've tried a few things in line 3, I know it's wrong)
  7. Social_Knight said:
    How do I get the popup to happen?
    you still need to forEach() on the other lines. youre only doing it on the gainHp
  8. Robro33 said:
    you still need to forEach() on the other lines. youre only doing it on the gainHp
    Could have sworn I tried that, but I think somehow I must have screwed it up (I think I didn't include the ally =>). It's fine now, thanks.
    Code:
    <Custom Turn End Effect>
    var cantorheal = 5;
    user.friendsUnit().aliveMembers().forEach(ally => ally.gainHp(cantorheal));
    user.friendsUnit().aliveMembers().forEach(ally => ally.startDamagePopup());
    user.friendsUnit().aliveMembers().forEach(ally => ally.clearResult());
    </Custom Turn End Effect>
  9. I am looking for help understanding why my javascript is not working as I expect. I have stripped the code down to the essential. It is supposed to allow you to select an item in battle through its own command and then log the item to console. It works to the point of selection, but then when the item is selected the code does not run the handler for the new window and instead runs the handler for the command window. It seems to me that the focus is never transferred to the new window, even though I am running .activate() on it. Is there an obvious error on my part? Is there a better place for me to look for help?

    JavaScript:
        const _Alias_Window_ActorCommand_prototype_makeCommandList = Window_ActorCommand.prototype.makeCommandList;
        Window_ActorCommand.prototype.makeCommandList = function() {
            if (this._actor) {
                this.addNewCommand();
            }
            _Alias_Window_ActorCommand_prototype_makeCommandList.call(this);
        };
    
        Window_ActorCommand.prototype.addNewCommand = function() {
            this.addCommand("New", "new");
        };
        
        const _Alias_Scene_Battle_prototype_createActorCommandWindow = Scene_Battle.prototype.createActorCommandWindow;
        Scene_Battle.prototype.createActorCommandWindow = function() {
            _Alias_Scene_Battle_prototype_createActorCommandWindow.call(this);
            this._actorCommandWindow.setHandler("new", this.commandNew.bind(this));
        };
    
        Scene_Battle.prototype.commandNew = function() {
            this._newWindow.refresh();
            this._newWindow.show();
            this._newWindow.activate();
            this._newWindow.select(0);
            this._statusWindow.hide();
            this._actorCommandWindow.hide();
            this._actorCommandWindow.deactivate();
        };
    
        const _Alias_Scene_Battle_prototype_createAllWindows = Scene_Battle.prototype.createAllWindows;
        Scene_Battle.prototype.createAllWindows = function() {
            _Alias_Scene_Battle_prototype_createAllWindows.call(this);
            this.createNewWindow();
        };
    
        Scene_Battle.prototype.createNewWindow = function() {
            const rect = this.itemWindowRect();
            const NewWindow = new Window_New(rect);
            NewWindow.setHelpWindow(this._helpWindow);
            NewWindow.setHandler("ok", this.onNewOk.bind(this));
            NewWindow.setHandler("cancel", this.onNewCancel.bind(this));
            this.addWindow(NewWindow);
            this._newWindow = NewWindow;
        };
    
        Scene_Battle.prototype.onNewOk = function() {
            const item = this._newWindow.item();
            console.log(item);
            this.onNewCancel.call(this);
        };
    
        Scene_Battle.prototype.onNewCancel = function() {
            this._newWindow.hide();
            this._newWindow.deactivate();
            this._statusWindow.show();
            this._actorCommandWindow.refresh();
            this._actorCommandWindow.show();
            this._actorCommandWindow.activate();
        };
    
        //-----------------------------------------------------------------------------
        // Window_New
        //
        // The window for selecting an item to use on the battle screen.
    
        function Window_New() {
            this.initialize(...arguments);
        }
    
        Window_New.prototype = Object.create(Window_ItemList.prototype);
        Window_New.prototype.constructor = Window_New;
    
        Window_New.prototype.initialize = function(rect) {
            Window_ItemList.prototype.initialize.call(this, rect);
            this.hide();
        };
    
        Window_New.prototype.includes = function(item) {
            return item;
        };
    
        Window_New.prototype.show = function() {
            this.selectLast();
            this.showHelpWindow();
            Window_ItemList.prototype.show.call(this);
        };
    
        Window_New.prototype.hide = function() {
            this.hideHelpWindow();
            Window_ItemList.prototype.hide.call(this);
        };
  10. @peetsnack Not 100% sure but wasn't that the case where the system activates your actor command window every frame. I think you need to modify this method to take into account your new window:

    Scene_Battle.prototype.isAnyInputWindowActive = function() {
    return (
    this._partyCommandWindow.active ||
    this._actorCommandWindow.active ||
    this._skillWindow.active ||
    this._itemWindow.active ||
    this._actorWindow.active ||
    this._enemyWindow.active
    );
    };

    EDIT: Or some other method. I'm pretty sure there was some annoying pathway that kept activating the actor command window.
  11. rpgLord69 said:
    @peetsnack Not 100% sure but wasn't that the case where the system activates your actor command window every frame. I think you need to modify this method to take into account your new window:

    Scene_Battle.prototype.isAnyInputWindowActive = function() {
    return (
    this._partyCommandWindow.active ||
    this._actorCommandWindow.active ||
    this._skillWindow.active ||
    this._itemWindow.active ||
    this._actorWindow.active ||
    this._enemyWindow.active
    );
    };

    EDIT: Or some other method. I'm pretty sure there was some annoying pathway that kept activating the actor command window.
    That was it. All I had to do was add the following:
    JavaScript:
    const _Alias_Scene_Battle_prototype_isAnyInputWindowActive = Scene_Battle.prototype.isAnyInputWindowActive;
        Scene_Battle.prototype.isAnyInputWindowActive = function() {
            return _Alias_Scene_Battle_prototype_isAnyInputWindowActive.call(this) || this._newWindow.active;
        };

    Thank you so much for the assistance. I have no idea how I could have figured that one out on my own.
  12. How would one call the skill id of the action currently being executed?

    I'm using Substitute Extend to have an actor intercept a specific skill.
  13. BattleManager._action.item().id

    But you might wanna make a check with something like this:
    const action = BattleManager._action;
    if (action && action.item() && action.isSkill() && action.item().id === X)
  14. rpgLord69 said:
    BattleManager._action.item().id

    But you might wanna make a check with something like this:
    const action = BattleManager._action;
    if (action && action.item() && action.isSkill() && action.item().id === X)
    This did the trick, thanks!
  15. Hi all, I don't know if this question have already been ask so sorry if I make you repeat.
    Ive come to see that changing an array base on another, change the original one and I'would like to know how I can work around so it change only the iteration.

    exemple
    JavaScript:
    let arrayObj = [{a:2,b:45},{a:57,b:265},{a:248,b:5}];
    console.log(arrayObj); //[{a:2,b:45},{a:18,b:265},{a:248,b:5}];
    let arrayObj2 = arrayObj;
    console.log(arrayObj2); //[{a:2,b:45},{a:18,b:265},{a:248,b:5}];
    arrayObj2[1].a = 18;

    For now the only solutions that I found are:

    Solutions temps
    JavaScript:
    // isolate
    
    let arrayObj = [{a:2,b:45},{a:57,b:265},{a:248,b:5}];
    console.log(arrayObj); //[{a:2,b:45},{a:57,b:265},{a:248,b:5}]
    let arrayObj2 = arrayObj;
    console.log(arrayObj2); //[{a:2,b:45},{a:57,b:265},{a:248,b:5}]
    let arrayObj3 = arrayObj2[0];
    console.log(arrayObj3); //{a:2,b:45}
    arrayObj3.a = 7;
    console.log(arrayObj3); //{a:7,b:45}
    
    // or mixing array
    
    let arrayObj = [{a:2,b:45},{a:57,b:265},{a:248,b:5}];
    console.log(arrayObj); // [{a:2,b:45},{a:57,b:265},{a:248,b:5}]
    let arrayObj2 = arrayObj;
    console.log(arrayObj2); // [{a:2,b:45},{a:57,b:265},{a:248,b:5}]
    let arrayObj3 = [];
    console.log(arrayObj3); // [{a:7,b:45},{a:5,b:265},{a:6,b:5}]
    let modifier = [7,5,6,2,9,4,1]
    for (let i = 0; i < arrayObj.length; i++) {
      arrayObj3[i] = {a: modifier[i], b:arrayObj2[i].b}
    }

    So if some less burdersome solutions exist I'll be glad to know.
  16. Drackus78 said:
    Hi all, I don't know if this question have already been ask so sorry if I make you repeat.
    Ive come to see that changing an array base on another, change the original one and I'would like to know how I can work around so it change only the iteration.

    exemple
    JavaScript:
    let arrayObj = [{a:2,b:45},{a:57,b:265},{a:248,b:5}];
    console.log(arrayObj); //[{a:2,b:45},{a:18,b:265},{a:248,b:5}];
    let arrayObj2 = arrayObj;
    console.log(arrayObj2); //[{a:2,b:45},{a:18,b:265},{a:248,b:5}];
    arrayObj2[1].a = 18;

    For now the only solutions that I found are:

    Solutions temps
    JavaScript:
    // isolate
    
    let arrayObj = [{a:2,b:45},{a:57,b:265},{a:248,b:5}];
    console.log(arrayObj); //[{a:2,b:45},{a:57,b:265},{a:248,b:5}]
    let arrayObj2 = arrayObj;
    console.log(arrayObj2); //[{a:2,b:45},{a:57,b:265},{a:248,b:5}]
    let arrayObj3 = arrayObj2[0];
    console.log(arrayObj3); //{a:2,b:45}
    arrayObj3.a = 7;
    console.log(arrayObj3); //{a:7,b:45}
    
    // or mixing array
    
    let arrayObj = [{a:2,b:45},{a:57,b:265},{a:248,b:5}];
    console.log(arrayObj); // [{a:2,b:45},{a:57,b:265},{a:248,b:5}]
    let arrayObj2 = arrayObj;
    console.log(arrayObj2); // [{a:2,b:45},{a:57,b:265},{a:248,b:5}]
    let arrayObj3 = [];
    console.log(arrayObj3); // [{a:7,b:45},{a:5,b:265},{a:6,b:5}]
    let modifier = [7,5,6,2,9,4,1]
    for (let i = 0; i < arrayObj.length; i++) {
      arrayObj3[i] = {a: modifier[i], b:arrayObj2[i].b}
    }

    So if some less burdersome solutions exist I'll be glad to know.
    The structuredClone method creates deep copies, so maybe give that a try.
    It'd look something like this:

    JavaScript:
    var arr1 = [{a: 0, b:0}];
    var arr2 = structuredClone(arr1);
    console.log(arr1, arr2); //[{a: 0, b:0}], [{a: 0, b:0}]
    arr2[0].a = 4;
    console.log(arr1, arr2); //[{a: 0, b:0}], [{a: 4, b:0}]
    EDIT: sorry, I forgot objects retain their original references when shallow copying. This works instead!
  17. StandardEnemy said:
    The structuredClone method creates deep copies, so maybe give that a try.
    It'd look something like this:

    JavaScript:
    var arr1 = [{a: 0, b:0}];
    var arr2 = structuredClone(arr1);
    console.log(arr1, arr2); //[{a: 0, b:0}], [{a: 0, b:0}]
    arr2[0].a = 4;
    console.log(arr1, arr2); //[{a: 0, b:0}], [{a: 4, b:0}]
    EDIT: sorry, I forgot objects retain their original references when shallow copying. This works instead!
    Thx a lot it's perfect, I didn't know this method.
  18. In MZ, how would I make items non-stackable? For instance, if the player has 2 potions it gets split into 2 separate potion items? I'm trying to do a limited inventory thing.
  19. Kind of hacking together several MV YEP tips and tricks here, but I've clearly missed something as it seems to be inoperative. Can someone diagnose it?

    This is a passive state that, at combat start, picks a random buff and applies it to a random party member:
    JavaScript:
    <Custom Battle Effect>
    // This is the number of turns the buffs and debuffs will last
    var turns = 4;
    // Create a pool for the parameters that can be changed
    var allowedParams = [];
    // Insert Param ID's you want to randomly add here:
    allowedParams.push(2, 4, 6, 7);
    // Make a copy of the pool
    var result = allowedParams.slice();
    
    // Initialize the parameter ID
    var paramId;
    // Loop through each of the copied pool's parameters
    while (result.length > 0) {
      // Get a randomly looped parameter
      paramId = result[Math.floor(Math.random() * result.length)];
      // Remove it from the copied pool
      result.splice(result.indexOf(paramId), 1);
      var members = [];
        // Loop through each of the target's alive allies.
        for (var i = 0; i < target.friendsUnit().aliveMembers().length; ++i) {
          // Set the potential variable to the current looped ally.
          var potential = target.friendsUnit().aliveMembers()[i];
          // If the ally doesn't exist, move onto the next.
          if (!potential) continue;
          // If the ally's HP is at zero (hence dead), move onto the next.
          if (potential.hp <= 0) continue;
          // Now that all checks have been cleared, put the potential ally into the members array.
          members.push(potential);
        }
        // Get a random member of the members array.
        var member = members[Math.floor(Math.random() * members.length)];
        // Check if the random member exists.
        if (member) {member.addBuff(paramId, turns); }
    break;
      }
    }
    </Custom Battle Effect>
    There's also probably a simpler way of doing this but this one made most sense to me.