JavaScript questions that don't deserve their own thread

In RMMZ I'm hoping to allow to counter both physical and magic attacks when the character is defending. The way I want it to work is that upon first hit that the affected unit receives (there are a lot of skills that hit multiple times) the defending unit will retaliate with the Counter skill (mainly to increase the counterer's TP but I do realize there are other methods). I have this put in the Defend state's Note are (I am using Visustella):
<JS Post-Damage as Target> if (this.isHpEffect()) { const skill = 5; const target = -2; user.forceAction(skill, target); } </JS Post-Damage as Target>
However it's not working as I hope as it causes the enemy that attacks defender to attack the defender continuously until they evade. Sadly my programming skills are very limited.
As far as I can tell user.forceAction(skill, target); should be altered to something else. Also, note that I do plan to add additional condition for activating the Counter skill, that is to be affected by a state (which AFAIK would be user.isStateAffected(stateID)).
I'm attempting to have a common event that will only remove states within a specific category...from the party.
Code:
$gameParty.members().forEach(actor => actor.removeStateCategoryAll("food"));
or whatever your category is called.

However it's not working as I hope as it causes the enemy that attacks defender to attack the defender continuously until they evade. Sadly my programming skills are very limited.
You appear to be reversing "user" and "target" inside of your notetag. You're using the damaged "As Target" notetag, but then you're telling the user to attack the target again, which will produce the loop you see.

If you swap that around and it still doesn't work the way you want, per the first post of this thread, plugin-specific questions should go elsewhere - you can make a post in Plugin Support, or Trihan has a thread dedicated to VisuStella notetags.
Code:
$gameParty.members().forEach(actor => actor.removeStateCategoryAll("food"));
or whatever your category is called.
Thank you, I really appreciate all the help I've gotten here ♥
Hello everyone, I use RPG Maker MV and I would like some help if possible, so thanks in advance to anyone who can help.

First, I know almost nothing about javascript, so my question may seem silly or stupid.

I'm making an event so that when a character "X" is in the group, while he is walking he makes a certain sound, for example, one of my characters is of the "Treant" race, and while he walks he makes a branch noise.

Therefore, I check if the character "X" is in position 1, 2 or 3 of the group (my group has a maximum limit of 3 characters) and if he is in any of these positions, either as a leader or not, the solution I found was temporarily set the conditional branch with a script command: $gamePlayer.isMoving()

Spoiler: Exemple
exemple.png

At first I got what I wanted, but I noticed that in reality this command is only for the group leader.

So if the character "X" is in the second or third position, when I put the leader to move in an event where the character "X" doesn't move (for example, with the plugin "SimpleFollowerControl", or in any other situation ), the branch noise keeps playing even though the character "X" is not walking.

Finally, my question is: Is there any script command where I can put a conditional branch so that the branch noise only occurs when the player ID "X" is moving, or something like that?

Obs.: I already use a plugin to make noise when walking through Regions ID, so what I'm trying to do is put movement noise depending on the characteristics of each character, and the plugins I checked do not offer this functionality.

So again, thanks in advance for any light on this matter.
Apparently I got what I wanted after researching some subjects here on the forum, in particular a post by Nolonar, regarding a member's question HERE.

For those wondering, the script command that worked was: $gamePlayer.followers().follower(0).isMoving()
$gamePlayer.followers().follower(1).isMoving()

However, despite working as intended, I still have some questions.

For example, by what Nolonar said in that post and "logic" (I think), if I have 3 characters, the command follower(0) would be for the leader, follower(1) for the second position, and follower(2) for the third position.

However, when calling the script command for the third position, the command with follower(2) does not work, having to also remain as follower(1) to work, as can be seen:


Spoiler: Exemple that is working
work.png

Spoiler: Exemple that doesn't work
dontwork.png

So, my question is, why does the follower(2) command don't work for the third position of the character but the follower(1) command does? Wouldn't the follower (1) command be just for the second position in the group and the follower (0) for the leader?

