MV An idea for a skill that costs items... with a targeting mechanic addition

I have a character that uses bullets for his skills and attack... No problem I have that figured out easily. What I want to do is have one [or more if this works out] of his skills and have an item cost that depends on the number of enemies in the troop and how many of said items are left. I'm not sure it is possible hundred percent how I want it, but maybe a form of it?

So I want the skill to display a '?' when in the menu before battle, but once the battle takes place the cost reflects the number of enemies in the battle.

5 enemies = 5 bullets.

Now, the tricky part... let's say there are 5 enemies, but you only have 3 bullets left. Can we make the skill target only that many enemies?

5 enemies + 3 bullets = 3 enemy targets

So, I really want to have this happen for my skill. I just don't how to pull it off... Though I do know where the lunatic modes are that could do it, I don't know how to use them to make this work.

So here is the Skill Uses Items Lunatic Mode:
============================================================================
Lunatic Mode - Custom Item Costs
============================================================================

For those with a bit of JavaScript knowledge, you can create dynamic item
costs for your skills using the following notetags:

Skill Notetags:

<Custom Type x Cost>
cost = user.level;
</Custom Type x Cost>
Replace 'type' with either 'item', 'weapon', or 'armor' to change the type
and x as the ID of that item type. The 'cost' variable determines how much
of the required item type is needed as the cost.

<Custom Item Cost: name>
cost = user.level;
</Custom Item Cost: name>
For those who prefer to use names instead, replace 'name' with the name of
the item to be used as the cost. The 'cost' variable determines how much
of the named item is needed as the cost. If you have multiple items in
your database with the same name, priority will be given to the item with
the highest ID in the order of items, weapons, and armors.

and this is the Lunatic Mode for the Targeting Core:
============================================================================
Lunatic Mode - Custom Target Eval
============================================================================

For users that are proficient with JavaScript, these notetags can be used to
make custom target selections. For the targeting aspect, this will refer to
the skill/item's current scope and the targets made here will be made
independent of the scope with the exception of the target, where if a target
is selected, it will become the 'target' value.

<Custom Target Eval>
for (var i = 0; i < foes.aliveMembers().length; ++i) {
var member = foes.aliveMembers();
if (member.level % 3 === 0) targets.push(member);
}
</Custom Target Eval>
The 'targets' variable is an array that determines which are the targets
to be used during the selection process. Push the desired targets into
the 'targets' array.


If there is any additional information you might need let me know so I can get it for you.

Thanks in advance
Try this.

Regarding the costs, have the skill's item cost and display eval notetags refer to either $gameTroop.aliveMembers().length or your item count through Math.min

Then the targetting aspect you could use a loop or just slice the aliveMembers() of the target eval tag to get the right number of targets.
you wouldnt be able to choose which 3 of the hypothetical 5 enemies to attack though. you could leave it be and have it be the first 3 indices or randomize it, but you wouldnt be able to select without some other plugin
That should be doable with the two tags you've mentioned, I think.

Code:
<Custom Item Cost: name>
cost = Math.min($gameParty.numItems(ITEMID), $gameTroop.aliveMembers().length);
</Custom Item Cost: name>
This would make the cost of the skill the number of alive enemy units, OR the number of bullet items remaining in the inventory, whichever is lower.

Code:
<Custom Target Eval>
for (var i = 0; i < foes.aliveMembers().length; ++i) {
if (i > $gameParty.numItems(ITEMID)) continue
var member = foes.aliveMembers();
targets.push(member);
}
</Custom Target Eval>
This will push an enemy to the target array as long as i isn't higher than the number of bullets, otherwise it will skip pushing the target. That should make it so that the maximum number of targets hit doesn't exceed the number of bullets you had when you selected the skill. It won't randomly select targets though, it would go by index number up to the maximum, so if you wanted it to be randomized as well, you'd need to do something else to the targets array.
That should be doable with the two tags you've mentioned, I think.

Code:
<Custom Item Cost: name>
cost = Math.min($gameParty.numItems(ITEMID), $gameTroop.aliveMembers().length);
</Custom Item Cost: name>
This would make the cost of the skill the number of alive enemy units, OR the number of bullet items remaining in the inventory, whichever is lower.

