JavaScript questions that don't deserve their own thread

CHKNRAVE

Surprisingly not sponsored by Yanfly.
Veteran
Joined
May 11, 2020
Messages
127
Reaction score
69
First Language
French
Primarily Uses
RMMV
I think that's definitely not a question that would get you a short answer, try asking this in JS Plugin Requests.
 

CHKNRAVE

Surprisingly not sponsored by Yanfly.
Veteran
Joined
May 11, 2020
Messages
127
Reaction score
69
First Language
French
Primarily Uses
RMMV
Hi, everybody.

Is there a way to change the target of a skill in a Custom Select / React Effect? I'm trying to make a skill where the actor who gave a state is taking damage for the wearer.
An alternate solution I'll take would be for the damage to be nullified (with a "missed" result on the target) and the damage being applied to origin instead.

Thanks in advance!
 

zelanius

Everyman
Veteran
Joined
Apr 29, 2020
Messages
50
Reaction score
4
First Language
English
Primarily Uses
RMMV
Hi, everybody.

Is there a way to change the target of a skill in a Custom Select / React Effect? I'm trying to make a skill where the actor who gave a state is taking damage for the wearer.
An alternate solution I'll take would be for the damage to be nullified (with a "missed" result on the target) and the damage being applied to origin instead.

Thanks in advance!
Are you looking for this?
 

CHKNRAVE

Surprisingly not sponsored by Yanfly.
Veteran
Joined
May 11, 2020
Messages
127
Reaction score
69
First Language
French
Primarily Uses
RMMV
Are you looking for this?
That's the right effect, except that it's an active ability which applies the state to a single ally, for a set number of turns. So here's what I came up with, and now it works:
JavaScript:
<Custom Apply Effect>
if(target===origin) {
  target.result().missed = true;
  target.removeState(20); //Immediately removed if used on one's self
}
origin.addState(5); //Another unrelated state given to the user
</Custom Apply Effect>
<Custom React Effect>
if(origin.isDead()) {
  target.removeState(20); //Removed if the protector died since then
} else {
  if((user.isActor()!==target.isActor())&&(value>0)) {
    origin.gainHp(-value);
    value = 0;
    origin.startDamagePopup();
    if (origin.isDead()) {
      origin.performCollapse();
    }
    origin.clearResult();
  }
}
</Custom React Effect>
Now I just need to make the defensive stats work which I should handle, but how do I replace the 0 damage pop-up on the original target by a Miss result?
Edit: Nevermind about that part I thought I could handle, somehow the damage transfer is cancelled when I add this
JavaScript:
if(this.isPhysical()) {
  value \= target.pdr;
  value *= origin.pdr;
}
right before the part that inflicts damage to the state's sender. Now I'm also stumped as to how I'm going to fix this.
2nd edit: It's weird as hell. This redirects:
JavaScript:
<Custom Apply Effect>
if(target===origin) {
  target.result().missed = true;
  target.removeState(20);
}
origin.addState(5);
target.setStateCounter(20, target.pdr);
<Custom React Effect>
if(origin.isDead()) {
  target.removeState(20);
} else {
  if((user.isActor()!==target.isActor())&&(value>0)) {
    var dmg = value;
    origin.gainHp(-dmg);
    value = 0;
    origin.startDamagePopup();
    if (origin.isDead()) {
      origin.performCollapse();
    }
    origin.clearResult();
  }
}
</Custom React Effect>
but this cancels everything out.
JavaScript:
...
    var dmg = value;
    dmg \= target.pdr;
    origin.gainHp(-dmg);
...
 
Last edited:

zelanius

