JavaScript questions that don't deserve their own thread

[MZ] Base function handling actor's parmas update from equipment.

Hello everyone.
I'm writing a plugin and need to change the standard behaviour of when an item is equipped (in particular an armor).
I didn't have much luck figuring out how to achieve this.
My base idea is to find what function handles this aspect, overwrite it with just the addition of a check (prob something along the line item.isArmor() or item.etype == 2) in order to do my custom calculation of bonus given by the item.

Spoiler: A more detail explanation of what I want to do
I'm creating a plugin that overhaul the base system with a modded version (from my very own homebrew campaign) of the D&D 5e one.
In this particular case, I'm working over AC (def) calculation based on the Actor dex modifier (base def) and the armor type (light/medium/heavy). Basically, in D&D based on the armor category you either add you modifier, add it up to 2 or not add it at all.
I'd like to express this when the Actor equips a new armor. The idea is to reduce the bonus based on the armor type, something along the line of:

JavaScript:
param -= (this.def * (item.atype == 3)) // Remove all dex bonus if Heavy Armor
    - (Math.max(this.def-2, 0) * (item.atype == 2)); // If it's medium armor should add only 2 dex bonus

(where this is supposedly the Game_Actor entity)

Thanks in advance for any help.
My base idea is to find what function handles this aspect
Game_BattlerBase.param is what handles stat calc overall.
Game_Actor.paramPlus is what handles stats from gear and stat grow effects.
Game_Actor.paramBase is what handles the base stats (raw stats from class)

even though it looks like a regular property that holds a number, when you call a battler's param directly (mhp, def, etc), its actually calls their param() function and it calculates what the param should be right then and there based on paramBase and ParamPlus. because param() uses paramPlus() in its own calculation, you shouldnt reference param() within paramPlus() directly.

you can edit paramPlus so that if the paramId is 3, look at if the current equipment is an armor, and if so add a bonus based on its atypeId.
- if its heavy, just use the armor's def
- if its medium, add in Math.min(Math.floor((this.paramBase(3)-10/)2), 2)
- if its light, add in Math.floor((this.paramBase(3)-10/)2)

Edit: I suppose you would also want to also make paramPlus no longer factor in this._paramPlus and move that into paramBase so that parameter grow effects count in dex bonuses
Game_BattlerBase.param is what handles stat calc overall.
Game_Actor.paramPlus is what handles stats from gear and stat grow effects.
Game_Actor.paramBase is what handles the base stats (raw stats from class)

even though it looks like a regular property that holds a number, when you call a battler's param directly (mhp, def, etc), its actually calls their param() function and it calculates what the param should be right then and there based on paramBase and ParamPlus. because param() uses paramPlus() in its own calculation, you shouldnt reference param() within paramPlus() directly.

you can edit paramPlus so that if the paramId is 3, look at if the current equipment is an armor, and if so add a bonus based on its atypeId.
- if its heavy, just use the armor's def
- if its medium, add in Math.min(Math.floor((this.paramBase(3)-10/)2), 2)
- if its light, add in Math.floor((this.paramBase(3)-10/)2)

Edit: I suppose you would also want to also make paramPlus no longer factor in this._paramPlus and move that into paramBase so that parameter grow effects count in dex bonuses
Thanks for the answers.
As soon as I have some free time I'll look into it
Hey everyone!

What's the correct way to leave the game back to the title screen?

At the moment I'm using SceneManager.goto(Scene_Title) and it works, but for some reason the title BGM does not play at all, and sometimes some of the current map sounds (like BGS etc) still play in the title screen.

Thanks for reading c:
@raffle You might want to start a support thread, including what plugins you're using. That command is what the default engine uses when you go into the menu and quit back to the title - so it ought to work.
VisuStella BattleCore Help

I'm using VisuStella's fix on RMMZ's TPB (Wait) combat system and I'm having an issue where my actors are not moving in order on how fast their AGI is. From my tests, if actors are within 4 AGI of another actor, turn order will be decided on which actor appears first in the party order. So in some instances, an actor with 100 AGI will get their first turn before an actor with 103 AGI. I'm assuming the issue lies in Mechanics Settings/JS: Calculate, but I could be completely wrong.
JavaScript:
// Declare Constants
const agi = this.subject().agi;

// Create Speed
let speed = agi;
if (this.allowRandomSpeed()) {
    speed += Math.randomInt(Math.floor(5 + agi / 4));
}
if (this.item()) {
    speed += this.item().speed;
}
if (this.isAttack()) {
    speed += this.subject().attackSpeed();
}

// Return Speed
return speed;
@Tennshii Per the first post in this thread, questions about plugins should get their own thread in Plugin Support.

