Copy Spell

Aloha Everyone! I was wondering if one can implement a copy spell, which has the caster copy any spell a monster has.
Thank you for your time.
Not too long ago I tested an event that allowed you to steal a skill from an enemy. I would think that is very similar to copying a skill.

If you don’t get a solution, I will look when I can get on my computer and post screen shots.

EDIT: Ok, so I found what I had been working on and it is woefully incomplete. I only tested the part where I could steal a skill, but there is a lot missing.

Essentially, I created a Skill for the Steal Skill ability and made a new type for that Skill (Learning). When that Skill is used in combat, it calls a common event the uses a random result and conditional branches to see if the Actor can steal a skill from the enemy. If successful, it uses the Event Command of Change Skill -> Learn Skill.

There is a lot more that I need to add to the system to cover all the contingencies, but that is the essential core.

Create a Skill to use in combat, call a Common Event, determine how you want to do the steal or copy skill part. I.E. see choices of the enemy skills to choose from or random determination. And you need checks to make sure the Actor can actually learn that Skill Type and that they don't already know the skill.

I will go back and work on it when I have time, but maybe this helps you a little.
To start, the object structure is going to look something like
$dataEnemies[*some enemy id*].actions[*some action index*].skillId

It's a bit tricky because an enemy might have, but not have, an action associated with a skill based on conditions. So it might be easier if you just write a specific skill id in the enemy's notetag like <skillCopy: 15>

So then you'd retrieve it with $dataEnemies[*some enemy id*].meta.skillCopy.

And then...idk, use a script call like $gameActors.actor(*some actor Id*).learnSkill(^that thing^)

You didn't say if you wanted to permanently learn this skill. Or make it a one time use. Like an "empath" power that stops working once the target is dead. Does an actor use a turn to assimilate the skill, or is it a shot in the dark? Does the enemy have to use the skill first? Does the actor need to be hit by it?

There are many options. The skill's damage formula can include a function for the targeted actor to learn the skill id. Like that script call above, but with with a set of conditions probably.

You can try having the enemy skill inflict a hidden state, that is only susceptible to one with a certain trait. That'll grant a skill or skill type temporarily.
^that's actually really fun. I've had the K.O. state add a "reincarnate" skill before

Something like that would potentially allow a skill select window. Maybe just "enemy skill" or a skill type for every enemy. Using battle events you can make a passive "copy" ability that simply adds and removes the viable skills at the start of battle. To be made accessible however you see fit. I recommend hidden states if the skills are not permanent.
To start, the object structure is going to look something like
$dataEnemies[*some enemy id*].actions[*some action index*].skillId

It's a bit tricky because an enemy might have, but not have, an action associated with a skill based on conditions. So it might be easier if you just write a specific skill id in the enemy's notetag like <skillCopy: 15>

So then you'd retrieve it with $dataEnemies[*some enemy id*].meta.skillCopy.

And then...idk, use a script call like $gameActors.actor(*some actor Id*).learnSkill(^that thing^)

You didn't say if you wanted to permanently learn this skill. Or make it a one time use. Like an "empath" power that stops working once the target is dead. Does an actor use a turn to assimilate the skill, or is it a shot in the dark? Does the enemy have to use the skill first? Does the actor need to be hit by it?

There are many options. The skill's damage formula can include a function for the targeted actor to learn the skill id. Like that script call above, but with with a set of conditions probably.

You can try having the enemy skill inflict a hidden state, that is only susceptible to one with a certain trait. That'll grant a skill or skill type temporarily.
^that's actually really fun. I've had the K.O. state add a "reincarnate" skill before

Something like that would potentially allow a skill select window. Maybe just "enemy skill" or a skill type for every enemy. Using battle events you can make a passive "copy" ability that simply adds and removes the viable skills at the start of battle. To be made accessible however you see fit. I recommend hidden states if the skills are not permanent.
Screenshot_20230207_021837.png
Screenshot_20230207_021956.png
Screenshot_20230207_022056.png

Am I on the right track?
Ok. Ok. Doing it this way, you'll want the actual ID of the enemy you targeted. Like $dataEnemies[3] -- that'd be the 3rd enemy in then Enemy database.
But the actor can potentially target anyone. Right? How do you get the target's ID number?

Luckily MZ keeps "last action" data which you can set using [control variables]
Personally I think using the variable event commands is clunky process. It's easier to just reference the data array directly with the script.
$gameTemp._lastActionData = [0-Last Skill, 1-Last Item, 2-Actor ID Act, 3-Enemy Index Act, 4-Actor targeted, 5-Enemy Targeted]

