Custom/Dynamic Action Speed

It's actually really strange that there's no plugins available to notetag in a custom formula for Action Speed/Invocation. Right now it's based solely on hard numbers, but I'd like to base it on the caster's MAT (Higher MAT = Better mage = Shorter Cast time)
I've been googling for hours to find this plugin and have yet to come across anything. I'm using Yanfly's Battle Engine Core and CTB, and I've attempted messing around with that code, but I dont quite get it well enough to write the code. myself.
well, then it would be a matter of finding, on one hand, the actual call to the caster's MAT, and on the other hand, the call to the action speed, from the skill's invocation, and crossing the two.
it's not a coding problem, it's a comprehension problem.
call it javascript, call it ruby, or call it assembler, *the call to the function* is always *the call to the function*, and *the assignment of the variable* is always *the assignment of the variable*
you can *assign the result of the call to the function, to the variable*, if you know where the function is, and where the variable is.

literally take two wires and cross them.
it will either short out, or not.... if it shorts out, you just uncross them
well, then it would be a matter of finding, on one hand, the actual call to the caster's MAT, and on the other hand, the call to the action speed, from the skill's invocation, and crossing the two.
it's not a coding problem, it's a comprehension problem.
call it javascript, call it ruby, or call it assembler, *the call to the function* is always *the call to the function*, and *the assignment of the variable* is always *the assignment of the variable*
you can *assign the result of the call to the function, to the variable*, if you know where the function is, and where the variable is.

literally take two wires and cross them.
it will either short out, or not.... if it shorts out, you just uncross them
I've been attempting this. The speed is calculated in Yanfly's Battle Engine Core

The notetag is defined on line 1251

Code:
var note2 = /<(?:SPEED):[ ]([\+\-]\d+)>/i;

And the notetag is normally handled with just an integer on line 1280

Code:
else if (line.match(note2)) {
        obj.speed = parseInt(RegExp.$1);
}

Right now I'm trying to create a space in that <Speed: > section that will execute code. By running

Code:
else if (line.match(note2)) {
        obj.speed = int(eval(line.substring(line.indexOf(':')+2, line.indexOf('>')))));
      }

with my notetag reading this just to test

Code:
<speed:-999;>
This simply doesn't do anything, and I can't quite figure out why. The program should still be getting an integer, and I can't quite figure out why it's not working. I'm not getting an error or anything, the program is just ignoring it.

It SHOULD be going to the ':' (inclusive) and then moving the cursor forward by two (to avoid the +/-), getting to "999;" and evaluating that code as an integer.
<SPEED: _blank_ (sign)value>
capital, blank, sign.
<SPEED: _blank_ (sign)value>
capital, blank, sign.
So like

<SPEED: -(0+999);>

?

Or do I need to actually type in _blank_?
....and no semicolon!
....and no semicolon!
Nope
It's still not catching the code at all
Code:
var note2 = /<(?:SPEED):[ ]([\+\-]\d+)>/i;

And the notetag is normally handled with just an integer on line 1280

Code:
else if (line.match(note2)) {
        obj.speed = parseInt(RegExp.$1);
}
Roughly speaking:
  • The first is a regular expression that expects the format <speed: ±number> and, incidentally, is case insensitive due to the "i" global flag. The capture group (in brackets) is ±number.
  • The second part says "if this line matches that format, set this item's action speed to the first captured value". The "speed" bit is recognised as a match but not captured due to the ?: syntax (check link above for details).
So both these parts will need changing if you want to use a string eval instead. (I haven't tested any of the following, it's all theory; fingers crossed and apologies if it doesn't work. 😅) Try overriding the first part with this:
Code:
var note2 = /<(?:SPEED):[ ](.*)>/i
I.e. swap the digit capture group for a string of arbitrary length. Then the second part:
Code:
} else if (line.match(note2)) {
        obj.speed = String(RegExp.$1);
}
Now (unless you want to evaluate its value right when the game loads, rather than every time the skill is used) you'll need a third part for the eval. I think it'd be this line under Game_Action.prototype.speed:
Code:
    if (this.item()) speed += this.item().speed;
Try changing it to:
Code:
    if (this.item()) speed += eval(String(this.item().speed));
I put a String() in there because eval expects a string and default speed values are numbers.

Hope that helps clear things up a bit! 🙏

Edit: I'd also advise against editing the actual plugin. Nothing wrong with it per se (I think Yanfly's OK with it) but any update will overwrite your changes. It's generally better to make a new plugin with the appropriate function overrides (assuming you know how).
is case insensitive due to the "i" global flag

