JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 93 of 171 View original ↗
  1. I almost forgot there is this kind of thread

    Vis_Mage said:
    Could someone please help me out with a script call for MV?

    What I'm hoping to do is make a script call that will forcibly use an item (id equal to a variable), on an actor (ID also equal to a variable). This script call happens out of battle, by the way.

    Forcibly using an item on a certain actor is quite tricky...
    It will be easier if those items are tied to common events since you can use the common event directly.
    Even if it's just forcibly using it, a normal scope item will bring you to window actor selection to choose the target, which I believe it's not what you want.
    There is no whole method of using an item on a certain user if it's not through battle or menu, unless you make it yourself.
    The rawest method would be to read each condition and property of the item, then apply those effects to the actor manually.

    If it's me, I will brute force my way by making it "looks like" the actor is using the item.
    Making a whole event list of the item is much simpler than scripting it.
  2. Kuro DCupu said:
    If it's me, I will brute force my way by making it "looks like" the actor is using the item.
    Making a whole event list of the item is much simpler than scripting it.
    Ah, in most cases, you're probably right. The main reason I'm trying to go about things in the roundabout way I am is because I'm trying to have certain notetags from plugins apply to the target.

    With a bit more searching, I was able to find something very close to what I'm looking for. In this thread, there's a script call that can force use an item, but the target is determined on the party position. Would this be able to be edited to instead target a specified actor instead (even if they are not in the party)?
    Force/Simulate Item Effect/Use (on map/in main menu)
    Code:
    var itemId = 30, memberId = 0;
    (function(v,i,t,a,c,u) {
    if (i = $dataItems[+v || 0]) {
    u = $gameParty.members()[memberId];
    a = new Game_Action(u);a.setItemObject(i);
    t = i.scope === 7 ? [u] : a.makeTargets();
    for (n in t) c = c || a.testApply(t[n]);
    if (u.canUse(i) && (i.scope === 0 || c)) {u.useItem(i);
      for (n in t) for (var m = a.numRepeats(); m--;) if ($gameParty.inBattle() && i.animationId) {t[n].startAnimation(i.animationId);} a.apply(t[n]);
      a.applyGlobal();
    }}})(itemId); $gameParty.loseItem($dataItems[itemId], 1);
  3. Vis_Mage said:
    Code:
    var itemId = 30, memberId = 0;
    (function(v,i,t,a,c,u) {
    if (i = $dataItems[+v || 0]) {
    u = $gameParty.members()[memberId];
    a = new Game_Action(u);a.setItemObject(i);
    t = i.scope === 7 ? [u] : a.makeTargets();
    for (n in t) c = c || a.testApply(t[n]);
    if (u.canUse(i) && (i.scope === 0 || c)) {u.useItem(i);
      for (n in t) for (var m = a.numRepeats(); m--;) if ($gameParty.inBattle() && i.animationId) {t[n].startAnimation(i.animationId);} a.apply(t[n]);
      a.applyGlobal();
    }}})(itemId); $gameParty.loseItem($dataItems[itemId], 1);

    o_O I never expected of using game action...
    it's trying to simulate the use of an item by doing what I thought, which is manually read each condition and property and apply it to the actor using raw method.
    I checked the thread, and it seems TS want to remove the item no matter if it's consumable or not.
    It's also trying to play animation for inside battle instead of on map, which is why the animation is not working.

    aaand so I fixed it, and make it to target actor ID instead of member ID by using variable ID for your need.
    Here:
    Code:
    var itemId = $gameVariables.value(ID), actorId = $gameVariables.value(ID);
    (function(v,i,t,a,c,u) {
    if (i = $dataItems[+v || 0]) {
    u = $gameParty.members()[$gameActors.actor(actorId).index()];
    a = new Game_Action(u); a.setItemObject(i);
    t = i.scope === 7 ? [u] : a.makeTargets();
    for (n in t) c = c || a.testApply(t[n]);
    if (u.canUse(i) && (i.scope === 0 || c)) { u.useItem(i);
      $gamePlayer.requestAnimation(i.animationId);
      a.apply(t[n]); a.applyGlobal();
    }}})(itemId);
    Don't forget to change the variable ID.
    It works on normal item.
    It will throw an error if the actor ID is not present in your party (currently I'm busy, no time to fix and check on that).

    Keep in mind that I'm just copying the work.
    There are parts I don't get and just leave it the way it is.
    I don't know if it can read notetags or not.
  4. Kuro DCupu said:
    Keep in mind that I'm just copying the work.
    There are parts I don't get and just leave it the way it is.
    I don't know if it can read notetags or not.
    Thank you very much! It seems to be working great, so long as I make sure the actor is in the party.

    Happy to say that it does indeed apply the effects of notetags on the item as well, which is a big relief.
  5. I am hoping to change how the Action Times+ trait functions.

    I simply want it to grant an extra action for EACH time the Action Times+ is added to the traits on an enemy, etc.

    So, if the enemy has...

    Action Times+ : 100%
    Action Times+ : 1%
    Action Times+: 52%

    Then, I still want it to grant them three extra actions without fail. If it's easier to just require 100% each time, that's fine too.

    JavaScript:
    Game_Battler.prototype.makeActionTimes = function() {
        return this.actionPlusSet().reduce(function(r, p) {
            return Math.random() < p ? r + 1 : r;
        }, 1);
    };

    This is where I assume this change would take place, I am just not fully understanding what is making it do what it does, which is grant a diminishing return on the trait.

    EDIT: It seems as though this code below works fine for what I was asking. Onto a new problem...

    JavaScript:
    Game_Battler.prototype.makeActionTimes = function() {
        return this.actionPlusSet().reduce(function(r, p) {
            return 0 < p ? r + 1 : r;
        }, 1);
    };

    So now that I have an enemy that has x amount of actions, I want certain ones to only be used once during the turn out of those x actions. I've set a skill that requires that a switch be ON. I set this switch to ON before the battle begins. Using that skill turns that switch OFF using an Action Sequence in Yanfly's plugin, making it so he should not use it again. He still uses this same move for every single action in the turn because it has the highest priority (9).

    I assume it's because the condition to use the skill was fulfilled at the start of the turn, and therefore ignores the condition on subsequent actions. However, Yanfly's BattleAICore should allow for dynamic actions on the fly (which is already set to true). I'll go over the notetags used in every part of this.

    The enemy has the notetag:
    JavaScript:
    <AI Level: 100>

    The skill has the following action sequence:
    JavaScript:
    <setup action>
    change switch 102: off
    clear battle log
    display action
    face user: targets
    animation 880: user
    wait for animation
    </setup action>
    <target action>
    clear battle log
    action animation: target
    wait for animation
    action effect: targets
    </target action>
    <finish action>
    perform finish
    face user: targets
    face targets: user
    </finish action>

    Lastly, the enemy's skills list has the above skill set to be used only when Switch 102 is ON (it is turned on before the battle begins, remember). The action sequence of the skill itself should be turning the switch OFF immediately, but every extra action afterwards is still this same skill.

    So, what I'm looking for now is a way to make enemies re-evaluate what they can use out of their list of actions before using EACH action, and select one that has its condition still fulfilled.
  6. @WCouillard - your questions (due both to the number of them and their complexity) definitely deserve their own thread. If you don't want to copy over your entire post, you could ask a mod if they can split it off, but you'll get more attention and help that way (especially since you're asking not just basic JavaScript questions, but about modding/writing an extension for an existing plugin).
  7. Hello! I'm looking for script/a plug-in that will not show 0 damage for certain skills (the skills that will always do 0 damage, essentially). I have skills that I use the battle formulas to add variables from use and this requires them to punch out a number (in this case, 0).
    Thanks in advance!
  8. I need to alter this so characters never use skill ID 1 or 2 when autobattling
    I also need to alter this so characters always use skills with the skill type ID 2 when autobattling

    Kinda stuck on where to even begin on this one.

    JavaScript:
    Game_Actor.prototype.makeActionList = function() {
        var list = [];
        var action = new Game_Action(this);
        action.setAttack();
        list.push(action);
        this.usableSkills().forEach(function(skill) {
            action = new Game_Action(this);
            action.setSkill(skill.id);
            list.push(action);
        }, this);
        return list;
    };
    
    Game_Actor.prototype.makeAutoBattleActions = function() {
        for (var i = 0; i < this.numActions(); i++) {
            var list = this.makeActionList();
            var maxValue = Number.MIN_VALUE;
            for (var j = 0; j < list.length; j++) {
                var value = list[j].evaluate();
                if (value > maxValue) {
                    maxValue = value;
                    this.setAction(i, list[j]);
                }
            }
        }
        this.setActionState('waiting');
    };
  9. Hey! I followed a tutorial which I thought was for MV but it was MZ instead. Everything works identically, not issues at all except for the last part of the event that has a script call $dataMap.note.includes(“<no camping>”) which does not work at all, I decided to make a separate testing event to see if it would recognize what was written in the map's notetag and it simply doesn't:
    images
    AwtXxps.png
    BwqCfvd.png

    I go to that map and activate the event with my action button and all i get is the not working text :(
    Is the syntax different for MV or is there a totally different script call?
  10. raffle said:
    Is the syntax different for MV or is there a totally different script call?
    Yes. $dataMap.meta["test1"]
  11. ATT_Turan said:
    Yes. $dataMap.meta["test1"]
    That was it, thank you so much! It's the second time you've helped me with script calls this week, you're a total lifesaver :kaojoy:
  12. I am having an unusual issue with one of my skills and a couple of other skills similar to it. The skill deals damage to one target, then applies a state to all allies that lasts for the remainder of the turn. To that end, the skill uses "1 Enemy" as its scope and applies the ally state through script. The code is as follows (I'm using Yanfly's Skill Core):

    JavaScript:
    <After Eval>
    var group = user.friendsUnit().aliveMembers();
        for (var i = 0; i < group.length; ++i) {
          var member = group[i];
            member.addState(81);
    }
    </After Eval>

    The state applies as expected unless I use the skill again on the next turn, immediately after the state elapses. If this happens, the state does not apply to anybody. On the turn after this, if the skill is used again, the state applies as normal.

    The issue has something to do with the Turn End auto-removal timing - the issue does not arise when using Action End, and as far as I can tell the only time this happens is when attempting to apply the same state using JS the turn after the initial state ends. Changing the note tags has not helped. I'm curious why this is happening and am in search of a solution.
  13. LittleMisterFrosty said:
    The state applies as expected unless I use the skill again on the next turn, immediately after the state elapses. If this happens, the state does not apply to anybody. On the turn after this, if the skill is used again, the state applies as normal.
    What are the settings on your state? If I understand correctly, states don't get removed at turn end until their counter is at 0 - that means the engine doesn't natively support the ability to have states that only last for the turn they're applied, as the minimum value you can enter for the duration is 1 (think of it as the number of full turns).

    So for this to work, you'd have to use note tags or a line of code in your After Eval to make the duration of the state start at 0.
  14. Hey everyone,

    I would like to add a signature move at my water golem boss.

    The twist is that the damage of this move is increased by the number of the allies and foes affected by waterish states. I identified the waterish stats with Yanfly State Categories as "Aqua".

    In the notetag of the signature move skills I added this line


    JavaScript:
    <Before Eval>
    value *=1+target.getStateCategoryAffectedCount('Aqua')+user.getStateCategoryAffectedCount('Aqua')+target.opponentsUnit().aliveMembers().getStateCategoryAffectedCount('Aqua')+user.opponentsUnit().aliveMembers().getStateCategoryAffectedCount('Aqua');
    </Before Eval>

    And I have no amplification.

    What did I miss ?

    Thanks for your help.
  15. Boonty said:
    the damage of this move is increased by the number of the allies and foes affected by waterish states. I identified the waterish stats with Yanfly State Categories as "Aqua"...
    Code:
    target.opponentsUnit().aliveMembers().getStateCategoryAffectedCount('Aqua')
    user.opponentsUnit().aliveMembers().getStateCategoryAffectedCount('Aqua');
    In these two statements you're taking a function that's a member of a Game_Actor (or Game_Battler or whatever, I haven't looked in the plugin) and you're trying to call it from an array. If you look in your console, you should be seeing error messages about that function being not defined.

    Member functions of a class can only be called from specific instances of that class (such as user.opponentsUnit().aliveMembers()[0]). Arrays can only call specific properties that are associated with arrays, such as length, some, etc. I wouldn't be surprised if that's nullifying the entire formula you typed out.

    You can achieve what you want through an inline arrow function.

    Edit: Also, the logic of your math seems wonky to me. You're adding the states on the caster, the states on the target, then the states on the entire gameParty which will include the target again, then the states on the entire gameTroop which will include the states on the caster again (and you're doing those in an unnecessarily convoluted way).
  16. Guys, so I want to make the "Attack" option in the Battle Menu to open that window where I can choose the ability instead of just attacking. I've looked at the Windows Js file but I couldn't make it work. Can I just do that without using plugin?
  17. Wisshy said:
    I want to make the "Attack" option in the Battle Menu to open that window where I can choose the ability instead of just attacking.
    You could try finding the command list and removing Attack from it, then rename your skill type to Attack. A few people have made plugins to customize the command list and what happens when you attack, but that's the only way I can think to make it open a window to further select a skill.
  18. ATT_Turan said:
    In these two statements you're taking a function that's a member of a Game_Actor (or Game_Battler or whatever, I haven't looked in the plugin) and you're trying to call it from an array. If you look in your console, you should be seeing error messages about that function being not defined.

    Member functions of a class can only be called from specific instances of that class (such as user.opponentsUnit().aliveMembers()[0]). Arrays can only call specific properties that are associated with arrays, such as length, some, etc. I wouldn't be surprised if that's nullifying the entire formula you typed out.

    You can achieve what you want through an inline arrow function.

    Edit: Also, the logic of your math seems wonky to me. You're adding the states on the caster, the states on the target, then the states on the entire gameParty which will include the target again, then the states on the entire gameTroop which will include the states on the caster again (and you're doing those in an unnecessarily convoluted way).
    Thanks a lot.

    I am kind of a noob in this. Regarding to your edit, indeed, the caster and the target will be counted twice which is incorrect.

    What are you meaning by inline arrow function?

    EDIT : do you mean something with for and if? I guess I can make this. I will try something.
  19. Boonty said:
    What are you meaning by inline arrow function?

    do you mean something with for and if?
    No - what purpose would there be to any ifs? I meant an arrow function.

    So, in your case:
    Code:
    <Before Eval>
    let aquas=0;
    
    $gameTroop.aliveMembers().forEach(member => aquas+=member.getStateCategoryAffectedCount('Aqua'));
    $gameParty.aliveMembers().forEach(member => aquas+=member.getStateCategoryAffectedCount('Aqua'));
    
    value*=1+aquas;
    </Before Eval>

    I haven't tested it, as I'm not using the state categories, but I think that should do what you want.
  20. ATT_Turan said:
    What are the settings on your state? If I understand correctly, states don't get removed at turn end until their counter is at 0 - that means the engine doesn't natively support the ability to have states that only last for the turn they're applied, as the minimum value you can enter for the duration is 1 (think of it as the number of full turns).

    So for this to work, you'd have to use note tags or a line of code in your After Eval to make the duration of the state start at 0.

    I tried adding
    JavaScript:
    member._stateTurns[81] = 0;
    to the After Eval. The state now disappears if an actor is attacked (not 100% what I'm looking for but that's not really a problem), and that allows me to reapply the state to that actor by reusing the skill on the next turn. However, reusing the skill still won't apply the state to any other actors that were not attacked, as if the state is not properly refreshing like it does when an actor gets attacked (it does also apply to the actor that used/is using the skill, which I guess is because by that point there's been one whole turn since the initial usage of the skill).

    These are the state's settings; they're fairly simple:
    Spoiler
    sowing.png

    Turning off the Turn End auto-removal causes the state to not be removed at all, even though the addition to the After Eval sets the turns to zero (I assume that it doesn't check turn count if there is no auto-removal parameter). Forcing a removal through e.g. user.removeState in the state's note field is not effective.

    Sorry if I'm overcomplicating this but I am stumped.