And how exactly would I reset it? Haha sorry. Your script worked perfectly, but yes you were right. I do need to reset it.
Increase a parameter of an enemy by percent using a variable?
RPG Maker MZ SupportAnd how exactly would I reset it? Haha sorry. Your script worked perfectly, but yes you were right. I do need to reset it.
Exactly as I said in post 13 - make an autorun event.
You already have the code for setting the experience:
$dataEnemies[Id of the enemy here].exp= whatever the original value isThen you Erase Event so it won't run again until the next time you appear on the map.
(I think Erased events reload after a battle. If that doesn't work and it only runs once, you'll need to do something fancier with a switch)
Here's the thing, buddy...where are you getting the original value from when you've modified the original value? 😉
Your brain? 🤣 I don't see any reason for this to be dynamic, the OP is making the game, they know what they want the exp to be. I don't super understand your question.
If they typed in the database entry for the enemy that the EXP given is 230, then they type that also into their event
$dataEnemies[Id of the enemy here].exp=230If they change it in the database later for balancing or something, they'll simply alter the value in the event also.
Fair enough. I wasn't sure if you'd intended for OP to hardcode it, but that works as long as he remembers he's done this if the value does change. 😛
Re editing
Resetting the value is a good idea, but remember that battles can end without returning to the map, e.g. defeat -> game over. I'm not sure if that situation applies in this case. Regardless, I notice VisuStella Battle Core has a
As an alternative (untested):
The example in this plugin's help is additive, here's a multiplicative version:
In case it's relevant, there are
$dataStuff: these arrays are loaded once per session. So, as well as not being recorded in save files, modifications will affect all gameplay, including new and continued playthroughs, until the game is closed. That's usually not a good idea. 😴Resetting the value is a good idea, but remember that battles can end without returning to the map, e.g. defeat -> game over. I'm not sure if that situation applies in this case. Regardless, I notice VisuStella Battle Core has a
<JS Post-End Battle> tag, so you could probably use that for the reset? (endBattle happens after makeRewards.)As an alternative (untested):
JavaScript:
/*:
* @target MZ
* @plugindesc Define custom enemy EXP formulae with notetags.
* @url https://forums.rpgmakerweb.com/index.php?threads/151540/
* @help Enemy notetag:
* <exp formula: code>
* Replace "code" with an eval, where "this" is the Game_Enemy instance.
* Example - increase enemy EXP by +20% for every +1 to variable ID 123:
* <exp formula: this.enemy().exp * (1 + $gameVariables.value(123) / 5)>
*
* Free to use and/or modify for any project, no credit required.
*/
void (alias => {
const TAG_NAME = "exp formula";
Game_Enemy.prototype.exp = function() {
const value = eval(this.enemy().meta[TAG_NAME]);
if (!isNaN(value)) return parseInt(value, 10);
return alias.apply(this, arguments);
};
})(Game_Enemy.prototype.exp);
<exp formula: this.enemy().exp * 1.2 ** $gameVariables.value(123)>In case it's relevant, there are
Game_Enemy methods for the other rewards: gold and makeDropItems.I think this fails because it creates a loop:
user.mhp asks for the total value, which includes the plus formula. Might work if you use user.paramBase(0) instead, i.e. the database value, no traits or anything.Where's the loop? Granted, I don't/can't know how the VisuStella tag works, but I assume it's referenced once when the state is applied. I didn't see any indication that it's a dynamic thing.
Here's the documentation on that tag from the Yanfly wiki (link):
<JS param Plus: code>
- Used for: Actor, Class, Weapon, Armor, Enemy, State Notetags
- Runs 'code' to change the 'param' plus value.
- Replace 'param' with 'MaxHP', 'MaxMP', 'ATK', 'DEF', 'MAT', 'MDF', 'AGI',
or 'LUK' to determine which parameter to modify.
- Replace 'code' with JavaScript code to determine how much to change the
plus amount for the parameter's total calculation.
- This is used to calculate the 'plus' portion in the Parameter Settings =>
Basic Parameter => Formula.The last point strongly suggests to me that this is incorporated as part of the
param formula. Haven't tested it, though; was just a suggestion. 👋I see what you mean there.
Original thread: https://forums.rpgmakerweb.com/threads/increase-a-parameter-of-an-enemy-by-percent-using-a-variable.151540/