Everyman
Veteran
Joined
Apr 29, 2020
Messages
50
Reaction score
4
First Language
English
Primarily Uses
RMMV
That's the right effect, except that it's an active ability which applies the state to a single ally, for a set number of turns. So here's what I came up with, and now it works:
JavaScript:
<Custom Apply Effect>
if(target===origin) {
  target.result().missed = true;
  target.removeState(20); //Immediately removed if used on one's self
}
origin.addState(5); //Another unrelated state given to the user
</Custom Apply Effect>
<Custom React Effect>
if(origin.isDead()) {
  target.removeState(20); //Removed if the protector died since then
} else {
  if((user.isActor()!==target.isActor())&&(value>0)) {
    origin.gainHp(-value);
    value = 0;
    origin.startDamagePopup();
    if (origin.isDead()) {
      origin.performCollapse();
    }
    origin.clearResult();
  }
}
</Custom React Effect>
Now I just need to make the defensive stats work which I should handle, but how do I replace the 0 damage pop-up on the original target by a Miss result?
Edit: Nevermind about that part I thought I could handle, somehow the damage transfer is cancelled when I add this
JavaScript:
if(this.isPhysical()) {
  value \= target.pdr;
  value *= origin.pdr;
}
right before the part that inflicts damage to the state's sender. Now I'm also stumped as to how I'm going to fix this.
2nd edit: It's weird as hell. This redirects:
JavaScript:
<Custom Apply Effect>
if(target===origin) {
  target.result().missed = true;
  target.removeState(20);
}
origin.addState(5);
target.setStateCounter(20, target.pdr);
<Custom React Effect>
if(origin.isDead()) {
  target.removeState(20);
} else {
  if((user.isActor()!==target.isActor())&&(value>0)) {
    var dmg = value;
    origin.gainHp(-dmg);
    value = 0;
    origin.startDamagePopup();
    if (origin.isDead()) {
      origin.performCollapse();
    }
    origin.clearResult();
  }
}
</Custom React Effect>
but this cancels everything out.
JavaScript:
...
    var dmg = value;
    dmg \= target.pdr;
    origin.gainHp(-dmg);
...
Why not just use a notetag to set the original effect as a passive state on an the actor or class you wish to apply the "cover" effect on, instead of applying it via a skill? This way, the state will always be on, instead of being an active skill.
 

kiriseo

Veteran
Veteran
Joined
Oct 27, 2015
Messages
245
Reaction score
82
First Language
German
but this cancels everything out.
JavaScript:
...
    var dmg = value;
    dmg \= target.pdr;
    origin.gainHp(-dmg);
