MV Referring to specific objects in plugin code

My question is: can I refer to a specific object like $gameActors.actor(x) in plugin code? This might be a dumb question but I've not messed around with plugin code before much at all, and I'm not very familiar with its structure. While I've examined a bunch of plugin code, I've never seen anything that specifically refers to an object in the manner that I want to. So is that possible?

For context, what I want to do is to modify the gainTp method of game_Battler so that whenever any battler gains tp, it checks if the battler who gained tp is a specific actor, and then runs a custom script if true.
Yeah, add like:

if (this.isActor() && this.actorId() === X) {
STUFF
}
For this use case, you want to write a plugin that aliases the original method. That means, the original code runs as usual, and your custom code is "attached".

Code:
(function() {

const _GameActor_gainTp = Game_Actor.prototype.gainTp;
Game_Actor.prototype.gainTp = function(value) {
  _GameActor_gainTp.call(this, value);
  
  // your custom code starts here
  if (this.actorId() == 1) {
    // whatever
  }
}

})();

The (function() { ... })() structure (IIFE) wraps your code and makes it safer not to crash your game. It's absolutely worth learning about it, but for the beginning, I think it's okay to just use it.
@Aerosys

Yes, I knew about not directly modifying the base code and attaching it as a new plugin. Since I don't know how exactly to do aliasing, I was planning on modifying a plugin I already have that adds onto the tpgain method but thanks for your code! It definitely helps me do it a lot easier.
I was planning on modifying a plugin I already have that adds onto the tpgain method but thanks for your code! It definitely helps me do it a lot easier.
another benefit of making your own plugin is that it makes future troubleshooting easier. if you introduce a change that causes an error or crash, its easier to look into it as you can disable your changes. and by not modifying the other plugin, you dont need to go find a fresh copy in order to make sure if the problem was something you did or not.

Since I don't know how exactly to do aliasing
its important to learn about it when you can. when you have multiple plugins that target the same functions, overwriting immediately presents a few constraints and issues that are avoided by aliasing.

Original thread: https://forums.rpgmakerweb.com/threads/referring-to-specific-objects-in-plugin-code.180073/