Turning who was targeted into a game variable

Kistulot

Easily Distracted Writer
Veteran
Joined
Oct 23, 2015
Messages
40
Reaction score
15
First Language
English
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!
 

DreamX

Veteran
Veteran
Joined
May 30, 2015
Messages
816
Reaction score
820
First Language
English
Primarily Uses
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.
 

kiriseo

Veteran
Veteran
Joined
Oct 27, 2015
Messages
229
Reaction score
74
First Language
German
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());
 

Kistulot

Easily Distracted Writer
Veteran
Joined
Oct 23, 2015
Messages
40
Reaction score
15
First Language
English
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! :)
 

DreamX

Veteran
Veteran
Joined
May 30, 2015
Messages
816
Reaction score
820
First Language
English
Primarily Uses
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.
 
Last edited by a moderator:

Kistulot

Easily Distracted Writer
Veteran
Joined
Oct 23, 2015
Messages
40
Reaction score
15
First Language
English
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.
 

Magusalfador

Veteran
Veteran
Joined
Jun 15, 2014
Messages
231
Reaction score
38
First Language
English Spanish
Primarily Uses
@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 ??
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

That moment when you realize you lost time frankenstiening a sprite together, only to realize it already exited.
My first game is going to have the main character more or less create monsters as his party members.

Thanks to the plugin creators still producing content for MV, I might be able to give each of the monster members a personalized range of tactics during combat. I liked how the devs made it like that in FF6.
Stream will be live shortly! Tonight will be the PREMIERE of Killer 7 for the first half of the stream, and at half-stream, we will switch to a session of the Interactive Text Adventure! Feel free to drop by!
Watching the launch, I felt a sort of detached excitement. Usually I'd think something like this would be extremely exciting. I'm fascinated by space exploration and am a big Sci-Fi fan. I guess it's just current events.
What did everyone else think about it?
Doing ep 1 of my RPG!
For those still craving more Konosuba madness
I'm new here, any tips welcome

Hope you fun! :LZSgrin: :LZSkiss:

Forum statistics

Threads
97,968
Messages
948,192
Members
129,220
Latest member
prevoid
Top