:oops:
I feel like a greenhorn...

I never used the (?: ) group that way, I thought it would grab things literally.
also, I'm so not a fan of yanfly, or any kind of notetag-only plugin.
getting *them* to work with *own* configurations is always a mess,.... might as well design a new plugin altogether, specifically for it.
nothing like tailor-made stuff.
:oops:
I feel like a greenhorn...

I never used the (?: ) group that way, I thought it would grab things literally.
Ehh, you're probably still more experienced in this than me. The only reason I thought to look for the i at the end was because I know Yanfly's notetags aren't usually case-sensitive. xP

I'm still pretty new to regular expressions, but it looks like non-capturing groups are great for grabbing things in a specific context. =)
also, I'm so not a fan of yanfly, or any kind of notetag-only plugin.
getting *them* to work with *own* configurations is always a mess,.... might as well design a new plugin altogether, specifically for it.
nothing like tailor-made stuff.
Fair points, but the flexibility can save time and it's good learning material! ^_^
Roughly speaking:
  • The first is a regular expression that expects the format <speed: ±number> and, incidentally, is case insensitive due to the "i" global flag. The capture group (in brackets) is ±number.
  • The second part says "if this line matches that format, set this item's action speed to the first captured value". The "speed" bit is recognised as a match but not captured due to the ?: syntax (check link above for details).
So both these parts will need changing if you want to use a string eval instead. (I haven't tested any of the following, it's all theory; fingers crossed and apologies if it doesn't work. 😅) Try overriding the first part with this:
Code:
var note2 = /<(?:SPEED):[ ](.*)>/i
I.e. swap the digit capture group for a string of arbitrary length. Then the second part:
Code:
} else if (line.match(note2)) {
        obj.speed = String(RegExp.$1);
}
Now (unless you want to evaluate its value right when the game loads, rather than every time the skill is used) you'll need a third part for the eval. I think it'd be this line under Game_Action.prototype.speed:
Code:
    if (this.item()) speed += this.item().speed;
Try changing it to:
Code:
    if (this.item()) speed += eval(String(this.item().speed));
I put a String() in there because eval expects a string and default speed values are numbers.

Hope that helps clear things up a bit! 🙏

Edit: I'd also advise against editing the actual plugin. Nothing wrong with it per se (I think Yanfly's OK with it) but any update will overwrite your changes. It's generally better to make a new plugin with the appropriate function overrides (assuming you know how).

I'm actually not very familiar with Javascript, I'll look int overriding the functions.
Right now I just saved a backup of the original and I've been playing around with my edits.

I inserted your code, but the game is still completely ignoring the Speed.
Here's what I have right now

DataManager.processBECNotetags2
Spoiler
Code:
DataManager.processBECNotetags2 = function(group) {
  var note1 = /<(?:ACTION COPY):[ ](.*):[ ]*(\d+)>/i;
  //var note2 = /<(?:SPEED):[ ]([\+\-]\d+)>/i;
  var note2 = /<(?:SPEED):[ ](.*)>/i
  var note3 = /<(?:DISPLAY NAME|DISPLAY TEXT):[ ](.*)>/i;
  var note4 = /<(?:DISPLAY ICON):[ ](\d+)>/i;
  var evalMode = 'none';
  var spellSpeed = '';
  var line = "";
  for (var n = 1; n < group.length; n++) {
    var obj = group[n];
    var notedata = obj.note.split(/[\r\n]+/);

    obj.battleDisplayText = obj.name;
    obj.battleDisplayIcon = obj.iconIndex;

    for (var i = 0; i < notedata.length; i++) {
      line = notedata[i];
      if (line.match(note1)) {
        var text = String(RegExp.$1).toUpperCase();
        var target;
        if (['I', 'ITEM'].contains(text)) {
          target = $dataItems[parseInt(RegExp.$2)];
        } else if (['S', 'SKILL'].contains(text)) {
          target = $dataSkills[parseInt(RegExp.$2)];
        }
        if (target) {
          obj.setupActions = target.setupActions.slice();
          obj.wholeActions = target.wholeActions.slice();
          obj.targetActions = target.targetActions.slice();
          obj.followActions = target.followActions.slice();
          obj.finishActions = target.finishActions.slice();
        }
      } else if (line.match(note2)) {
        obj.speed = String(RegExp.$1);
      } else if (line.match(note3)) {
        obj.battleDisplayText = String(RegExp.$1);
      } else if (line.match(note4)) {
        obj.battleDisplayIcon = parseInt(RegExp.$1);
      } /*else if (line.match(/<(?:SPELL SPEED)>/i)) {
          obj.spellSpeed = 0;
          evalMode = 'speed eval';
      } else if (line.match(/<\/(?:SPELL SPEED)>/i)) {
          evalMode = 'none';
      }    else if (evalMode === 'speed eval') {
          obj.spellSpeed = eval(line);
      }*/
     
    }
  }
};