^for reference, I keep this written down in a comment somewhere, because I use it A LOT.
The actor will use the copy skill, the common event will follow immediately as an effect. So the "last data" is a given.

For this event we'll want the last acting Actor and the last targeted Enemy Index.
$gameTemp._lastActionData[2]
$gameTemp._lastActionData[5]

Now this "last" data only gives you the Enemy Troop INDEX number. Their place in the battle troop. But we can use it to get the enemy's database ID in the $gameTroop._enemies
SO instead of $dataEnemies[3] we'll use $dataEnemies[$gameTroop._enemies[$gameTemp._lastActionData[5] -1]._enemyId]

So then you can have the script check if that targeted enemy has a skillCopy value. Then have the actor learn that skill id.
The thing about note tags is that everything is a text string. The learnSkill() function needs a number not a string. learnSkill(10); not learnSkill("10"). Using the Number() function will read "10" as 10.
JavaScript:
target = $gameTroop._enemies[$gameTemp._lastActionData[5]-1]._enemyId
if ($dataEnemies[target].meta.skillCopy != "undefined" ){
$gameActors.actor($gameTemp._lastActionData[2]).learnSkill(Number($dataEnemies[target].meta.skillCopy))};

[img]https://i.imgur.com/sY2IIDc.png[/img]

I'm sorry if this feels like a lot. I never know how much structure I have to explain.

Honestly, checking the enemy's note tag for a skill ID might be excessive. You could just have a conditional branch in the common event learn a skill based on the Enemy ID.

Edit: Sorry #2. I forgot that the last enemy target "index" is a misnomer and isn't actually numbered like an index. You need to subtract 1. Also, the if statement needs to check if the tag is undefined or not. I guess I could write it other ways, but I won't go into that.
I fixed the code above if you want to copy and paste it. But it's not reflected in the screenshot.
Ok. Ok. Doing it this way, you'll want the actual ID of the enemy you targeted. Like $dataEnemies[3] -- that'd be the 3rd enemy in then Enemy database.
But the actor can potentially target anyone. Right? How do you get the target's ID number?

Luckily MZ keeps "last action" data which you can set using [control variables]
Personally I think using the variable event commands is clunky process. It's easier to just reference the data array directly with the script.
$gameTemp._lastActionData = [0-Last Skill, 1-Last Item, 2-Actor ID Act, 3-Enemy Index Act, 4-Actor targeted, 5-Enemy Targeted]

^for reference, I keep this written down in a comment somewhere, because I use it A LOT.
The actor will use the copy skill, the common event will follow immediately as an effect. So the "last data" is a given.

For this event we'll want the last acting Actor and the last targeted Enemy Index.
$gameTemp._lastActionData[2]
$gameTemp._lastActionData[5]

Now this "last" data only gives you the Enemy Troop INDEX number. Their place in the battle troop. But we can use it to get the enemy's database ID in the $gameTroop._enemies
SO instead of $dataEnemies[3] we'll use $dataEnemies[$gameTroop._enemies[$gameTemp._lastActionData[5] -1]._enemyId]

So then you can have the script check if that targeted enemy has a skillCopy value. Then have the actor learn that skill id.
The thing about note tags is that everything is a text string. The learnSkill() function needs a number not a string. learnSkill(10); not learnSkill("10"). Using the Number() function will read "10" as 10.
JavaScript:
target = $gameTroop._enemies[$gameTemp._lastActionData[5]-1]._enemyId
if ($dataEnemies[target].meta.skillCopy != "undefined" ){
$gameActors.actor($gameTemp._lastActionData[2]).learnSkill(Number($dataEnemies[target].meta.skillCopy))};

sY2IIDc.png


I'm sorry if this feels like a lot. I never know how much structure I have to explain.

Honestly, checking the enemy's note tag for a skill ID might be excessive. You could just have a conditional branch in the common event learn a skill based on the Enemy ID.

Edit: Sorry #2. I forgot that the last enemy target "index" is a misnomer and isn't actually numbered like an index. You need to subtract 1. Also, the if statement needs to check if the tag is undefined or not. I guess I could write it other ways, but I won't go into that.
I fixed the code above if you want to copy and paste it. But it's not reflected in the screenshot.
It's fine dude. I'll admit, I am incredibly green when it comes to game design and this engine.
Ok. Ok. Doing it this way, you'll want the actual ID of the enemy you targeted. Like $dataEnemies[3] -- that'd be the 3rd enemy in then Enemy database.
But the actor can potentially target anyone. Right? How do you get the target's ID number?

Luckily MZ keeps "last action" data which you can set using [control variables]
Personally I think using the variable event commands is clunky process. It's easier to just reference the data array directly with the script.
$gameTemp._lastActionData = [0-Last Skill, 1-Last Item, 2-Actor ID Act, 3-Enemy Index Act, 4-Actor targeted, 5-Enemy Targeted]

