MV PT Variance

Hi.

Does anyone know if there is a way for TP (who're used in TP Gauge for a LimitBreak-Like System) to be subject to a Variance ?

For exemple, my skill gimme theoretically 6 TP per hit.
I would like put a Variance on this 6 TPs gifted per Hit, like a Variance50% , means, hit would gift me in reality TPs between Minimum 3 TPs and Maximum 9 TPs, randomly.
Like the 1st hit gimme 5 PTs, the next one 9 , the next 3 the next 6 the next 6 , the next 4, etc etc.

It's possible ? (by some script/plug-in/Calculation/Formula )


[ I've already started looking at this ( http://www.yanfly.moe/wiki/Enhanced_TP_(YEP) ), but it doesn't seem to have what I want to do (or else I read it wrong]
The Enhanced TP plugin does exactly what you want.

Every entry in the plugin parameters is a JavaScript eval, so you can make the formula be whatever you want it to be.

The Deal HP Dmg entries are executed by the battlers, so you'd reference the TP gain field of the action with $dataSkills[BattleManager._action.item().itemId()].tpGain

So you could put for the Deal HP DMG field:
Code:
Math.randomInt($dataSkills[BattleManager._action.item().itemId()].tpGain+1)+$dataSkills[BattleManager._action.item().itemId()].tpGain/2
and you'll get a number between 50% and 150% of the TP Gain you entered for the skill in the database.
Ok, thanks, I guess I missed that line, or just didn't understand what I was reading ^^
When you are talking about HP Damage field of EnhancedTP plugIn, you are talking about this, right ? (screenshot linked)


By the way, could I abuse your kindness and ask you how to modify the formula with 20% Variance, and one other of 30% Variance ? I want to do variance tests to find out which Fill rate is the most suitable.
I'm realy not at all good with coding or scripts and formula T-T
When you are talking about HP Damage field of EnhancedTP plugIn, you are talking about this, right ? (screenshot linked)
No, you circled the line that says "Take HP DMG" - the words I used twice are "Deal HP DMG," which is the line below. That's what I assumed from your original post when you said "my skill gimme theoretically 6 TP" - that you're talking about when the actor is using a skill and dealing damage.

By the way, could I abuse your kindness and ask you how to modify the formula with 20% Variance, and one other of 30% Variance ?
It's just math. At the end I put "/2", divided by 2, so 50%. All of the stuff inside Math.randomInt() produces a random number between 0 and what you put inside the parentheses.

So if you want a different number range, you can just change what's inside the parentheses and what you add after.
No, you circled the line that says "Take HP DMG" - the words I used twice are "Deal HP DMG," which is the line below. That's what I assumed from your original post when you said "my skill gimme theoretically 6 TP" - that you're talking about when the actor is using a skill and dealing damage.

My bad, im a little bit tired after read formulas for hours, I misunderstood, but it's ok now 🙂

It's just math. At the end I put "/2", divided by 2, so 50%. All of the stuff inside Math.randomInt() produces a random number between 0 and what you put inside the parentheses.

So if you want a different number range, you can just change what's inside the parentheses and what you add after.

I'm sincerely sorry (you'll probably take me for an idiot...) but not being English and not understanding anything about coding, it's quite complicated for me to learn and understand all this....

If I understand what you are saying, then the 1st formula you used is equivalent to 100% of the damage, so /2 gives a variance of 50%
So if I use the formula

Math.randomInt($dataSkills[BattleManager._action.item().itemId()].tpGain+1)+$dataSkills[BattleManager._action.item().itemId()].tpGain/5

, this translates to a variance of 20%?
I'm sincerely sorry (you'll probably take me for an idiot...) but not being English and not understanding anything about coding, it's quite complicated for me to learn and understand all this....
No, it's okay, just try to stop thinking in terms of English or coding. It's just math that you learned in school 😉

If I understand what you are saying, then the 1st formula you used is equivalent to 100% of the damage, so /2 gives a variance of 50%
No. I said it gives a random number between 0 and what you put inside Math.randomInt().

So if it gives 0, then you have 0 + the skill's TP number/2 which is 50% of the skill's TP number (what you said you wanted for your minimum).

I put inside of the parentheses the skill's TP + 1 because it gives us a value between, not equal to. So the highest number that can make is the skill's TP number...then it adds the skill's TP/2 which will be 150% of the number, the maximum you said it wanted.

So if you want +/-20%, the minimum value is 80% of the skill's TP value.

So you have Math.randomInt()+$dataSkills[BattleManager._action.item().itemId()].tpGain*.8

Then you say "What plus skill's TP * .8 will give me 120% of the value? 40%!"

