MV Yanfly Job Points - Set Maximum Per Battle

Hi everyone!
I'm using Yanfly's Job Points plugin, and I want to add a limit to how much JP can be earned from one battle.

Otherwise the system is very easily exploitable by keeping enemies alive and using a ton of skills
(since the plugin makes you gain JP for each action used, and that is something I want to keep).
I just don't want JP to be super easily farmable like this.

Any suggestions would be greatly appreciated!
I have next to no JS knowledge lol

Thanku! ^_^
Are you wanting the value to be static or variable across different battles?
@ThreeSixNine I'd like it to be a static number across the whole game, probably something like 300 JP at maximum per battle ^_^
So this one we will need to add two different sections of code.

First, add code 1 to line 637
Spoiler: code 1
JavaScript:
Game_Troop.prototype.maxJp = function () {
  return 300; // Change Max Jp value here.
}
}

Next, replace the two functions starting on line 401 and ending on line 424 with code 2:
Spoiler: code 2
JavaScript:
Yanfly.JP.BattleManager_makeRewards = BattleManager.makeRewards;
BattleManager.makeRewards = function() {
    Yanfly.JP.BattleManager_makeRewards.call(this);
    if ($gameTroop.jpTotal() < $gameTroop.maxJp()) { //Conditional added to show proper gains
      this._rewards.jp = $gameTroop.jpTotal();
    } else {
      this._rewards.jp = $gameTroop.maxJp();
    }
    this.gainJp();
};
BattleManager.gainJp = function() {
    var jp = $gameTroop.jpTotal();
    var max = $gameTroop.maxJp()
    $gameMessage.newPage();
    if (Yanfly.Param.JpAliveActors) {
      var members = $gameParty.aliveMembers();
    } else {
      var members = $gameParty.members();
    }
    members.forEach(function(actor) {
      actor.gainJp(Math.min(jp, max)); //Math.min added to set a maximum value
    });
};

This will set the maximum Jp that can be earned by each individual battler to 300. I have only lightly tested it so let me know if there's anything I might have missed.

-Edit-
Also, I know you said you wanted a static value, but there's something to be said for adding another function to set the value found in the maxJp function, in the event you do decide you'd like to change it. Consider boss battles or other situations that might warrant an individual high jp gain. Just something to think about.
@ThreeSixNine
I've made the changes you suggested, and am getting this error upon winning a battle.

I tried winning one as fast as I could to make test to see if it was specifically going over 300 that was causing it, but the error is occurring regardless of whether I stall out the battle for ages to get 300JP or not :/

Capture.PNG
@ThreeSixNine
I've made the changes you suggested, and am getting this error upon winning a battle.

I tried winning one as fast as I could to make test to see if it was specifically going over 300 that was causing it, but the error is occurring regardless of whether I stall out the battle for ages to get 300JP or not :/

View attachment 200588
Spoiler: mistake
When you get to that error screen, could you press f12 and upload a screen shot of the console error log?

I'll have to take a look, but I think I might already know whats happening.

Line 400 in my version has no code, the Battle Manager Section of the JP plugin starts on line 401 with this code:
JavaScript:
Yanfly.JP.BattleManager_makeRewards = BattleManager.makeRewards;

Can you verify that this line is still in your version for me?

The code 2 block should begin just below this line.

@LunaFamiliar I apologize, I made an error with the starting position for the code 2 block. I updated my original post with the correct starting location (line 401). I have also included the alias to the BattleManager.makeRewards function that was missing from the edit.
Otherwise the system is very easily exploitable by keeping enemies alive and using a ton of skills
Not related to the plugin, I would suggest you consider this part thoughtfully, as it may lead to other problems in your game. Generally speaking, you shouldn't want this to be possible.

Participating in combat should cost the party finite resources. For example, typically:
1) HP is a finite resource, and if the party runs out they die and lose the game.
2) In order to replenish that, you use MP on healing skills or potions, both of which are also finite. If you run out of those, you're back to #1.

You're absolutely free to do whatever you like with your game, but typically the above is what creates the challenge in the game. If the player can easily keep a combat going indefinitely, then the combat isn't draining their resources, which means they're in no real danger of losing. If there's no danger of losing, there's no real point to combat.

Just some stuff to consider - if I were in your situation, rather than adding a JP cap I would make sure that trying to prolong combats was a deadly proposition.
Not related to the plugin, I would suggest you consider this part thoughtfully, as it may lead to other problems in your game. Generally speaking, you shouldn't want this to be possible.

Participating in combat should cost the party finite resources. For example, typically:
1) HP is a finite resource, and if the party runs out they die and lose the game.
2) In order to replenish that, you use MP on healing skills or potions, both of which are also finite. If you run out of those, you're back to #1.

You're absolutely free to do whatever you like with your game, but typically the above is what creates the challenge in the game. If the player can easily keep a combat going indefinitely, then the combat isn't draining their resources, which means they're in no real danger of losing. If there's no danger of losing, there's no real point to combat.

Just some stuff to consider - if I were in your situation, rather than adding a JP cap I would make sure that trying to prolong combats was a deadly proposition.
You make a great point. I believe there might be better ways to handle this type of situation as well. I don't disagree with a cap, and if I were to use something like this in my project, I might try to set it up a bit differently.

