MZ Restrict target selection?

Apologies if this is in the wrong section. I'm working on a plugin, and don't necessarily need help learning javascript for what I need(I think), I DO need help figuring out where a piece of code resides.

Basically, I'm looking for the code that handles choosing a skill's target in battle. I want to be able to restrict which enemies you can target based on certain criteria. Easiest would be to have the skill not do anything to enemies with certain criteria, but I want the criteria to prevent allowing a player to even select that enemy as a target the first place. I found a section about making targets in Game_Action, but I THINK that's only for when a skill has a wide scope. Not 100% sure, because I set a break there with the console and it never breaks, and that's about the only kind of skill my test project doesn't have, and I haven't bothered checking that because it's not breaking where I need to stick my code anyway.

I'm still learning what parts of the engine are handled by what scripts, so I don't know if I should be looking at objects, scenes, windows, managers, or what. I'm not sure what to search for either, and I don't generally have time to just read the whole thing line by line(that and the last time I started doing that, I discovered something that inspired a distraction, and I'm TRYING to get this thing done lol).

Thanks in advance!
Mine: https://github.com/theoallen/RMMZ/blob/master/Plugins/Theo_TauntHideTraits.js
I do it by overwriting the selection in the Window_BattleEnemy then adding the condition there.
Moderator note: Moving this to Learning Javascript, as you're not asking for assistance with an existing plugin, and there are a lot of threads in that forum related to "finding your way" with the RPG Maker implementation of Javascript
Mine: https://github.com/theoallen/RMMZ/blob/master/Plugins/Theo_TauntHideTraits.js
I do it by overwriting the selection in the Window_BattleEnemy then adding the condition there.
I love how concise your code is. I still don't understand JavaScript nearly well enough to do stuff as concisely as you do.

Unfortunately, the Window_BattleEnemy function you overwrite doesn't seem to exist in the base code. I assumed it wouldn't matter since as far as I can tell, it would inherit the same function from its own prototype, but it never fires (I haven't tried your plugin, I simply copied the function name to my own). I can still freely select any enemy with any skill. I've set a break point on the function, but it never breaks.

Moderator note: Moving this to Learning Javascript, as you're not asking for assistance with an existing plugin, and there are a lot of threads in that forum related to "finding your way" with the RPG Maker implementation of Javascript
Thanks! I wasn't quite sure exactly where this belonged, and I think it's morphed into a learning javascript problem anyway. lol
Unfortunately, the Window_BattleEnemy function you overwrite doesn't seem to exist in the base code. I assumed it wouldn't matter since as far as I can tell, it would inherit the same function from its own prototype, but it never fires (I haven't tried your plugin, I simply copied the function name to my own). I can still freely select any enemy with any skill. I've set a break point on the function, but it never breaks.
The function is simply making it impossible to choose, not to move the selection.
If you choose the enemy, it will play a buzzer sound if it is not impossible to choose.

if you want to filter the selection, you need to overwrite a different function.
I'm not opening the MZ code now, but the function name should be like either makeItemList or makeEnemyList or along those lines.

What is your code look like so far if you don't mind sharing?
The function is simply making it impossible to choose, not to move the selection.
If you choose the enemy, it will play a buzzer sound if it is not impossible to choose.

if you want to filter the selection, you need to overwrite a different function.
I'm not opening the MZ code now, but the function name should be like either makeItemList or makeEnemyList or along those lines.

What is your code look like so far if you don't mind sharing?
Ah, there was my problem, I was assuming the function did something else, so when I was able to move the selection to an invalid enemy I was immediately trying to check out what was happening, I never tried to actually use the skill on it. I was also stumped on why the break never fired. Still don't know why, but it still works so I'll take it.

Now that I know what it ACTUALLY does, I think this will work better than filtering. Thanks a lot!

By the way, the plugin I'm working on here is actually inspired by your metadata plugin, so I honestly find it amusing that it was you that helped me here. I'm basically making keyword plugins. I've finished the core already, now I'm making keyword extension plugins for it that recreate certain mechanics from other games in a mostly plug and play fashion, translated for RPGs if they're not from RPGs already. Basically, a little like your metadata plugin but with the mechanics pre-defined and built in, instead of developing it yourself. Less customizable, but potentially useful nonetheless. This one specifically recreates certain core keywords from Magic: The Gathering. (If you're curious and know MtG at all, this thread was trying to get hexproof and flying/reach targeting restrictions working.)

So, I think I have one final question. I assume that I'll need to alias this function if any of my other plugins need to use it too? I'm not sure just how many of these plugins I'll end up making, so it's possible I'll never need it again, but better safe than sorry. I'll do it anyway, but I'm curious if it's necessary as I assume it is. I only ask because JavaScript has a tendency of turning everything I think I know about how it's supposed to work on its head and seems to love frustrating me when the obvious(to me) doesn't work. But as I'm essentially learning solely by doing, there are a lot of holes in what someone even of my level should already know if they'd learned THIS language from the ground up.
So, I think I have one final question. I assume that I'll need to alias this function if any of my other plugins need to use it too?
You can do either of the approaches. Overwrite or an alias (if you know how). But first thing first, make it work. You can update and optimize the code later if you don't have the knowledge, wisdom, and/or experience yet. The easiest way would be to overwrite it. You don't have to do it perfectly for the first time. Code refactor happens.
You can do either of the approaches. Overwrite or an alias (if you know how). But first thing first, make it work. You can update and optimize the code later if you don't have the knowledge, wisdom, and/or experience yet. The easiest way would be to overwrite it. You don't have to do it perfectly for the first time. Code refactor happens.
Indeed. I'm not new to programming in general, just JavaScript, I know the truth of rewrites and optimizations. I've rewritten the core plugin twice already. Made it a bit more modular and cut the code length in half at the same time. And erased a plugin-breaking bug I didn't even know was present until about halfway through the first rewrite.

The function does work, and I think I know how to go about properly aliasing this particular function. I'll test that part out on the next plugin I make that needs to use it.

Thanks so much for your help dude!
Thread closed

Original thread: https://forums.rpgmakerweb.com/threads/restrict-target-selection.134827/