So you put 40% of that as the maximum inside Math.randomInt() (+1 because it will always be less). Thus the end result is:
Code:
Math.randomInt($dataSkills[BattleManager._action.item().itemId()].tpGain*.4+1)+$dataSkills[BattleManager._action.item().itemId()].tpGain*.8
well, thanks for your patience 🙂

i dont know why but with +/-20%Formula, i understand ^^

I guess it was the "1" that was giving me trouble understanding. I understand much better with the "0.8" ..... ^^" xD
Maybe just as I think of math, 0.8 reminds me more of percentages than 1, so I understand better.

Anyway, thank you anyway.

In the end, I must therefore put this formula
Code:
Math.randomInt($dataSkills[BattleManager._action.item().itemId()].tpGain*.4+1)+$dataSkills[BattleManager._action.item().itemId()].tpGain*.8
in the field "Deal HP damages"

And if i want to adapt variance, i need to modifie 0.4 and 0.8 ?
For exemple:



I want a 35% variance
So if i want a +/-35%, the minimum value is 65% of the skill's TP value.
So i have: Math.randomInt()+$dataSkills[BattleManager._action.item().itemId()].tpGain*0.65
Then now i want 135%
"What plus skill's TP * 0.65 will give me 135% of the value? =>70%
Then i put 70% of that as the maximum inside Math.randomInt() (+1 because it will always be less)


Thus the end result is

Math.randomInt(
$dataSkills[BattleManager._action.item().itemId()].tpGain*0.70+1
)

+$dataSkills[BattleManager._action.item().itemId()].tpGain*0.65



Which finally gives me:
Code:
Math.randomInt($dataSkills[BattleManager._action.item().itemId()].tpGain*.70+1)+$dataSkills[BattleManager._action.item().itemId()].tpGain*.65



Am I right? (crossing finger for luck xD )
Looks right to me.

Keep in mind unless you're setting your skills to give high amounts of TP in the database, a lot of these aren't going to produce very meaningful results.

For example, in your first post you refer to a skill having 6 for its TP value. 35% is a very specific number that doesn't mean anything there (you won't see any difference from 25% until you get to 50%).
Looks right to me.

Keep in mind unless you're setting your skills to give high amounts of TP in the database, a lot of these aren't going to produce very meaningful results.

For example, in your first post you refer to a skill having 6 for its TP value. 35% is a very specific number that doesn't mean anything there (you won't see any difference from 25% until you get to 50%).
nice 😀

Yes, I will adapt the TP gain of the skills themselves 🙂


Thank you for everything.
It's thanks to people like you that I'll be able to improve (and above all, that I'll be able to understand what I'm doing instead of doing stupid copy/paste without understanding ^^ )
@ATT_Turan - mostly OK, but testing your code in-game yields a TypeError: itemId is a Game_Item method, but action.item() returns a database reference, i.e. a $dataItems/$dataSkills record.

I'd consider one of these instead:

  1. var variance = 0.2; var gain = BattleManager._action.item().tpGain; var v = Math.floor(gain * variance); gain + Math.randomInt(v+1) + Math.randomInt(v+1) - v

  2. BattleManager._action.applyVariance(BattleManager._action.item().tpGain, 20)
Both these examples should give the same result: ±20% variance.

  1. var variance = 0.2; var gain = BattleManager._action.item().tpGain; var v = Math.floor(gain * variance); gain + Math.randomInt(v+1) + Math.randomInt(v+1) - v

  2. BattleManager._action.applyVariance(BattleManager._action.item().tpGain, 20)

Both these examples should give the same result: ±20% variance.

thank you for proofreading and testing the formulas.

Do the new formulas also have to be put in the Deal HP DMG field of the Yanfly Enhanced TP Plugin ?
If that's the part that you want it to affect, yes. I had a look at the code of YEP_EnhancedTP and it looks like you were correct: I don't see a "TP Gain" ("Gain de TP") trigger. If you put it in Deal HP DMG, then the user will gain that much TP when they deal HP damage.

Alternatively, I just wrote a small plugin (see attached file).
[Edit: see my follow-up post for a better version!]
Spoiler: plugin code
JavaScript:
/*:
 * @target MV MZ
 * @plugindesc Apply variance for user TP Gain.
 * @url https://forums.rpgmakerweb.com/index.php?threads/152698/
 * @help Free to use and/or modify for any project, no credit required.
 */