Code:
<Custom Target Eval>
for (var i = 0; i < foes.aliveMembers().length; ++i) {
if (i > $gameParty.numItems(ITEMID)) continue
var member = foes.aliveMembers();
targets.push(member);
}
</Custom Target Eval>
This will push an enemy to the target array as long as i isn't higher than the number of bullets, otherwise it will skip pushing the target. That should make it so that the maximum number of targets hit doesn't exceed the number of bullets you had when you selected the skill. It won't randomly select targets though, it would go by index number up to the maximum, so if you wanted it to be randomized as well, you'd need to do something else to the targets array.
I don't want to complicate the whole thing more than it already is, so no randomizing is not important on this one.

But... I've tried this out and have gotten a few errors:
Error 1 (1).png

Error 2 (1).png


The following is a lot so, into a spoiler it goes:
Spoiler: Errors
Error 3.png

Error 4.png

Error 5.png

Error 6.png

Error 7.png

Error 8.png

Error 9.png

There are some of the errors that are scrambled and unreadable... So unfortunately I couldn't get those for you.

Also, a little visual problem:
Visual 1.png

The one that's highlighted is supposed to say one [since I was only using one enemy for this test], but it says zero.

Thanks for helping out. Hopefully, the stuff I've given can help find a solution.
your first issue is this.
var member = foes.aliveMembers();
targets.push(member);
targets should be an array of battlers, not an array of an array of battlers. Ramza just missed the at the end of aliveMembers(), but it would presumably cause that error.
EDIT: im too lazy to look up the escape charcacters here, but use the index i of aliveMembers()

For your second issue, $gameParty.numItems takes a Item as an argument, not an integer. Its used for items, weapons, and armors, so giving it the item is needed. the cost is showing 0 because its actually returning 0 in this case. change both uses of
Code:
$gameParty.numItems(ID)
to
$gameParty.numItems($dataItems[ID])

The following is a lot so, into a spoiler it goes:
There are some of the errors that are scrambled and unreadable... So unfortunately I couldn't get those for you.
Also while I appreciate giving as much info as you could, there was no need to give a screencap of all the functions leading up to the error provided you didnt edit any of them. just the error trace was fine. none of those are "errors", theyre just the path to it.
in this case, the error only had to do with the last call there, and the cause of that was the notetag creating an unexpected input
your first issue is this.

targets should be an array of battlers, not an array of an array of battlers. Ramza just missed the at the end of aliveMembers(), but it would presumably cause that error.
EDIT: im too lazy to look up the escape charcacters here, but use the index i of aliveMembers()

For your second issue, $gameParty.numItems takes a Item as an argument, not an integer. Its used for items, weapons, and armors, so giving it the item is needed. the cost is showing 0 because its actually returning 0 in this case. change both uses of
Code:
$gameParty.numItems(ID)
to
$gameParty.numItems($dataItems[ID])



Also while I appreciate giving as much info as you could, there was no need to give a screencap of all the functions leading up to the error provided you didnt edit any of them. just the error trace was fine. none of those are "errors", theyre just the path to it.
in this case, the error only had to do with the last call there, and the cause of that was the notetag creating an unexpected input

Thank you so much @Robro33, I was fiddling with the note tag while I was waiting for an answer and I actually came up with that array part on my own... After looking at the Lunatic Mode example long enough I noticed that little detail and 'fixed' it that way.

So, this is what I came up with:
Code:
<Custom Target Eval>
for (var i = 0; i < foes.aliveMembers().length; ++i) {
if (i < $gameParty.numItems(169)) continue
var member = foes.aliveMembers()[i];
targets.push(member);
}
</Custom Target Eval>

It worked in targeting the enemies... No problem... BUT, it always targeted ALL the enemies. When I experimented with lowering the ammo count the skill targeted all the enemies REGARDLESS of how much ammo was left. I was able to use the skill continuously despite having 0, ZERO, ammo for it.

It was like the skill was ignoring the Item Cost Notetag...

When I came back to report my endeavours I read your post and implemented the changes to the notetags... And, despite that Item Cost note tag displaying the proper ammo amount now... It still gets ignored and I can still use the skill repeatedly despite not having the proper amount ammo for it - IE: I have zero bullets but I can still use the skill and have it work.

But that's not the only thing that happened... With the change to the Targeting notetag my skill now no longer attacks the enemies. The skill activates and it goes through the motions, but there is no target and no damage... in fact, because I used the Opacity not focus action all the enemies are invisible because they are no longer part of the skill.