Game_Action.prototype.speed
Spoiler
Code:
Game_Action.prototype.speed = function() {
    var user = this.subject(); var a = user;
    var maxhp = user.mhp; var mhp = user.mhp; var hp = user.hp;
    var maxmp = user.mmp; var mmp = user.mmp; var mp = user.mp;
    var maxtp = user.maxTp(); var mtp = user.maxTp(); var tp = user.tp;
    var atk = user.atk; var def = user.def; var mat = user.mat;
    var int = user.mat; var mdf = user.mdf; var res = user.res;
    var agi = user.agi; var luk = user.luk;
    var code = Yanfly.Param.BECActionSpeed;
    try {
      var speed = eval(code);
    } catch (e) {
      var speed = 0;
      Yanfly.Util.displayError(e, code, 'ACTION SPEED FORMULA ERROR');
    }
    if (this.item()) speed += eval(String(this.item().speed));
    if (this.isAttack()) speed += this.subject().attackSpeed();
    return speed;
};
Not sure why that would be, just literally copy+pasted what you posted and it seems to work for me... 👋

Did you save both the plugin and your project after making edits (and before testing)? If not, do so and see if that makes a difference.

Does any error or warning message appear in the console (press F8 during playtest to view) when testing this?

What value(s) did you try in the notetag? I've tested with these two:
Code:
<speed: console.log('testing')>
<speed: user.luk * 5>
The first one is just to make sure the eval is running; the second one should set the skill speed to 5 times the skill user's luck. Both seem to work as expected for me. 😅
replace this line
var code = Yanfly.Param.BECActionSpeed;

with a random string (var code = "sdgadfgasdfsdgs").
that should trip the error catch and return speed = 0.
if that's the case, then you'll know this
Yanfly.Param.BECActionSpeed
is not working.

that's what you have to fix.

whenever you see that a program has an error catch, trip it.
it's there for a reason.
Not sure why that would be, just literally copy+pasted what you posted and it seems to work for me... 👋

Did you save both the plugin and your project after making edits (and before testing)? If not, do so and see if that makes a difference.

Does any error or warning message appear in the console (press F8 during playtest to view) when testing this?

What value(s) did you try in the notetag? I've tested with these two:
Code:
<speed: console.log('testing')>
<speed: user.luk * 5>
The first one is just to make sure the eval is running; the second one should set the skill speed to 5 times the skill user's luck. Both seem to work as expected for me. 😅