void (function(alias) {
'use strict';
    var VARIANCE = 20;

    Game_Action.prototype.applyItemUserEffect = function() {
        var subject = this.subject();
        var base    = this.item().tpGain;
        var value   = Math.floor(this.applyVariance(base, VARIANCE) * subject.tcr);
        var diff    = value - base;
        // add before/after to avoid upper/lower TP limits
        // console.info('    tp =', subject.tp, '\n  diff =', diff);
        if (diff > 0)
            subject.gainSilentTp(diff)
        alias.apply(this, arguments);   // +(base)
        if (diff < 0)
            subject.gainSilentTp(diff);
        // console.info('now tp =', subject.tp);
    };

})(Game_Action.prototype.applyItemUserEffect);
It seems to work OK for me in MV and MZ. To change the variance, open the plugin in a text editor (e.g. Notepad) and edit this line:
JavaScript:
    var VARIANCE = 20;
20 means ±20% variance. 👋
If that's the part that you want it to affect, yes. I had a look at the code of YEP_EnhancedTP and it looks like you were correct: I don't see a "TP Gain" ("Gain de TP") trigger. If you put it in Deal HP DMG, then the user will gain that much TP when they deal HP damage.

Alternatively, I just wrote a small plugin (see attached file).
Spoiler: plugin code
JavaScript:
/*:
 * @target MV MZ
 * @plugindesc Apply variance for user TP Gain.
 * @url https://forums.rpgmakerweb.com/index.php?threads/152698/
 * @help Free to use and/or modify for any project, no credit required.
 */

void (function(alias) {
'use strict';
    var VARIANCE = 20;

    Game_Action.prototype.applyItemUserEffect = function() {
        var subject = this.subject();
        var base    = this.item().tpGain;
        var value   = Math.floor(this.applyVariance(base, VARIANCE) * subject.tcr);
        var diff    = value - base;
        // add before/after to avoid upper/lower TP limits
        // console.info('    tp =', subject.tp, '\n  diff =', diff);
        if (diff > 0)
            subject.gainSilentTp(diff)
        alias.apply(this, arguments);   // +(base)
        if (diff < 0)
            subject.gainSilentTp(diff);
        // console.info('now tp =', subject.tp);
    };

})(Game_Action.prototype.applyItemUserEffect);
It seems to work OK for me in MV and MZ. To change the variance, open the plugin in a text editor (e.g. Notepad) and edit this line:
JavaScript:
    var VARIANCE = 20;
20 means ±20% variance. 👋
*3* thanks a lot 😮
If i understand, i just need to DL the file, pût it in js/plugin file, and if i want to test with others VAR, i just need to change the "20" by the VAR i want, and this modifies the TP gain by adding the desired variance to it ? ^^
Then, if I use the plugin, I must put the "Deal HP DMG" field at 0 or I must write a formula there?

(Or did I misunderstand, i may have to DL the plugin, put it in js/plugin, copy the entire formula and paste it in "Deal HP DMG" of the EnhancedTP plug-in?)

Btw, i know there is write "no credit required", but would you like to be credited for this? that seems fair to me ^^
(I don't think my game will ever be released, it's more of a personal hobby than a real project, but who know ?)
@Khyoshyro - oh, I just found a small bug: you could lose TP if you are near max TP and the variance goes below the original TP Gain.

I've rewritten the plugin to fix this, see the attached file. This new version has a plugin parameter so you don't have to edit the code, and it also has a notetag so you can make some skills/items have different TP Gain variance. (There should also be a little bit less risk of incompatibility with other plugins, e.g. no double-refresh).

It works like any other plugin: put the file in your project's js/plugins folder, add it in the editor (Plugin Manager), then save your project to apply changes.

Yes, if you're using this then you can reset the Deal HP DMG parameter of YEP_EnhancedTP to 0. This plugin is an alternative to YEP_EnhancedTP; it doesn't need YEP_EnhancedTP to work. I think they should be compatible with each other, though, in case you want to use Yanfly's plugin for something else.

You can credit me as "Caethyril" if you want. Happy RPG Making! 👋


Just for reference (you can download the attached file instead):
Spoiler: plugin code
JavaScript:
// ============= //
// VarianceTP.js //
// ============= //

/*:
 * @target MV MZ
 * @plugindesc v2 - Apply variance for user TP Gain.
 * @url https://forums.rpgmakerweb.com/index.php?threads/152698/
 * @help Set the default TP Gain variance in the plugin parameters.
 * 
 * You can also use this tag in the Note box of an Item or Skill:
 *        <TP Gain Variance: X>
 *   e.g. <TP Gain Variance: 40>
 * This example sets the TP Gain variance to 40% for the tagged Item/Skill.
 * 
 * Free to use and/or modify for any project, no credit required.
 * 
 * @param Variance
 * @type number
 * @decimals 2
 * @min 0
 * @max 100
 * @desc Variance to apply to all items/skills.
 * Default: 20, i.e. ±20%.
 * @default 20
 */

