Turning who was targeted into a game variable

Hello everyone!

I apologize if this was answered elsewhere. I did try to look! Thankfully you've all been pretty understanding in the past so I'm pretty sure that'll keep up.


Basically, I know if you use $gameVariables.setValue() you can set things to the Rpgmaker MV variables... Which is very useful! However, I'm trying to make it so say, you used an item in the menu, or an attack in battle, and it saved the ID of either the ally, or the enemy, so you could later use a common event to affect the given target. IE to see who an item was used on in the menu, or to see which enemy was targeted with a specific attack for the sake of a follow up effect. I realize both could probably be done with States, but for the sake of what I'm working on that feels like throwing in extra work to do something that should be simpler to accomplish.


I've tried using the following for the formula for items and skills, with both b.id and a.id to no success.


$game_variables.value(20); $game_variables.setValue(20,b.id);


I have some coding experience, but less javascript and I may also just not be setting things up properly, but any assistance for moving in the right direction would be greatly appreciated!


Thanks in advance!
It should actually be $gameVariables instead of $game_variables


But here, I've made a plugin for you. It has comments so you can also learn how and why I did things.


Script


How to use:  


Put <saveTarget:1> in the notetag for a skill or item. If you want to use a variable other than what was set in the plugin parameters, use <actorVariable:x> or <enemyVariable:x> for actor or enemy targets respectively, with x being the variable id. If the skill or item is successful then the id of the target will be stored in their respective variable.
If it have to be in the formula, you could try something like this:


var ID = b.isEnemy() ? b.enemyId() : b.actorId(); $gameVariables.setValue(20, ID);


or a little shorter:

Code:
$gameVariables.setValue(20, b.isEnemy() ? b.enemyId() : b.actorId());
Wow, thanks both of you for the quick responses, that was really great and deeply appreciated! 🙂


The plugin does 99% of what I was thinking, I just realized that for enemies I had in mind something a little bit different which I did not say - but this functionality actually adds a heck of a lot to things too. What I was thinking additionally would be to be able to store the battle-slot the enemy was in.


I see a lot of value for knowing which type of enemy, or specific enemy int he case of unique monster, was hit. Good for things like captuing monsters to unleash in attacks or for some sort of monster raising, with only one slot being available, or the potential to have multiple with additional work. I know there's a "last hit" variable somewhere but would it be possible to also know the variable for the enemy's battle location? IE you have 4 slimes, each one of them has... not an ID, but I'm afraid I don't know the name for their space in the battle, so that could also be stored?


It'd be cool to have in this plugin, but it would also just be neat to know if not! This is really cool, and works for a lot of things... thank you both again, very much! 🙂
Wow, thanks both of you for the quick responses, that was really great and deeply appreciated! 🙂


The plugin does 99% of what I was thinking, I just realized that for enemies I had in mind something a little bit different which I did not say - but this functionality actually adds a heck of a lot to things too. What I was thinking additionally would be to be able to store the battle-slot the enemy was in.


I see a lot of value for knowing which type of enemy, or specific enemy int he case of unique monster, was hit. Good for things like captuing monsters to unleash in attacks or for some sort of monster raising, with only one slot being available, or the potential to have multiple with additional work. I know there's a "last hit" variable somewhere but would it be possible to also know the variable for the enemy's battle location? IE you have 4 slimes, each one of them has... not an ID, but I'm afraid I don't know the name for their space in the battle, so that could also be stored?


It'd be cool to have in this plugin, but it would also just be neat to know if not! This is really cool, and works for a lot of things... thank you both again, very much! 🙂

Here you are. You will want to delete from the old version from the plugin list and add the new version. Remember to set the parameters if you want defaults.


The notetags for skills/items have been changed. Here is the list:


<actorIDVariable:x> with x being the variable to store the actor id.


<enemyIDVariable:x> with x being the variable to the store the enemy id.


<enemySlotVariable:x> with x being the variable to store the enemy slot.


Script


P.S. I haven't updated the code comments for this new version, I might do so later or sooner if you need them.
I felt a little presumptuous asking for that, but this feels like it opens so many possibilities, so I really appreciated it! Thank you again for helping with this so quickly. The way I misspoke feels like it could be used for a lot of interesting functionality, too!


And no worry about needing to update the comments. You did a great job with what you already commented, which I already foresee being incredibly helpful if/when I get around to futzing with this stuff.
@Kistulot Im using this plug in but the notags are not working for me:
<actorIDVariable:x> with x being the variable to store the actor id.
<enemyIDVariable:x> with x being the variable to the store the enemy id.
<enemySlotVariable:x> with x being the variable to store the enemy slot.

Are those working for you?

Any chance you can check this up for me @DreamX ??
In the damage formula you can use this;

v[varID]=b.enemyId();

However you'll do the enemyID in damage.
Necro-post notice: Dagothe

Original thread: https://forums.rpgmakerweb.com/threads/turning-who-was-targeted-into-a-game-variable.56054/