So I tried it without the CTB, and it works fine, prints to the console when I use the skill (That's a really great testing trick btw, thanks!). But with the CTB on it completely ignores it. The eval is never run. Normally (using the vanilla script w/ hard numbers) the CTB works fine with the tags,

replace this line


with a random string (var code = "sdgadfgasdfsdgs").
that should trip the error catch and return speed = 0.
if that's the case, then you'll know this
Yanfly.Param.BECActionSpeed
is not working.

that's what you have to fix.

whenever you see that a program has an error catch, trip it.
it's there for a reason.
I'm confused, how would this be relative to the speed issue?
I'm confused, how would this be relative to the speed issue?

the formula for speed is the result of that call to that yanfly function, not what you bring up from the notetag.
that call, passes through that error handler.
if you're recieving no error and your formula doesn't work, that means that yanfly function is either not working, or returning zero.
use the error handler to isolate that function from the code.
if the error handler detects the error, that meanst that function is not giving out an error.... so, look into that function in case *it* is returning zero.

that's how you debug code you don't know.
the formula for speed is the result of that call to that yanfly function, not what you bring up from the notetag.
that call, passes through that error handler.
if you're recieving no error and your formula doesn't work, that means that yanfly function is either not working, or returning zero.
use the error handler to isolate that function from the code.
if the error handler detects the error, that meanst that function is not giving out an error.... so, look into that function in case *it* is returning zero.

that's how you debug code you don't know.
It spits out an error for sure if I change it. So that's working.

Pretty much everything works until I plug in the CTB, then it just ignores the tag entirely

I went through the CTB and I didn't find any overrides for the speed notetag, as the one from BEC works just fine with the CTB in order to set actors back. It doesn't even print to the console with the CTB on though
Oh. Hmm...

Are you sure none of the "Lunatic Mode" notetags mentioned on the plugin page suit your purposes? Maybe double-check just in case. xP

If not: I'm not familiar with Yanfly's CTB plugin, but from the code it looks like it just uses flat speed values, rather than invoking the speed function. Perhaps you could try editing the CTB plugin: search and replace all 6 occurrences of item.speed with item.speed() and maybe that'll help? 😅
Oh. Hmm...

Are you sure none of the "Lunatic Mode" notetags mentioned on the plugin page suit your purposes? Maybe double-check just in case. xP

If not: I'm not familiar with Yanfly's CTB plugin, but from the code it looks like it just uses flat speed values, rather than invoking the speed function. Perhaps you could try editing the CTB plugin: search and replace all 6 occurrences of item.speed with item.speed() and maybe that'll help? 😅
I was using the lunatic method to do it through two separate skills (one skill would invoke the casting state, send the user back by the correct number of turns, then lock them out of all skills other than the one they wanted to use) but It's rather convuluted, and doesn't show the user WHERE in the battle order they'll end up, which I'd say is key to this battle system. Using the <Speed: X> method does this.

I tried replacing item.speed with item.speed() and get "Error String is not a function"
Looked into it and read that since speed and speed() have the same name it might be accessing the wrong data, so I went and tried writing a new function that would return the speed() function, then replaced all instances of item.speed in the CTB with item.QSpeed.
Code:
Game_Action.prototype.QSpeed = function() {
    return this.speed();
};
But this gave me "Undefined is not a function"
You're using CTB by yanfly.
From the sound of what you want. What you want to do is use ATB by Yanfly and make it where there's no charge up to the skill and then make it where user's mat affects how fast the the charge is after the skill is cast.

The way ATB works is before you input the action you want, you have a gauge that fills up, you input the action; then the gauge fills up again and you cast the skill. CTB systems made in RMMV are based off of ATB systems, but instead of having you wait for a gauge to fill up either before you input a skill or before you cast, instead everything is instant. What you want is for the first part waiting for to input a skill to be instant while the second part waiting for a gauge to be manipulated. So what you should do as I said before is use ATB.


And then in the plugin parameters(For AT😎 do this:
Per Tick: user.mat
Full Gauge: 1 or 0
Charge Gauge: x
Where x is the max amount of that the magic attack stat can be. If it's 2 different amounts for enemies and actors then do this:
user.isActor() ? x : y;
where x is the max amount of magic attack for the actors and y is the max amount for enemies.

Now what's going to happen is the higher the mat stat the faster you'll cast and the lower the mat stat the slower you cast, until you've reach max stat where it's now instant.
You're using CTB by yanfly.
From the sound of what you want. What you want to do is use ATB by Yanfly and make it where there's no charge up to the skill and then make it where user's mat affects how fast the the charge is after the skill is cast.

The way ATB works is before you input the action you want, you have a gauge that fills up, you input the action; then the gauge fills up again and you cast the skill. CTB systems made in RMMV are based off of ATB systems, but instead of having you wait for a gauge to fill up either before you input a skill or before you cast, instead everything is instant. What you want is for the first part waiting for to input a skill to be instant while the second part waiting for a gauge to be manipulated. So what you should do as I said before is use ATB.


And then in the plugin parameters(For AT😎 do this:
Per Tick: user.mat
Full Gauge: 1 or 0
Charge Gauge: x
Where x is the max amount of that the magic attack stat can be. If it's 2 different amounts for enemies and actors then do this:
user.isActor() ? x : y;
where x is the max amount of magic attack for the actors and y is the max amount for enemies.

Now what's going to happen is the higher the mat stat the faster you'll cast and the lower the mat stat the slower you cast, until you've reach max stat where it's now instant.
That's close to what I'm talking about, but not quite there.

So normally AGI would determine how fast you move.
Selecting normal attacks would be instant, then you go back to your space in the turn order
Some skills might have a charge time, based on different stats and varriables.
Spells have a charge time that's based on your mat and the difficulty of the spell.

E.g. "Fireball" would have a much shorter cast time than "Meteor Shower" because it's not as complex of a spell.

At some point if a character's MAT was high enough, the eval used to determine the spell's charge time would return a value that is < 1, allowing the to cast this spell without any sort of charge up time, but that's on a per-spell basis. A high level mage could likely cast "Fireball" with no cast time, but still only have a reduced cast time for "Meteor shower"

The other question I'd have is, does the ATB have a turn order window? Never been a fan of the gagues

Original thread: https://forums.rpgmakerweb.com/threads/custom-dynamic-action-speed.95341/