If anyone can clarify these doubts I would be grateful.
For example, by what Nolonar said in that post and "logic" (I think), if I have 3 characters, the command follower(0) would be for the leader, follower(1) for the second position, and follower(2) for the third position.
That's not quite right, because you're mixing some terms there. The leader is the first person who is actually being controlled by the player's input. That is, by definition, not a follower - the followers start behind them.

So in a typical 4-character party, you will have the leader then followers 0, 1, and 2.

If you only have 3 characters total, you only have 2 followers. You'd get the front character, the leader, with $gameParty.leader(), then you can use the code you got above for followers 0 and 1.

That's why you're getting an error when trying to look at follower 2 (and why the other conditionals could glitch, depending on your party formation).
Thank you very much for the feedback ATT_Turan, I already changed the command as per your explanation, everything is working perfectly now.
Can you make this state's notetag to check for the actor's position in the party and also if a switch is on? Thanks a lot.

<Custom Passive Condition>
if ($gameParty.members()[0] === user) {
condition = true;
} else {
condition = false;
}
</Custom Passive Condition>
Can you make this state's notetag to check for the actor's position in the party
What do you mean here? It's already looking to see if the user is member 0 (the party leader). What do you want it to do differently?

and also if a switch is on?
To ask two things in a conditional, you use boolean AND: &&
And from the script call list, the function to check a switch is $gameSwitches.value(X)

So your notetag would be:
Code:
<Custom Passive Condition>
condition = $gameParty.members()[0]==user && $gameSwitches.value(X);
</Custom Passive Condition>
where X is the ID of the switch (no leading zeros).
What do you mean here? It's already looking to see if the user is member 0 (the party leader). What do you want it to do differently?


To ask two things in a conditional, you use boolean AND: &&
And from the script call list, the function to check a switch is $gameSwitches.value(X)

So your notetag would be:
Code:
<Custom Passive Condition>
condition = $gameParty.members()[0]==user && $gameSwitches.value(X);
</Custom Passive Condition>
where X is the ID of the switch (no leading zeros).
Thanks a lot for the answer! Unfortunately, it seems that the conditions in Yanfly's Auto Passive States no longer work with switches. I tried your way (with and without the party members condition) and with the notetag the plugin itself provides (<Passive Condition: Switch x ON>), but nothing. The state is not in the party members as if the conditions are not met (and they are). I don't see what I'm doing wrong, that's why I think that maybe the plugin doesn't work that way anymore.
I tried your way (with and without the party members condition) and with the notetag the plugin itself provides (<Passive Condition: Switch x ON>), but nothing.
There's a bug in the plugin where the Passive Condition: Switch notetag doesn't work correctly. If you click into my thread in my signature, I provide a fix.

However, what I just typed above with the Custom Passive Condition should work. So if that's also not working, you need to make sure your conditions in your game actually are what you think they are.

If you need more help getting it to work, you should make a new thread in Plugin Support. Make sure to provide screenshots of your setup.
Hi,
i try Statpolygon to add on Visustella Statusmenu.
It´s working but i missed the Text "atk", def" etc.

Code:
//Polygon
sx = quarterWidth;
sy = rect.y + lineHeight * 5;
this.drawItemDarkRect(sx, sy, quarterWidth, lineHeight * 9);
this.contents.SPolyDrawStatPolygon(this._actor);
this.drawText(TextManager.param(stats));

when i try this.drawText(TextManager.param(stats)); it´s have an error:
ReferenceError
stats is not defined

what it´s my mistake 😳?
i try Statpolygon to add on Visustella Statusmenu.
Per the first post in this thread, it's not for support with specific plugins. Those questions should go in that plugin's thread or you make a new thread in Plugin Support.

However, I'll give you one thing that I see off the top of my head: the Stat Polygon is for RPG Maker MV, and VisuStella and your profile indicate you're using MZ. You should not presume that an MV plugin will be compatible with MZ.

when i try this.drawText(TextManager.param(stats)); it´s have an error:
ReferenceError
stats is not defined