Have you disabled whatever parameter will make the this.allowRandomSpeed() true?
@Tennshii Per the first post in this thread, questions about plugins should get their own thread in Plugin Support.

Have you disabled whatever parameter will make the this.allowRandomSpeed() true?
Ok I'll make a thread for this.
Code:
this.allowRandomSpeed()
is also disabled by default. I can try to remove it since it's disabled anyways, but I'm worried that I'll break something if I do.

Spoiler: Disabled Option
1717086893466.png
@Tennshii Well, I dunno what else to say - that's the only line in the code you posted which would change the end value.

There's nothing in there which references formation order, so if the randomSpeed is returning negative, the return value will be the battler's agi plus the speed of the skill.

Anything outside of that would be how the rest of the plugin's code handles that value, which we can't see.
Guys, is there a list where I can check javascript code for stuff like enabling the Escape command, checking if an actor used Guard, checking if an actor inflicted magic damage etc.?

By the way, I'm mostly interested in code that can be used during battle, like user.gainHP(), target.isDead() etc.
enabling the Escape command
the flag for that is BattleManager._canEscape

checking if an actor used Guard, checking if an actor inflicted magic damage etc.?
the important detail here is *when*. cant really tell you how to go about that without knowing when youre checking this. You dont have a listed engine, but between yanfly's buffs & states for MV and Turans Eval Tags for MZ you can set up states to do things when those criteria are met at different timings
@TheNewSon Erm...the code? 😛

A lot of that isn't in the script call list, as far as I know. You could also go through
if that's easier for you to read than the code. You could also choose an individual item and Google it and usually find a thread where it's been already asked.

Your profile doesn't say which engine you're using, and neither does your post, so that Web site doesn't detail the differences between MV and MZ.

enabling the Escape command
Code:
BattleManager._canEscape = true
or false

checking if an actor used Guard
"used" at what past point? You can see whether an actor is currently guarding for their turn with
Code:
your reference for the actor.isGuard()

checking if an actor inflicted magic damage
Again, at what point? During a skill's resolution, that Game_Action object will have an isMagical() method.
@Robro33 @ATT_Turan thanks for the quick answer! And sorry, I forgot to say I'm using MV.

EDIT: I created this post since my doubts have become more complex.
@TheNewSon This thread is really designed for simple questions about JavaScript syntax or finding the right function, etc.

For specific questions that interact with plugins - especially 5 questions - you really should make your own thread.
Is there a way to go through the events on another map than the one the player is currently on?

I am trying to apply this script to another map, e.g. go through every event on that map and if it has the notetag <enemy> set its self switch A to false.

$gameMap.events().forEach(event => {if (event.event().meta.enemy && !event._erased){
$gameSelfSwitches.setValue([$gameMap._mapId,event._eventId,'A'], false);
}});
Is there a way to go through the events on another map than the one the player is currently on?

I am trying to apply this script to another map, e.g. go through every event on that map and if it has the notetag <enemy> set its self switch A to false.

$gameMap.events().forEach(event => {if (event.event().meta.enemy && !event._erased){
$gameSelfSwitches.setValue([$gameMap._mapId,event._eventId,'A'], false);
}});
Not easily, since other maps are not loaded, and so you can't directly access the information about their events.

You'd probably need to load the JSON files for those maps yourself and look through those.
Check out DataManager.loadMapData to see how the engine does it - you'd need to do something similar, just without using it to overwrite the currently loaded map.
Just thinking out loud but... isn't it easier to have this be processed through an autorun event upon entering the target map?
Is there a way to go through the events on another map than the one the player is currently on?
I saw a Japanese blogger with the same issue a while ago, but can’t seem to find it. The conclusion (IIRC) was that it’s possible to load the map into another variable and reference the data there. Don’t recall him concluding the blog post with an “I did it!”, though… Will post it when I find it.
isn't it easier to have this be processed through an autorun event upon entering the target map?
Yes, but I'm trying to think of the best way to do this: When a day passes/the player sleeps, respawn the enemies on every map (or toggle their self switch A, which controls dead/alive states)
You could put them in an array after they are defeated to be respawned and then during the sleep event or time system slice them out using a modified version of Trihan's tutorial for Respawn resource nodes

I use it to respawn fish in my game.
Don’t recall him concluding the blog post with an “I did it!”, though…
There have been threads here where code was produced to load a second map's data. I don't recall the purpose, which would make searching difficult.

Yes, but I'm trying to think of the best way to do this
I think werzaque's suggestion is the best way to do this. When whatever happens that indicates a day has passed, set a switch/increment a variable that indicates the last date you were places, whatever. When you go to a map, if that switch is on, respawn enemies. Should be a few lines of an Autorun event, copy and paste.

You could also do something like Slaughty suggests, but I'm not sure that level of complexity is merited.

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