Status
Not open for further replies.

zerobeat032

Cloaked Wanderer...
Veteran
Joined
Mar 28, 2014
Messages
357
Reaction score
588
First Language
English
Primarily Uses
RMMV
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.
 

Jragyn

JABS codemonkey
Veteran
Joined
Aug 14, 2012
Messages
165
Reaction score
143
First Language
English
Primarily Uses
RMMZ
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.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,411
Reaction score
1,821
First Language
EN
Primarily Uses
RMMZ
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
    }
 

zerobeat032

Cloaked Wanderer...
Veteran
Joined
Mar 28, 2014
Messages
357
Reaction score
588
First Language
English
Primarily Uses
RMMV
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.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,006
Reaction score
2,274
First Language
English
Primarily Uses
RMMV
Can you paste the exact code you're currently using?
 

zerobeat032

Cloaked Wanderer...
Veteran
Joined
Mar 28, 2014
Messages
357
Reaction score
588
First Language
English
Primarily Uses
RMMV
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.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,006
Reaction score
2,274
First Language
English
Primarily Uses
RMMV
After the var rate line, add
console.log(rate);

And see what the console prints.
 

zerobeat032

Cloaked Wanderer...
Veteran
Joined
Mar 28, 2014
Messages
357
Reaction score
588
First Language
English
Primarily Uses
RMMV
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.
 

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,870
Reaction score
4,813
First Language
English
Primarily Uses
RMMZ

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.

 
Status
Not open for further replies.

Latest Threads

Latest Posts

Latest Profile Posts

Screenshot-2021-05-02-at-15-07-54.png


Tivadar will help you travel to distant places in Eniko: Ghosts Of Grace

Finally done with the school project, here's the raw video of it. o_O :smile:
Can February March? No, but April May.

Forum statistics

Threads
111,173
Messages
1,058,959
Members
144,419
Latest member
harry30705
Top