what it´s my mistake 😳?
Exactly what it said, that there's no variable called "stats". When you post your question again, include the entire function you're trying to make.
I´m sorry.
I have found a another way, but thanks 🙂
Is there a script/plugin that will have an event follow the exact path the player took?
1. While the player is moving, an array logs the player's position every few frames and holds the past 10 or so positions.
2. Check if the following event is currently at the player's position, and if not move towards the nearest position the player was at. Then move to the next direction/position on the array.
Is there a script/plugin that will have an event follow the exact path the player took?
Yanfly's Move Route plugin has a Move To Coordinates command, along with Move Toward Location and Move Toward Player.

You can do what you're asking with that.
How would I modify this script:
Code:
var m = $gameMap.mapId();
for (var s = 1; s < $dataMap.events.length; s++){
$gameSelfSwitches.setValue([m, s, 'A'], false);
$gameSelfSwitches.setValue([m, s, 'B'], false);
$gameSelfSwitches.setValue([m, s, 'C'], false);
$gameSelfSwitches.setValue([m, s, 'D'], false);}

So that it only affects a specific range of event ID's instead of all events on the map?
(in my case, events 30 - 58)
How would I modify this script:
Code:
var m = $gameMap.mapId();
for (var s = 1; s < $dataMap.events.length; s++){
$gameSelfSwitches.setValue([m, s, 'A'], false);
$gameSelfSwitches.setValue([m, s, 'B'], false);
$gameSelfSwitches.setValue([m, s, 'C'], false);
$gameSelfSwitches.setValue([m, s, 'D'], false);}

So that it only affects a specific range of event ID's instead of all events on the map?
(in my case, events 30 - 58)
You need to add an IF statement to check against those event IDs.


JavaScript:
var m = $gameMap.mapId();
for (var s = 1; s < $dataMap.events.length; s++) {
if ($dataMap.events[s].id >= 30 && $dataMap.events[s].id <= 58)
    {do this;}
}

Also, since S is going to be the same as what the ID is, you don't even need to compare IDs, this will also work:
JavaScript:
var m = $gameMap.mapId();
for (var s = 1; s < $dataMap.events.length; s++) {
if (s >= 30 && s <= 58)
    {do this;}
}

It's just (in my opinion) better to check against the actual eventId since it'll lead to less errors, and if one appears down the line you'll know why. Also, if you do compare against eventId, when you come back to look at this script later you'll know exactly what it's doing, because $gameMap.events.id is much easier to understand than just 's'.
I'm getting a script call error with this implemented. I'm sort of script-dumb so I am not sure if I am just overlooking something obvious - for example, I adjusted the formatting so it's easier for me to read, maybe I caused a problem when I did this? Can I get a sanity check?
Code:
var m = $gameMap.mapId();
for (var s = 1; < $dataMap.events.length; s++)
{
 if (s >= 30 && s <= 58)
 {
 $gameSelfSwitches.setValue([m, s, 'A'], false);
 $gameSelfSwitches.setValue([m, s, 'B'], false);
 $gameSelfSwitches.setValue([m, s, 'C'], false);
 $gameSelfSwitches.setValue([m, s, 'D'], false);
 }
}

edit:
Screen shot
error.png
Spoiler
I'm getting a script call error with this implemented. I'm sort of script-dumb so I am not sure if I am just overlooking something obvious - for example, I adjusted the formatting so it's easier for me to read, maybe I caused a problem when I did this? Can I get a sanity check?
Code:
var m = $gameMap.mapId();
for (var s = 1; < $dataMap.events.length; s++)
{
 if (s >= 30 && s <= 58)
 {
 $gameSelfSwitches.setValue([m, s, 'A'], false);
 $gameSelfSwitches.setValue([m, s, 'B'], false);
 $gameSelfSwitches.setValue([m, s, 'C'], false);
 $gameSelfSwitches.setValue([m, s, 'D'], false);
 }
}

edit:
Screen shot
View attachment 252918
Ahh that was caused because I forgot to put the 's' in the for(loop). I edited my original post.

Original thread: https://forums.rpgmakerweb.com/threads/javascript-questions-that-dont-deserve-their-own-thread.46341/