MV Scripting Help with an Actor Fusion System

First time post, apoligies if this is the wrong subforum. I'm attempting to create a system that allows the player to choose two actors and fuse them together to create a new stronger actor. Actors that ain't the MC level up slower; so the idea is the player would need to do this to not risk party members falling behind in levels and stats. Similar to the SMT series. Found this video by DriftWood and it's more or less what I was looking for but needed to make some changes to make it fit what I'm looking for:


So I basically took the script in his video, put it into a js. file to use as a funtion call (mainly because I use MV not MZ, which has a line limit). Got rid of the conditional branches Drift used in favour of using SumRandomDudes Actor Select plugin (http://sumrndm.site/actor-select/) to allow the player to select which ever combination of actors they wish to fuse together.

And here's where I'm stuck: SRD's plugin allows player to select actors and the actor ID get's asigned to a variable of the users choosing. How do I go about incorporating that into this script?:

Code:
PerformFusion = function() {
//Take stats of the fodder character and get percentage
var fuseChar = $gameActors.actor(2); //I want fuseChar change depending on the variable assigned via SRDs Plugin
var fusePercent = 0.20; //20%
var fuseMHP = fuseChar.mhp * fusePercent;
var fuseMMP = fuseChar.mmp * fusePercent;
var fuseATK = fuseChar.atk * fusePercent;
var fuseDEF = fuseChar.def * fusePercent;
var fuseMAT = fuseChar.mat * fusePercent;
var fuseMDF = fuseChar.mdf * fusePercent;
var fuseAGI = fuseChar.agi * fusePercent;
var fuseLUK = fuseChar.luk * fusePercent;

//Add those states into the Vassel character
var newChar = $gameActors.actor(1); //Same as above only with Actor 1
newChar.addParam(0,fuseMHP);
newChar.addParam(1,fuseMMP);
newChar.addParam(2,fuseATK);
newChar.addParam(3,fuseDEF);
newChar.addParam(4,fuseMAT);
newChar.addParam(5,fuseMDF);
newChar.addParam(6,fuseAGI);
newChar.addParam(7,fuseLUK);

//Remove fodder character from the party
$gameParty.removeActor(2); //Same as the above instance of Actor2. To remove them from the party after this funtion is called
}

I'm no scripter but this should seem pretty simple to do, no? It would make Driftwoods system way more flexable than having to rely on having conditional branches for every possible party combination. Hope I explained this well, if anymore clarification is needed feel free to ask.
I only skimmed this but if I understood correctly, replace the actor id (currently 2) with whatever variable you use SRD plugin to store the actor id. Like $gameActors.actor($gameVariables.value(X))
I only skimmed this but if I understood correctly, replace the actor id (currently 2) with whatever variable you use SRD plugin to store the actor id. Like $gameActors.actor($gameVariables.value(X))
This worked! Thanks man. Sorry for late reply.
as a small head-up as options. 0.20 can also be written as 0.2 (safety) or shorter as .2
but 0.20 is best readable, but I mostly go for 0.2 for safety reasons rather than .2.

but another way to make it slightly better that you can use as variable (if not fixed)
or possible.

JavaScript:
PerformFusion = function(actorId) {
//Take stats of the fodder character and get percentage
var fuseChar = $gameActors.actor(actorId);

so you can remove actor ID from x position if exist 🙂
so if you add a bit more like:

JavaScript:
PerformFusion = function(actorId = 2) {

//Take stats of the fodder character and get percentage
var fuseChar = $gameActors.actor(actorId);

so this way, actorId can be omitted. (its optional, but also bit more powerful
if they have different actors 🙂 or set a percentage as well like (actorId =2, percent = 0.2)

so both could be omitted or both can be used 😉
Here's a way to simplify and also adding on to what RL and SD posted - easier to see the code and reduces the need of defining new variables that are only used once while maintaining readability:
JavaScript:
/*
Setting the method parameters to default 2, 1, and .2 follows your specific needs
Use script call PerformFusion() for the default values to target:
  fuse actor 2, new actor 1, and 20% of their params
    -or-
PerformFusion(5, 3, .4) to target:
  fuse actor 5, new actor 3, and 40% of their params
Params by number:
  0 = mhp, 1 = mmp, 2 = atk, 3 = def,
  4 = mat, 5 = mdf, 6 = agi, 7 = luk
*/

function PerformFusion(fuseId = 2, newId = 1, fusePercent = .2) {
  const fuseChar = $gameActors.actor(fuseId);
  const newChar  = $gameActors.actor(newId);
  for (let i = 0; i < 8; i++) {
    newChar.addParam(i, fuseChar.param(i) * fusePercent);
  }
  $gameParty.removeActor(fuseId);
}

You can now do:
Code:
PerformFusion($gameVariables.value(1), 2, .3);
to get fuse id from variable 1, actor 2, and 30%.

Original thread: https://forums.rpgmakerweb.com/threads/scripting-help-with-an-actor-fusion-system.178664/