MV Success Rate based on Target's TP amount...

I'm using the steal move from the Octopath Demo by Olivia and there's this following line in a Before Eval...


var rate = [0.05, 0.33, 0.67, 1.0][user.bp] + 1 - target.hpRate();

I was wondering how do I change the success rate to be based on the enemy's TP instead of BP(Boost Points)... I tried changing user.bp to target.tp but that was basically making it guranteed if the user had no tp somehow... I basically want it where, the more tp the enemy has, the higher the chance of sucess. if anyone can point me in the right direction, I'd be thankful... have a great day everyone.
I'm using the steal move from the Octopath Demo by Olivia and there's this following line in a Before Eval...


var rate = [0.05, 0.33, 0.67, 1.0][user.bp] + 1 - target.hpRate();

I was wondering how do I change the success rate to be based on the enemy's TP instead of BP(Boost Points)... I tried changing user.bp to target.tp but that was basically making it guranteed if the user had no tp somehow... I basically want it where, the more tp the enemy has, the higher the chance of sucess. if anyone can point me in the right direction, I'd be thankful... have a great day everyone.
I believe under the covers, enemies may be battlers but I don't think they ever really have or generate TP. At least, in my testing efforts of trying to allow enemies to utilize TP, they never did.

I'm not familiar with the plugin you're using (you should probably link it, too), but I wager that is a good place to start.
To explain the original code: [0.05, 0.33, 0.67, 1.0][user.bp] means "return the value at index user.bp from the array" (the first value is at index 0). I.e. when BP = 0, the result is 0.05; when BP = 1, the result is 0.33; etc.

Some possible options:
  1. You could use [a multiple of] target.tpRate() instead, e.g.
    JavaScript:
    var rate = target.tpRate() + 1 - target.hpRate();
    Like hpRate, tpRate returns a value from 0 (0% of max TP) to 1 (100%).
  2. If you want to use a tiered formula like the original example, you could try something like this instead:
    JavaScript:
    var rate = [0.05, 0.33, 0.67, 1.0][Math.floor(3 * target.tpRate())] + 1 - target.hpRate()
    Math.floor rounds down to the nearest integer, transforming the TP% value into the appropriate "tier" index. In this case, for targets at full HP (i.e. target.hpRate() is 1), I think this should return:
    • 0.05 for 0% <= TP < 33%
    • 0.33 for 33% <= TP < 66%
    • 0.67 for 66% <= TP < 100%
    • 1.00 for TP = 100%

  3. If you want a more complex tier structure then you might want to consider just making a big if...else block, e.g.
    JavaScript:
    var rate = 1 - target.hpRate();       // value without TP contribution
    if (target.tpRate() < 0.2) {          // if TP < 20%...
      rate += 0.05;                       // ...then add 0.05 to rate
    } else if (target.tpRate() < 0.5) { 
      rate += 0.2;
    } else {
      // etc
    }
To explain the original code: [0.05, 0.33, 0.67, 1.0][user.bp] means "return the value at index user.bp from the array" (the first value is at index 0). I.e. when BP = 0, the result is 0.05; when BP = 1, the result is 0.33; etc.

Some possible options:
  1. You could use [a multiple of] target.tpRate() instead, e.g.
    JavaScript:
    var rate = target.tpRate() + 1 - target.hpRate();
    Like hpRate, tpRate returns a value from 0 (0% of max TP) to 1 (100%).

  2. If you want to use a tiered formula like the original example, you could try something like this instead:
    JavaScript:
    var rate = [0.05, 0.33, 0.67, 1.0][Math.floor(3 * target.tpRate())] + 1 - target.hpRate()
    Math.floor rounds down to the nearest integer, transforming the TP% value into the appropriate "tier" index. In this case, for targets at full HP (i.e. target.hpRate() is 1), I think this should return:
    • 0.05 for 0% <= TP < 33%
    • 0.33 for 33% <= TP < 66%
    • 0.67 for 66% <= TP < 100%
    • 1.00 for TP = 100%

  3. If you want a more complex tier structure then you might want to consider just making a big if...else block, e.g.
    JavaScript:
    var rate = 1 - target.hpRate();       // value without TP contribution
    if (target.tpRate() < 0.2) {          // if TP < 20%...
      rate += 0.05;                       // ...then add 0.05 to rate
    } else if (target.tpRate() < 0.5) {
      rate += 0.2;
    } else {
      // etc
    }
I feel like this is exactly what I need... but for some reason, no matter what the rate is of the enemy's tp... it always fails to steal anything from them. basically in my game, enemies gain tp when hit and once it reaches full, they get stunned. then tp drops by 50 each turn till it's back to 0. so I caught the enemy while it was still 100 and even then the stealing failed. but I feel what you've told me should work based on what I do and don't know about formulas.
Can you paste the exact code you're currently using?
Code:
<Before Eval>
var text = '<CENTER>';
if (!target._isItemStolen && target.isEnemy()) {
    var rate = [0.25, 0.50, 0.80, 1.0][Math.floor(3 * target.tpRate())] + 1 - target.hpRate();
    var items = [];
    for (var i = 0; i < target.enemy().dropItems.length; i++) {
        var dropItem = target.enemy().dropItems[i];
        if (dropItem.kind === 1) {
            items.push($dataItems[dropItem.dataId]);
        } else if (dropItem.kind === 2) {
            items.push($dataWeapons[dropItem.dataId]);
        } else if (dropItem.kind === 3) {
            items.push($dataArmors[dropItem.dataId]);
        }
    }
    if (Math.random() < rate && items.length > 0) {
        target._isItemStolen = true;
        SoundManager.playUseItem();
        var item = items[Math.floor(Math.random() * items.length)];
        $gameParty.gainItem(item);
        text += 'Stole ' + item.name;
    } else {
        text += 'Failed to steal';
    }
} else {
    text += 'Already stolen'
}
text += ' from ' + target.name() + '!';
BattleManager.addText(text, 60);
</Before Eval>

this is the original code, with the bp changed to what was suggested above. I changed the tier rates a bit, but that's about it.
After the var rate line, add
console.log(rate);

And see what the console prints.
After the var rate line, add
console.log(rate);

And see what the console prints.
it said 0.25 and magically... it's working. I think I must've typed it in wrong before. thanks tho, I didn't realize you could use the console.log in the middle of an eval like that.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/success-rate-based-on-targets-tp-amount.136159/