JavaScript questions that don't deserve their own thread

Vis_Mage

Wisp Charmer
Veteran
Joined
Jul 28, 2013
Messages
709
Reaction score
230
First Language
English
Primarily Uses
RMMV
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.
 

Kuro DCupu

Trust me, I'm a veteran RMer
Veteran
Joined
Jul 6, 2014
Messages
525
Reaction score
1,528
First Language
Indonesia
Primarily Uses
RMMV
I almost forgot there is this kind of thread

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.
 
Last edited:

Vis_Mage

Wisp Charmer
Veteran
Joined
Jul 28, 2013
Messages
709
Reaction score
230
First Language
English
Primarily Uses
RMMV
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)?

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);
 

Kuro DCupu

Trust me, I'm a veteran RMer
Veteran
Joined
Jul 6, 2014
Messages
525
Reaction score
1,528
First Language
Indonesia
Primarily Uses
RMMV
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.
 

Vis_Mage

Wisp Charmer
Veteran
Joined
Jul 28, 2013
Messages
709
Reaction score
230
First Language
English
Primarily Uses
RMMV
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.
 

WCouillard

Veteran
Veteran
Joined
Nov 24, 2013
Messages
77
Reaction score
21
First Language
English
Primarily Uses
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.
 
Last edited:

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,231
Reaction score
1,195
First Language
English
Primarily Uses
RMMV
@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).
 

Sirius270

Veteran
Veteran
Joined
May 2, 2020
Messages
60
Reaction score
16
First Language
English
Primarily Uses
RMMV
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!
 

WCouillard

Veteran
Veteran
Joined
Nov 24, 2013
Messages
77
Reaction score
21
First Language
English
Primarily Uses
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');
};
 

raffle

Veteran
Veteran
Joined
Oct 25, 2020
Messages
70
Reaction score
14
First Language
English
Primarily Uses
RMMV
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:
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?
 

raffle

Veteran
Veteran
Joined
Oct 25, 2020
Messages
70
Reaction score
14
First Language
English
Primarily Uses
RMMV
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:
 
Joined
Jul 8, 2021
Messages
8
Reaction score
1
First Language
English
Primarily Uses
RMMV
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.
 
Last edited:

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,231
Reaction score
1,195
First Language
English
Primarily Uses
RMMV
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.
 

Boonty

Veteran
Veteran
Joined
Oct 10, 2018
Messages
135
Reaction score
49
First Language
French
Primarily Uses
RMMV
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.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,231
Reaction score
1,195
First Language
English
Primarily Uses
RMMV
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).
 

Wisshy

Villager
Member
Joined
Jan 16, 2019
Messages
10
Reaction score
0
First Language
Português
Primarily Uses
RMMV
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?
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,231
Reaction score
1,195
First Language
English
Primarily Uses
RMMV
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.
 

Boonty

Veteran
Veteran
Joined
Oct 10, 2018
Messages
135
Reaction score
49
First Language
French
Primarily Uses
RMMV
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.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,231
Reaction score
1,195
First Language
English
Primarily Uses
RMMV
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.
 

Latest Threads

Latest Profile Posts

Even though I spent 100's of dollars on my game already. I think I might just have to give it away for free. Since I haven't heard back from people if I could use some of their graphics. Even from a global mod here. Maybe I can make a donation thing.
you know, some days you get resentful that game dev is even considered a "fun job" and other days it's like, welp, time to roll up my sleeves and code these molotov cocktails
If you suck at playing trumpets, that is probably why.
Been sick with a stomach virus for seven days now. Not going to work tomorrow because I'm still contagious according to my doctor.
Much as I love my job, I really hate playing "office politics". It would be nice if I didn't have to pretend to be someone else all day long.

Forum statistics

Threads
115,959
Messages
1,094,394
Members
151,228
Latest member
Hokorrii
Top