The first option that came to my mind was to change all the plugin options so that the only way to gain jp was by defeating enemies. Since there is a limit to how many enemies can be in a formation, this is essentially one way to achieve a soft cap.
The first option that came to my mind was to change all the plugin options so that the only way to gain jp was by defeating enemies.
This is already one of the parameters, you would just set the other methods of gaining to 0 (perhaps this is what you meant...I read "change the options" as modify the code for them, which isn't necessary in this case).

The other thing for @LunaFamiliar to consider is whether it's really necessary to control the player's behavior. Personally, I don't try to force people to play in a certain way.

For example, this exact situation is possible to do in Final Fantasy Tactics - every action gets you JP, so if you try really hard and plan out the correct combination of units, classes and skills, it is possible to sit in a map and grind JP.

Now, it's really freaking tedious to do that, and simply not fun...but some people enjoy doing it to min-max their characters, or get jobs earlier that they normally couldn't. Who are they hurting by doing that? What makes it worth coding some way to prevent them from doing it?
This is already one of the parameters, you would just set the other methods of gaining to 0 (perhaps this is what you meant...I read "change the options" as modify the code for them, which isn't necessary in this case).
Exactly, I would attempt to use the existing plugin options to achieve my goals, but, that being said, I have asked for a decent amount of help here on the forums so I'm always trying to give back.

But I definitely hear what you are saying. Sometimes the initial response to what we see as a problem in our projects, is not always the best route.
@LunaFamiliar I apologize, I made an error with the starting position for the code 2 block. I updated my original post with the correct starting location (line 401). I have also included the alias to the BattleManager.makeRewards function that was missing from the edit.

Thanks for the update, running a quick Battle Test with a ton of enemies still lets me gain more than 300 JP
I got about 340 just now, so I'm not sure what's going on there or whether it doesn't work in a Battle Test and I'd have to try it in a save file?
(but I assume Battle Test emulates a proper fight scenario because if it doesn't what's the point of it)

Thank you for your feedback and thoughts on placing a cap on JP, I've noted your opinion 🙂
battle test is really only useful for making sure a skill works correctly or the enemy AI is correct.
it definitely has some flaws to it.
i just make an encounter event on a testing map for testing battle mechanics.

edit: and testing boss fights is best in actual playthroughs. battle test kinda broken there cus the items.
once done couple playthrough tests and know the exact inventory and exp would have for each part in the game you can make events in the test map to just give you those exact amounts for retesting after tweak the boss's stats.
@Tiamat-86 ahhh okie dokie.
That's a bit lame.. but good to know thank you.

Just tested it in an actual save file, and it's definitely not capping at 300.
Got 314 that time.
i have an idea for a different kind of approach to discourage doing this kind of JP grinding.
what if made a troop event that runs every turn after X amount of turns, and this event would use if statements (to check active the party) and the plugin command to lose JP for those party members.
then its kinda like "ya training can good thing but but to much can hurt you more then it helps."
Just tested it in an actual save file, and it's definitely not capping at 300.
Got 314 that time.
There are some errors in @ThreeSixNine 's code.

You don't need to include his Code 1, (and if you do, you shouldn't have the second closing brace at the bottom...I'm not sure how that isn't throwing an error).

The problem with the rest of it is that there are two different ways your actors gain JP - one function (that he gave you) applies it to the entire party, and looks like it's getting correctly tracked and capped. But the other gives it to individual actors when they do things like perform actions.

So find the line that says this._battleJp += value; (line 525 in the original file)

Add a line before it that says value=Math.min(value, 300-this._battleJp);

You should not need either of the other pieces of code you were given before.
@ATT_Turan thank you very much, that seems to be working <3
@ATT_Turan Thanks for the correction of the code 1.

As for the inclusion of that function, I was planning on adding another to be able to change the max value, rather than have it be hard coded.

As for the missing of the individual actor gains, I have them set to 0 already in my current project so I didn't even consider it while looking at this.

Thanks again for the corrections.
As for the inclusion of that function, I was planning on adding another to be able to change the max value, rather than have it be hard coded.
And that's a fine concept, but since that number is only used in one place, there's really no point in making a function that returns that number that's only used once. Just change it in that one place if you want to (it being in a function doesn't make it any less hard coded).

I think more of what you're thinking of would be to create a new plugin parameter that could be edited inside the plugin manager in MV.
@ATT_Turan In your solution, the max value is only used once. In the code I added, I referenced the max value three times. I figured adding in that function would give the ability to change all 3 at once. Eventhough those three places are within the same few lines.

Wouldn't adding a function to change the value give the option to change it mid-game? Which is something that crossed my mind. I am still learning when it comes to js and coding in general.

A plugin parameter did also come to mind as well.
Wouldn't adding a function to change the value give the option to change it mid-game?
Not that I can think of - how would you do this? Anything that's typed into your code is there.

If you had it stored as a variable (which also makes much more sense than a function that does nothing except return a specific value), you could use script commands during the game to change the value of that variable.
A plugin parameter did also come to mind as well.
That's the most sensible path - it would allow the user to choose the value in the plugin manager, and you could also provide a plugin command to change it during the game.

I will mention to you that the above post is pretty borderline per forum rules; I've asked before about releasing snippets to fix some bugs in Yanfly plugins, and been told that posting an entire function of that code is considered to infringe on Yanfly's terms of use. Just so you have that in part of your mind 🙂

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-job-points-set-maximum-per-battle.140174/