MZ Specifying opening TP

I'm trying to replicate one of my mechanics concerning TP.

When TP is not preserved, the engine allocates a random amount of TP at the beginning of battle.
I would like this always to be between 11-18 so that the player is guaranteed to start with something.
In addition, whilst I'm happy with TP being generated by being hit, I would like the amount generated each turn to be based on the actor's AGI, not on damage dealt.

Is this possible in MZ?
Thank you.

EDIT
In case it helps (it probably doesn't) I did the first part with a small edit to the method 'Initialise TP' in the default script 'Game Battler'. I now don't remember how I got the TP to increase based on agility.
Hey there.

Both parts of your request are fairly easy to implement.
You will need a plugin for it, however.

For now, I can quickly write a snippet to hard code the request you wanted.
(If anyone else would want something like this, I could expand it.)

All that said, I'll need to know exactly how you want AGI to affect TP growth.
If you want to randomly initialize TP between 11 and 18, then you'd want to put this function into a .js file and add it to your project as a plugin:
JavaScript:
Game_Battler.prototype.initTp = function() {
    this.setTp(Math.randomInt(8) + 11);
};

For the increasing based on agility thing, I can't really tell you what to do, since I don't know the exact formula that you want to use, but these are the two relevant functions (they can be found in rmmz_objects.js):
JavaScript:
Game_Battler.prototype.onDamage = function(value) {
    this.removeStatesByDamage();
    this.chargeTpByDamage(value / this.mhp);
};

Game_Battler.prototype.chargeTpByDamage = function(damageRate) {
    const value = Math.floor(50 * damageRate * this.tcr);
    this.gainSilentTp(value);
};

The first function calls the next function, while passing (damage / max HP) to it. The next function uses that value to calculate an amount of TP, and also adds that amount of TP to the battler. You would need to edit them to reflect whatever it is that you want to do. Really, you could get away with just editing the second one... but I personally would probably get some kind of OCD issue from having a function named chargeTpByDamage that doesn't actually utilize damage when deciding how much TP to charge, and that would generally be considered an "un-clean" thing to do.
In addition to Arthran's answer, depending on how complex your system is, VisuStella has an Enhanced TP System plugin that allows you to configure starting rate and what happens on damage via plugin parameters (you could reference Agi in there).

It also lets you have different methods of gaining TP and assign them on a per-actor/enemy basis.
@Maliki79 and @Arthran
Thank you both for your quick responses.
For the AGI increase, the purpose is to ensure that the player is not penalised if an actor has to use a turn to e.g. use an item. As I mentioned in my opening post, to my embarrassment I can't remember now how I did it, so the formula itself has vanished into the mist. I do know that it tended to produce an increase of around 8 - 10 per turn. However, in the light of ATT_Turan's reply, it seems that it won't be necessary to write something specific for this.
Once again, thank you for your replies.

@ATT_Turan Thank you for your encylopedic knowledge of what's out there. I think the VS plugin is going to be the option I pick as, having had a quick look at it, it also does a couple of other things that I've wanted to do for a long time
@Kes
Actually, now that I re-read your post, I see that the latter part of my answer was incorrect anyway. I misunderstood and thought that you wanted to make it so that when an actor gets hit, they gain TP based on their agility, rather than based on how much damage was done to them.

Original thread: https://forums.rpgmakerweb.com/threads/specifying-opening-tp.148987/