Background (skip to next bolded text for meat of the question):
I'm trying to add a feature to my ABS based on clicking the enemy (or ally NPC) event you want to target (for potentially a plethora of uses, but mostly for targeting of various ranged, non-projectile spell effects). I can't use a plugin that allows event activation via click, because the feature needs to still be able to work if the event's active page is a parallel/looping one (core to several other aspects of the ABS). So I've been using a parallel common event to check if there are any events on the clicked tile (yes, after converting screen coords to map tile coords), using a variation of this script call:
(The variation I'm using is actually
My problem is that I'm also using a pixel movement plugin (Altimit Movement), which makes pinning down events to an appropriate tile trickier. My guess is that it's just finnicky, because sometimes when I click on an event during playtesting, it returns my test text (meaning the script call in the parallel common event successfully identified and returned that event's ID in the array) - but most of the time, it doesn't. I imagine this is just an inherent aspect of trying to check for events in a grid-based way, when those events have grid-free movement.
So a potential solution I thought of would be to check for not just the tile clicked, but each tile surrounding it, as well, to give more spatial leeway to the player's click (I know this would result in a much wider margin of error, but that's okay for my purposes - the point is to allow the player to easily choose a target, not to test their coordination/reflexes). Thing is, I don't have enough JS knowledge to have any idea how to approach doing this.
Could the script call I'm using potentially be altered to check multiple tiles for event IDs at once, perhaps by utilizing arrays for the x and y parameters? If this is possible, how would I write such code (to have it check each of those tiles)?
Or, does it have to be done by separately checking the clicked tile and each of the 8 tiles surrounding it? If this is the case, what code would I need to add the contents of each subsequent, resulting array to the same variable (so I can check all the returned event IDs at once, rather than from 9 separate variables)?
Ultimately, I just need to be able to retrieve the IDs of any events on or immediately near (so the targeting is less precise/finnicky) the spot where the player clicked.
I mostly just gave background so there's context of what I'm trying to do, since I know that's helpful, even though the root of the question is pretty straight-forwardly a "how do I write this in JavaScript" one. However, if based on the background you think there might be a better/more efficient way to go about implementing this clicking feature, I can provide screenshots of the event pages I currently have if needed/requested.
Thanks so much for any help and insight!
I'm trying to add a feature to my ABS based on clicking the enemy (or ally NPC) event you want to target (for potentially a plethora of uses, but mostly for targeting of various ranged, non-projectile spell effects). I can't use a plugin that allows event activation via click, because the feature needs to still be able to work if the event's active page is a parallel/looping one (core to several other aspects of the ABS). So I've been using a parallel common event to check if there are any events on the clicked tile (yes, after converting screen coords to map tile coords), using a variation of this script call:
Code:
$gameMap.eventIdXy(x, y)
(The variation I'm using is actually
$gameMap.eventIdXy_special, from the code @MushroomCake28 provided in this thread - with that code in my game as a plugin, as recommended - so I can receive the IDs of all events on the clicked tile, and check which one(s), if any, is/are designated "enemies")My problem is that I'm also using a pixel movement plugin (Altimit Movement), which makes pinning down events to an appropriate tile trickier. My guess is that it's just finnicky, because sometimes when I click on an event during playtesting, it returns my test text (meaning the script call in the parallel common event successfully identified and returned that event's ID in the array) - but most of the time, it doesn't. I imagine this is just an inherent aspect of trying to check for events in a grid-based way, when those events have grid-free movement.
So a potential solution I thought of would be to check for not just the tile clicked, but each tile surrounding it, as well, to give more spatial leeway to the player's click (I know this would result in a much wider margin of error, but that's okay for my purposes - the point is to allow the player to easily choose a target, not to test their coordination/reflexes). Thing is, I don't have enough JS knowledge to have any idea how to approach doing this.
Could the script call I'm using potentially be altered to check multiple tiles for event IDs at once, perhaps by utilizing arrays for the x and y parameters? If this is possible, how would I write such code (to have it check each of those tiles)?
Or, does it have to be done by separately checking the clicked tile and each of the 8 tiles surrounding it? If this is the case, what code would I need to add the contents of each subsequent, resulting array to the same variable (so I can check all the returned event IDs at once, rather than from 9 separate variables)?
Ultimately, I just need to be able to retrieve the IDs of any events on or immediately near (so the targeting is less precise/finnicky) the spot where the player clicked.
I mostly just gave background so there's context of what I'm trying to do, since I know that's helpful, even though the root of the question is pretty straight-forwardly a "how do I write this in JavaScript" one. However, if based on the background you think there might be a better/more efficient way to go about implementing this clicking feature, I can provide screenshots of the event pages I currently have if needed/requested.
Thanks so much for any help and insight!