void (function(alias) {
'use strict';
    var PLUGIN_NAME = 'VarianceTP';
    var TAG_NAME    = 'TP Gain Variance';

    var PARAMS   = PluginManager.parameters(PLUGIN_NAME);
    var VARIANCE = Number(PARAMS.Variance || 0);

    Game_Action.prototype.applyItemUserEffect = function() {
        var item = this.item();
        var orig = item.tpGain;
        var tag  = item.meta[TAG_NAME];
        var v    = isNaN(tag) ? VARIANCE : Number(tag);
        // adjust value
        item.tpGain = this.applyVariance(orig, v);
        // console.info('    tp =', this.subject().tp, '\n   old =', orig, '\n   new =', item.tpGain);
        // apply existing TP Gain method
        alias.apply(this, arguments);
        // reset value
        item.tpGain = orig;
        // console.info('now tp =', this.subject().tp);
    };

})(Game_Action.prototype.applyItemUserEffect);
@caethyril what if you want to have a different TP variance based per skill?
could a notetag work? like: <TPvariance:20> (20%) and <TPvariance: 17> for 17%?

as some skills are more powerfull, some can give you more or less, or weaker give more
than the really strong once to balance the TP better?

just an idea though.

EDIT: just readed the code and is possible 😛 (sorry)

@Khyoshyro - oh, I just found a small bug: you could lose TP if you are near max TP and the variance goes below the original TP Gain.

I've rewritten the plugin to fix this, see the attached file. This new version has a plugin parameter so you don't have to edit the code, and it also has a notetag so you can make some skills/items have different TP Gain variance. (There should also be a little bit less risk of incompatibility with other plugins, e.g. no double-refresh).

It works like any other plugin: put the file in your project's js/plugins folder, add it in the editor (Plugin Manager), then save your project to apply changes.

Yes, if you're using this then you can reset the Deal HP DMG parameter of YEP_EnhancedTP to 0. This plugin is an alternative to YEP_EnhancedTP; it doesn't need YEP_EnhancedTP to work. I think they should be compatible with each other, though, in case you want to use Yanfly's plugin for something else.

You can credit me as "Caethyril" if you want. Happy RPG Making! 👋


Just for reference (you can download the attached file instead):
Spoiler: plugin code
JavaScript:
// ============= //
// VarianceTP.js //
// ============= //

/*:
 * @target MV MZ
 * @plugindesc v2 - Apply variance for user TP Gain.
 * @url https://forums.rpgmakerweb.com/index.php?threads/152698/
 * @help Set the default TP Gain variance in the plugin parameters.
 *
 * You can also use this tag in the Note box of an Item or Skill:
 *        <TP Gain Variance: X>
 *   e.g. <TP Gain Variance: 40>
 * This example sets the TP Gain variance to 40% for the tagged Item/Skill.
 *
 * Free to use and/or modify for any project, no credit required.
 *
 * @param Variance
 * @type number
 * @decimals 2
 * @min 0
 * @max 100
 * @desc Variance to apply to all items/skills.
 * Default: 20, i.e. ±20%.
 * @default 20
 */

void (function(alias) {
'use strict';
    var PLUGIN_NAME = 'VarianceTP';
    var TAG_NAME    = 'TP Gain Variance';

    var PARAMS   = PluginManager.parameters(PLUGIN_NAME);
    var VARIANCE = Number(PARAMS.Variance || 0);

    Game_Action.prototype.applyItemUserEffect = function() {
        var item = this.item();
        var orig = item.tpGain;
        var tag  = item.meta[TAG_NAME];
        var v    = isNaN(tag) ? VARIANCE : Number(tag);
        // adjust value
        item.tpGain = this.applyVariance(orig, v);
        // console.info('    tp =', this.subject().tp, '\n   old =', orig, '\n   new =', item.tpGain);
        // apply existing TP Gain method
        alias.apply(this, arguments);
        // reset value
        item.tpGain = orig;
        // console.info('now tp =', this.subject().tp);
    };

})(Game_Action.prototype.applyItemUserEffect);
Thanks a lot :3


just two last little questions. I see that there is the command: <TP Gain Variance: X> in the plugin.

Does the plugin already directly apply a VAR to all skills, or do I have to put the command in the notes for each skill?

Or is the command only used, as ShadowDragon said, to apply a different variant to certain chosen skills, while applying the plugin's reference variance to all the others?

(I know the question may be silly, but I'm just new to the subject, so I'm learning ^^ )
It's OK! This is correct:
Or is the command only used, as ShadowDragon said, to apply a different variant to certain chosen skills, while applying the plugin's reference variance to all the others?
Any Item/Skill without the tag will use the value of the plugin's Variance parameter instead (default 20%).
itemId is a Game_Item method, but action.item() returns a database reference
Oops! I thought I even checked that...apparently not 😛

Original thread: https://forums.rpgmakerweb.com/threads/pt-variance.152698/