^for reference, I keep this written down in a comment somewhere, because I use it A LOT.
The actor will use the copy skill, the common event will follow immediately as an effect. So the "last data" is a given.

For this event we'll want the last acting Actor and the last targeted Enemy Index.
$gameTemp._lastActionData[2]
$gameTemp._lastActionData[5]

Now this "last" data only gives you the Enemy Troop INDEX number. Their place in the battle troop. But we can use it to get the enemy's database ID in the $gameTroop._enemies
SO instead of $dataEnemies[3] we'll use $dataEnemies[$gameTroop._enemies[$gameTemp._lastActionData[5] -1]._enemyId]

So then you can have the script check if that targeted enemy has a skillCopy value. Then have the actor learn that skill id.
The thing about note tags is that everything is a text string. The learnSkill() function needs a number not a string. learnSkill(10); not learnSkill("10"). Using the Number() function will read "10" as 10.
JavaScript:
target = $gameTroop._enemies[$gameTemp._lastActionData[5]-1]._enemyId
if ($dataEnemies[target].meta.skillCopy != "undefined" ){
$gameActors.actor($gameTemp._lastActionData[2]).learnSkill(Number($dataEnemies[target].meta.skillCopy))};

sY2IIDc.png


I'm sorry if this feels like a lot. I never know how much structure I have to explain.

Honestly, checking the enemy's note tag for a skill ID might be excessive. You could just have a conditional branch in the common event learn a skill based on the Enemy ID.

Edit: Sorry #2. I forgot that the last enemy target "index" is a misnomer and isn't actually numbered like an index. You need to subtract 1. Also, the if statement needs to check if the tag is undefined or not. I guess I could write it other ways, but I won't go into that.
I fixed the code above if you want to copy and paste it. But it's not reflected in the screenshot.
It's fine man. I put this down and it functions, but it's not copying anything for some reason.
It looks generally right, we'd need to see the end that's cut off to the right to make sure of any little syntax errors.

It's good coding practice to use getter functions when they're provided to you, so members() instead of _enemies and enemyId() instead of _enemyId, but I'm not going to suggest you rewrite your script box over that.

Does the actor have access to the stolen skill's skill type?
<skillCopy: 10> means the Actor is going to learn Skill #10 in the database.
Forgot to explain that.

Looks like your Anewbus enemys has Plague Blast, which is Skill #236
So you want <skillCopy: 236> in Anewbus' notebox.

You'll probably also want some kind of message to pop when the Actor does learn a new skill.

I didn't want to make this too complicated. But you can change the common event script to this. Which adds a battlelog message.
JavaScript:
target = $gameTroop._enemies[$gameTemp._lastActionData[5]-1]._enemyId
skillId = Number($dataEnemies[target].meta.skillCopy);
thisActor = $gameTemp._lastActionData[2];

if ($dataEnemies[target].meta.skillCopy != "undefined" && skillId > 0){

if ($gameActors.actor(thisActor).skills().includes($dataSkills[skillId])){
BattleManager._logWindow.addText("Skill already learned.")
}else{
$gameActors.actor(thisActor).learnSkill(skillId);
BattleManager._logWindow.addText($gameActors.actor(thisActor)._name+" learned skill!")
};

}else{
BattleManager._logWindow.addText("No Skill to copy");
};
<skillCopy: 10> means the Actor is going to learn Skill #10 in the database.
Forgot to explain that.

Looks like your Anewbus enemys has Plague Blast, which is Skill #236
So you want <skillCopy: 236> in Anewbus' notebox.

You'll probably also want some kind of message to pop when the Actor does learn a new skill.

I didn't want to make this too complicated. But you can change the common event script to this. Which adds a battlelog message.
JavaScript:
target = $gameTroop._enemies[$gameTemp._lastActionData[5]-1]._enemyId
skillId = Number($dataEnemies[target].meta.skillCopy);
thisActor = $gameTemp._lastActionData[2];

if ($dataEnemies[target].meta.skillCopy != "undefined" && skillId > 0){

if ($gameActors.actor(thisActor).skills().includes($dataSkills[skillId])){
BattleManager._logWindow.addText("Skill already learned.")
}else{
$gameActors.actor(thisActor).learnSkill(skillId);
BattleManager._logWindow.addText($gameActors.actor(thisActor)._name+" learned skill!")
};

}else{
BattleManager._logWindow.addText("No Skill to copy");
};
Thank you so much! Now it's working like a charm!

Original thread: https://forums.rpgmakerweb.com/threads/copy-spell.154753/