...
is this copied from your project?
If so, try it with a normal slash ("/") instead of a backslash ("\") like:
Code:
dmg /= target.pdr
 

CHKNRAVE

Surprisingly not sponsored by Yanfly.
Veteran
Joined
May 11, 2020
Messages
127
Reaction score
69
First Language
French
Primarily Uses
RMMV
Why not just use a notetag to set the original effect as a passive state on an the actor or class you wish to apply the "cover" effect on, instead of applying it via a skill? This way, the state will always be on, instead of being an active skill.
Because I want this protection to have a cost, to be an action during the character's turn, and most importantly to have one target. I really mean this protection to be a state given through a skill.
is this copied from your project?
If so, try it with a normal slash ("/") instead of a backslash ("\") like:
Code:
dmg /= target.pdr
Oh, that's... Quite a mistake. A few fixes and the reattribution issue is solved:
JavaScript:
<Custom Apply Effect>
if(target===origin) {
  target.result().missed = true;
  target.removeState(20);
}
origin.addState(5);
</Custom Apply Effect>

<Custom React Effect>
if(origin.isDead()) {
  target.removeState(20);
} else {
  if((user.isActor()!==target.isActor())&&(value>0)) {
    var dmg = value;
    if(this.isPhysical()) {
      dmg /= target.pdr;
      dmg *= origin.pdr;
      dmg = Math.floor(dmg);
    }
    if(this.isMagical()) {
      dmg /= target.mdr;
      dmg *= origin.mdr;
      dmg = Math.floor(dmg);
    }
    origin.gainHp(-dmg);
    value = 0;
    origin.startDamagePopup();
    if (origin.isDead()) {
      origin.performCollapse();
    }
    origin.clearResult();
  }
}
</Custom React Effect>
Now is there a way to remove the 0 damage pop-up on the target? Maybe replace it with a "Miss" one?
 
Last edited:

Essention

Essential
Member
Joined
Oct 6, 2020
Messages
14
Reaction score
19
First Language
English
Primarily Uses
RMMV
Hello! I just want to ask about something related to SRD's Summon Core plugin. Is there any method of making the summons function similar to how everything works in a game like Persona? Say you have a magic skill in your party member's list but you want it so that the given party member summons an actor and the actor does the skill you chose before immediately ending the summon. Would there need to be a plugin extension made for something like this if there aren't any known methods? I could try but I have little knowledge in something like JavaScript.
 

Nate_Tillern

Villager
Member
Joined
Apr 14, 2019
Messages
11
Reaction score
0
First Language
English
Primarily Uses
RMMV
Hi, I tried the <Custom Apply Effect> and then <Custom Remove Effect>, but the problem is, the maths needed got a bit too complicated (mostly I was using Math.round() function, so it always returns an integer, and then I added that value in Custom Apply Effect, but when I do the same for Custom Remove Effect, the amount to remove had to be recalculated, and was calculated on the higher user mat, which caused the removal to be higher than the added amount. Theoretically, you could create variables to store the original mat, but if you have a big cast of actors, you would need 1 variable for each (including any "guest" characters).

For the vectors you mentioned, you just need the ID of the skills or type in the database as an integer, so 0001 would be just 1, 0020 would be just 20, so on and so forth.
Thank you again for the insight! I've been messing around on my own the past couple of days, getting successful code for some states. There's something I've been trying to do in the notetags that I was wondering if you knew the proper syntax for. I'd like to identify the party position of a targeted character and save it as an integer in a local variable that will then be used as the index for a global array that I'd like to edit the position of.

I've been experimenting with:

<Custom Apply Effect>
// Identify position of target of state
position = $gameParty.members().indexOf(user);
// Save an integer value in a global array that can be referenced later by position index
$gameVariables.value(100)[position] = [INTEGER];
</Custom Apply Effect>

I believe the issue is likely in the first line where I try to create the local var 'position', but I'm not sure, it's hard to debug. Have you done something like this before by any chance?
 

Vis_Mage

Novice Magician
Veteran
Joined
Jul 28, 2013
Messages
571
Reaction score
196
First Language
English
Primarily Uses
RMMV
Hey,

I was wondering if any of these custom jump commands (used in a move route) would be possible with a line of script:

1. Jump to player's current position
2. Jump to player's position, plus or minus 2
3. Jump to 2 tiles in front of the player, factoring in their facing direction
4. Jump to a random tile within a 3 block radius of the player (or another way to look at this, jump to the player's position, with a random value of 3 to -3 applied to both the X and Y values)
 

HasdrubalBarca

Veteran
Veteran
Joined
Feb 4, 2015
Messages
162
Reaction score
56
First Language
English
Primarily Uses
Does anyone know how to set up states that make use of VisuStella Custom Parameters like say a purchasable skill that adds to, say, endurance? Or add them in the actor menu? And also set up for a conditional branch in events?

I used to know how for RMMV with custom parameters plugins but I've lost that project and wondering if it's possible.
 

MerlinCross

Veteran
Veteran
Joined
Jun 8, 2015
Messages
208
Reaction score
89
First Language
English
Primarily Uses
Just to make sure I don't get into trouble down the line and this might be based on the terms of service provided;

Can I edit Plugins someone else made so long as I don't put said code out into the net? At times I've thought about a small edit or so but thought "Wait is this a problem?"
 

Nekohime1989

Nekohime
Veteran
Joined
May 31, 2014
Messages
498
Reaction score
226
First Language
English
Primarily Uses
RMMZ
How exactly does the origin field work in $gameScreen.showPicture. I'm confuzzled.
I figured it out!
 
Last edited:

CHKNRAVE

Surprisingly not sponsored by Yanfly.
Veteran
Joined
May 11, 2020
Messages
127
Reaction score
69
First Language
French
Primarily Uses
RMMV
Hi y'all,

I'm using an STB battle system for my game, and I need to execute code when it's a battler's turn to play. Is there any way to catch this moment?

Another thing that could work would be to detect who's playing after the current battler, so that I can execute the code with the same timing once the current battler's phase ends.

Thanks in advance to anyone who can help me with that.
 

Riazey

Master of None
Veteran
Joined
Feb 27, 2014
Messages
145
Reaction score
171
First Language
English
Primarily Uses
RMMV
I scoured google the internet for an answer but didn't see anything glaringly obvious, is there a way to move the text box a bit to the right without a plugin or with a short plugin snippet? I just need to position it so doesn't stretch across the entire screen~ :kaopride:

Alternatively, if there is maybe a way to restrict the width of the text box? Whichever is better!

I pretty much see everyone say to just use yanfly plugins but I'm looking for something ultra-light and am not using other yanfly plugins, preferably I wouldn't use a plugin at all! :kaoswt:
 

Vis_Mage

Novice Magician
Veteran
Joined
Jul 28, 2013
Messages
571
Reaction score
196
First Language
English
Primarily Uses
RMMV
Is there a script call I can use to check if the first party member has a certain armor/accessory equipped?
 

SeaPhoenix

Veteran
Veteran
Joined
May 14, 2015
Messages
249
Reaction score
230
First Language
English
Primarily Uses
RMMV
Is there a script call I can use to check if the first party member has a certain armor/accessory equipped?
Assuming you want this for MV (it should work for MZ too but I didn't check), the event command for conditional branch lets you check if a particular weapon or armor is equipped (see page 2 of the event command).

However, if you do need the code, the following gives you the equipment in slot n for the party leader:
Code:
$gameParty.leader().equips()[n]
n is 0, 1, 2, etc depending on which equipment slot you're looking at; these correspond to the equipment types in your database.

So to check if a sword (let's say it's the first equipment type, so n is 0) of id 5 is equipped, you can use the following script call in a conditional branch:
Code:
$gameParty.leader().equips()[0] && $gameParty.leader().equips()[0].id === 5
For more variations on this theme and if you're using Yanfly's plugins, you may find the list of script calls useful: https://forums.rpgmakerweb.com/index.php?threads/rpg-maker-mv-script-call-list.46456/

-------------------------------------------
@Riazey Once again assuming this is for MV and not MZ (since you mentioned Yanfly's plugins) It's easiest to change the width of the message box, because the message window is automatically centered based on the width. To change the message box width to 500 or whatever number you want, just paste the following code, save it as a .js file and add it as a plugin.
Code:
Window_Message.prototype.windowWidth = function() {
    return 500;
};
 
Last edited:

Riazey

Master of None
Veteran
Joined
Feb 27, 2014
Messages
145
Reaction score
171
First Language
English
Primarily Uses
RMMV
@SeaPhoenix Ooooh perfect thanks so much! Is there also a way to move the message box up a bit and increase the space between lines/add another few lines as well? The message skin is set to transparent so how that ends up looking isn't an issue for me~ Just need that text aligned with my image :kaoblush:
 

SeaPhoenix

Veteran
Veteran
Joined
May 14, 2015
Messages
249
Reaction score
230
First Language
English
Primarily Uses
RMMV
@SeaPhoenix Ooooh perfect thanks so much! Is there also a way to move the message box up a bit and increase the space between lines/add another few lines as well? The message skin is set to transparent so how that ends up looking isn't an issue for me~ Just need that text aligned with my image :kaoblush:
So all the relevant code that you want is in rpg_windows.js. Changing the window height will automatically change the y position of the message box to fit the new height (the y position is actually calculated by the updatePlacement function, but for your purposes it doesn't look like you need to fiddle with that).

Code:
Window_Message.prototype.numVisibleRows = function() {
    return 4;
};
Right now the default is to show 4 lines. You can copy the code above and change 4 to any other number. Note that this will affect ALL your message boxes.

If you want to increase the space between lines, this will affect the text everywhere, not just the message box (e.g., the menu screen, etc).

Code:
Window_Base.prototype.lineHeight = function() {
    return 36;
};
Again, copy the code above and change the number 36 to a larger number to increase the space between each line. There's probably a way to do it just for the message window, but that would require more time than I have to help out.

(Note: you can put all these snippets of code in one plugin, they don't have to be in separate plugins.)

If you want to change the height/width/position multiple times mid-game and if you have any further requirements, I'd suggest using Yanfly Message Core and Yanfly Extended Message Pack 1. I know you said you already looked at them, but this is precisely why the plugins are so popular - they give you the chance to customize the message box to look exactly the way you want if you're unfamiliar with Javascript. :smile:
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Evil7 added!


I did a bit of a remake on one of the maps, also I made a particle for jumping into the portal, and one for traveling through the portal. I'll probably add more sparkles later to embellish it. :LZSwink:
Polished the animation and added details :kaojoy:
Ami
What do you think about the Wood Bridge inside of Volcano?
Yet another gaming question, i'm currently playing Last of Us 2 and want to get another game to play next but can't decide between Ghost of Tsushima, Miles Morales & Jedi Fallen Order. After the latest mandalorian i AM on a star wars kick, but i also LOVED the last spiderman game that prequels Miles Morales. Ghost of Tsushima is the bottom of my list but i heard it was AWESOME. Just want a good story & fun gameplay.

Forum statistics

Threads
105,677
Messages
1,015,496
Members
137,353
Latest member
vongolavxv
Top