Turning who was targeted into a game variable

Kistulot

Easily Distracted Writer
Veteran
Joined
Oct 23, 2015
Messages
40
Reaction score
17
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
826
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
245
Reaction score
82
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
17
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
826
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
17
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
240
Reaction score
41
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

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,864
Messages
1,017,056
Members
137,573
Latest member
nikisknight
Top