Going back to the original note tag allows the skill to attack the enemies again, but the problem from the original note tag is still present.

Here is a video showing what I mean: (Ignore the obvious errors in my Sequence code, I'm still refining this skill)


And I found that interesting bug when I was recording this video... The one where it attacks an enemy after not attacking, but it uses two items instead of one and then it just attacks everybody...
It was like the skill was ignoring the Item Cost Notetag...
...IE: I have zero bullets but I can still use the skill and have it work.
youd need to either use the skill core's custom requirement tag to be able to specify that you want it to only be usable if you have atleast one of the items, or adjust your item cost to always be atleast 1.

It did exactly as was asked. think about it like this. you manipulate the costs of the skill dynamically to be either the number of enemies, or the number of items you have with that notetag. if you have 0 items, it costs 0 items. nothing about that says you cant use it.

But that's not the only thing that happened... With the change to the Targeting notetag my skill now no longer attacks the enemies.
if (i < $gameParty.numItems(169)) continue
Did you intentionally change the "i > itemcount" in ramza's example to "i < itemcount"? cause youve inverted the logic without changing anything else

as i said. if you give numitems a number, gives you back 0. in the case of the old notetag with numItems(169), since you start i at 0 and the condition to skip is "if i < 0", you cant ever run that continue and all battlers would be pushed into the targets array.
if you added my change to it so that it now numItems looks at your item count for item 169, the line now reads "if i < itemcount, continue", which means you never push any targets into the array unless you have more enemies than ammo. change the comparison back to greater than

And I found that interesting bug when I was recording this video... The one where it attacks an enemy after not attacking, but it uses two items instead of one and then it just attacks everybody...
the exact thing i mentioned above. with that comparison, you dont push targets until you have more enemies than ammo. you shot 0, then 1, than 3 because you had 5, then 2, then 0 rounds. youre shooting them with negative ammo
youd need to either use the skill core's custom requirement tag to be able to specify that you want it to only be usable if you have atleast one of the items, or adjust your item cost to always be atleast 1.

It did exactly as was asked. think about it like this. you manipulate the costs of the skill dynamically to be either the number of enemies, or the number of items you have with that notetag. if you have 0 items, it costs 0 items. nothing about that says you cant use it.



Did you intentionally change the "i > itemcount" in ramza's example to "i < itemcount"? cause youve inverted the logic without changing anything else

as i said. if you give numitems a number, gives you back 0. in the case of the old notetag with numItems(169), since you start i at 0 and the condition to skip is "if i < 0", you cant ever run that continue and all battlers would be pushed into the targets array.
if you added my change to it so that it now numItems looks at your item count for item 169, the line now reads "if i < itemcount, continue", which means you never push any targets into the array unless you have more enemies than ammo. change the comparison back to greater than


the exact thing i mentioned above. with that comparison, you dont push targets until you have more enemies than ammo. you shot 0, then 1, than 3 because you had 5, then 2, then 0 rounds. youre shooting them with negative ammo
Ok... I see what you mean. Yes, I inverted the logic because at the time I heard of this thing called BREAK [found it online] and thought - it's the opposite of continue and so I should make the IF/Else opposite as well. Well, long story short, I forgot to change it back when it didn't work and went back to the 'continue' again.

I changed it back and the skill is working again... But it still not doing exactly what I think it should based on the way I have read this Note-tag...

Check this out: [it's shorter than the last one]

The first round of attacks goes off without a hitch and it exactly what needs to happen. The second round though, yeah... That's wrong. The second round only has ammo for 2 shots, but it still attacks all three of the enemies... Is the "Itemcount" not updating properly?

I have a skill for one of my enemies that was having a problem with the targeting eval that ended up needing to make variables for it and have them update BEFORE the loop. Would that be something that needs to happen here?
The second round only has ammo for 2 shots, but it still attacks all three of the enemies... Is the "Itemcount" not updating properly?
oh.
back to the same comparison again. greater than or equal to. you start the loop at 0
oh.
back to the same comparison again. greater than or equal to. you start the loop at 0
That did it and thank you for all the help... You and @ramza have been a big help in this. Now, to adapt this for some of my other skills so they are more dynamic and less static. Oh and work out the kinks of this skill as well... I have so much to do and so little time to do it in!

Thank you so much
your first issue is this.

targets should be an array of battlers, not an array of an array of battlers. Ramza just missed the at the end of aliveMembers(), but it would presumably cause that error.
EDIT: im too lazy to look up the escape charcacters here, but use the index i of aliveMembers()

For your second issue, $gameParty.numItems takes a Item as an argument, not an integer. Its used for items, weapons, and armors, so giving it the item is needed. the cost is showing 0 because its actually returning 0 in this case. change both uses of
Code:
$gameParty.numItems(ID)
to
$gameParty.numItems($dataItems[ID])



Also while I appreciate giving as much info as you could, there was no need to give a screencap of all the functions leading up to the error provided you didnt edit any of them. just the error trace was fine. none of those are "errors", theyre just the path to it.
in this case, the error only had to do with the last call there, and the cause of that was the notetag creating an unexpected input
Thanks for the assist there.
TBH I hadn't opened RM in a long time, so I was a little rusty. What I'd posted initially was actually very different than what I ended up with after the 12 edits I already did, and it seems that I messed up some stuff anyway 🙂

Glad we got there in the end though,
@Robro33 or @ramza, I have a little question about this setup... How would I change this to get it to loop twice?

If there are 3 enemies and I use the skill, the skill will hit each enemy twice or until it runs out of ammo, whichever comes first.

I tried:
Code:
<Custom Target Eval>
for (var i = 0; i < foes.aliveMembers().length * 2; ++i) {
if (i >= $gameParty.numItems($dataItems[168])) continue
var member = foes.aliveMembers()[i];
targets.push(member);
}
</Custom Target Eval>
But that didn't do anything... It pushed the three enemies into the target array and that's it, just three. So the skill attacks three times and finishes. I would like it to repeat the target array one more time so that it attacks the three enemies twice.

No fancy stuff is needed, just attack enemies 1, 2, 3, 1, 2, 3 would be fine.

It's for a different skill, but the last skill worked out so well I got inspired to do something with my other skills...
im surprised that didnt cause a crash tbh. the problem is that changing the loop condition the way you did isnt enough without changing what happens in the loop. when you doubled foes.aliveMembers().length, you doubled the range of i from 0-2 to 0-5, but youre still pushing the ith member of the troop into that array. there arent any troop members past the third enemy, so youre not actually doing anything you'd want here.

If there are 3 enemies and I use the skill, the skill will hit each enemy twice or until it runs out of ammo, whichever comes first.
I would like it to repeat the target array one more time so that it attacks the three enemies twice.
theres a little bit of a discrepancy here, but maybe its cause im still thinking youre holding on to 5 rounds. if you want the skill to keep going until it either hits each enemy twice OR runs out of ammo, then you can change your loop condition to be that i doesnt exceed your ammo count AND that i doesnt go over than twice the foes.aliveMember().length.
from there, you can push members of foes.aliveMembers() based on i%foes.aliveMembers().length

Code:
for (var i = 0; i < $gameParty.numItems($dataItems[168]) && i < foes.aliveMembers().length*2; ++i) {
  var member = foes.aliveMembers()[i%foes.aliveMembers().length];
  targets.push(member);
}

that should cycle the targets and stop once its either done it twice or you ran out of bullets
im surprised that didnt cause a crash tbh. the problem is that changing the loop condition the way you did isnt enough without changing what happens in the loop. when you doubled foes.aliveMembers().length, you doubled the range of i from 0-2 to 0-5, but youre still pushing the ith member of the troop into that array. there arent any troop members past the third enemy, so youre not actually doing anything you'd want here.



theres a little bit of a discrepancy here, but maybe its cause im still thinking youre holding on to 5 rounds. if you want the skill to keep going until it either hits each enemy twice OR runs out of ammo, then you can change your loop condition to be that i doesnt exceed your ammo count AND that i doesnt go over than twice the foes.aliveMember().length.
from there, you can push members of foes.aliveMembers() based on i%foes.aliveMembers().length

Code:
for (var i = 0; i < $gameParty.numItems($dataItems[168]) && i < foes.aliveMembers().length*2; ++i) {
  var member = foes.aliveMembers()[i%foes.aliveMembers().length];
  targets.push(member);
}

that should cycle the targets and stop once its either done it twice or you ran out of bullets
Thank you very much for all the help. It's working just the way I want it to.

Original thread: https://forums.rpgmakerweb.com/threads/an-idea-for-a-skill-that-costs-items-with-a-targeting-mechanic-addition.170677/