Global Variable that stores the coordinates of any event? Or some more easy method

Good afternoon everyone.
Spoiler: Spoiler
I'm using Khas's ABS battle system: Sapphire Action System. I believe this information is just to make things clearer, because the resolution should work for any ABS system.

I'm facing the following situation: I'm creating a skill where the actor basically jumps towards the event and returns to their starting point after the attack. Returning to the starting point isn't a problem; the actor's location is stored in two variables, and a jump command is used for them. I'm using this command:

"jump($game_variables[z] - self.x, $game_variables[z] - self.y)" where z are the x and y coordinates of the player. Great, that's the easy part.

However, how do I determine the position coordinates of any event? Because there is 1 event on map x, there are 3 events on the next map, then 10 more events on a third map, 2 more events on a fourth map, and so on.

Am I required to create an event, on all maps, that provides all enemy coordinates - in a parallel process? Or is there an easier way to provide this information?

And there is a code, let's say "global script call code", that can be used so that the player jumps to the variable specified in the previous question?
I think I posted this in the wrong place. If you move it to the rgss3 request area, I would appreciate it.
I think I posted this in the wrong place. If you move it to the rgss3 request area, I would appreciate it.
If you click on the report link in your first post and ask for it to be moved then an Admin will do that. Otherwise just posting a comment is hoping an admin reads it.
Reporting brings it right to their attention

I've moved this thread to RGSS3 Requests. Thank you.

How does the player target an event?
You'll need a way for the player to decide which event is an enemy that should be attacked, or nothing will ever work.
This is especially true because you'll have decorative events and door events and functional events (chests etc) in addition to events pretending to be enemies.

Once you are able to decide that, there are ways to get the other infos needed from the game.
for example get location info will return the ID of an event (or other things) at coordinates (or zero if there is no event)
and either control variable or its script variant can return the coordinates of any event once you know which one (that is in game data, the script variant is needed if the event identification is variable)

.
How does the player target an event?
You'll need a way for the player to decide which event is an enemy that should be attacked, or nothing will ever work.
This is especially true because you'll have decorative events and door events and functional events (chests etc) in addition to events pretending to be enemies.

Once you are able to decide that, there are ways to get the other infos needed from the game.
for example get location info will return the ID of an event (or other things) at coordinates (or zero if there is no event)
and either control variable or its script variant can return the coordinates of any event once you know which one (that is in game data, the script variant is needed if the event identification is variable)

.
Good afternoon, Andar.

You are correct in your questions, as I have already thought about all of them and still haven't arrived at an answer.

At the moment I am still avoiding deciding how I will resolve this, proceeding with the following actions.
Here's what I'm doing right now:

1. I create a skill that calls a common event;

2. The common event triggers a switch x;

3. Events with automatic start, initiated by the switch, are scattered across the maps. Each(of this) event carries its grouping of variables that inform the location of the events(which should be targets), as well as the skill acting to attack the event informed.
At the moment, hahaha, as expected: it only works on the map with 1 event.
Events whitout information variable will not be targeted.

4. I haven't thought about the other events scattered across the map yet, like chests, because their(location) information isn't being shared.

5. After the skill's effect is executed, the switch turns off - essentially erasing the events scattered across the map. Using the skill again restarts the process.


Now, going back to your relevant questions, ideally I would create an event selection window (something similar to a keyitem window). My inspiration is this:
Spoiler: SK3
a.png

but I haven't yet figured out how to implement this type of scene.
An arrow icon could be used to indicate(by location) of the selected event, but the problem would be how to create the scene and its navigation(I thought this might be possible by having the event location information).

And thats it.
At the moment I am still avoiding deciding how I will resolve this,
Unfortunately that is like trying to build the roof of a house before the walls stand.

there are several different ways to handle selection, but they all have different advantages and disadvantages - and you can't continue if you don't know how to start.

your biggest problem is that you're currently using a single switch to trigger an unknown number of placed enemy events - you need a way to get the information of how many and which events react to that switch (becoming valid targets), or nothing else will ever work correctly.

This will either require a script to analyse every event on the current map or a different activation method that can be used to count and point the events.

And I can't even guess because you never describe how your game should work.
Unfortunately that is like trying to build the roof of a house before the walls stand.

there are several different ways to handle selection, but they all have different advantages and disadvantages - and you can't continue if you don't know how to start.

your biggest problem is that you're currently using a single switch to trigger an unknown number of placed enemy events - you need a way to get the information of how many and which events react to that switch (becoming valid targets), or nothing else will ever work correctly.

This will either require a script to analyse every event on the current map or a different activation method that can be used to count and point the events.

And I can't even guess because you never describe how your game should work.
Thank you for your reply.

I understand your questions, Andar, but how could I suggest something I don't know how to execute?

I will then describe my ideal scene:
-This is how the standard SAS scene works when using a skill: the D button selects the skill, the S button executes the skill;

-When the S button is used, a transparent event selection window appears in the scene(events above or below it cannot be selected. I'm referring to those events that don't appear in the player's view; if the player moves upwards with the actor, then the events above will appear in their field of vision - and can then be selected); and an arrow icon appears over the event to be targeted;

-The event selection window(arrow icon above the events) could then be manipulated to always move towards the events whose locations have been specified; in my mind, this would be the basis for the "arrow's movement";

-Ideally, the event selection scene would feature a brighter color tone, making the skill user and the events that could be targeted stand out on the screen, almost as if there were a black background. But this is more of an aesthetic aspect of the scene, almost to make it perfect, and it's not a key element for its execution(I think);

-Once the event was selected, the event selection window would be cleared, and the skill's sequence of actions would be executed: the animation would hit the event, the damage would be dealt(via code), etc. This is basically the part I've focused on so far, because it's what I'm able to do.


Now, if the description you were expecting wasn't this one, of how the scene would work, I don't know what you're referring to.
that was exactly what I meant.

on the S button you need to first call a script that filters the event list of the map - both to their position/distance from the player (or if onscreen depending on your screen size), and whether that event is an enemy or a decoration or an invisible background process.

If the list after the filter contains only one element, that is the target - if it has multiple events, then a selection (either show choice, select item or a scripted new menu) will be used to determine which of the remaining event will be targeted.

that filter-script will be multiple lines in a script command at minimum, the only way to reduce that to a single call is to use a full script in the script editor containing both the filter and the selection window.

once you have the ID of the event there rest is easy - there are already script calls to get the position of an event by ID.
that was exactly what I meant.

on the S button you need to first call a script that filters the event list of the map - both to their position/distance from the player (or if onscreen depending on your screen size), and whether that event is an enemy or a decoration or an invisible background process.

If the list after the filter contains only one element, that is the target - if it has multiple events, then a selection (either show choice, select item or a scripted new menu) will be used to determine which of the remaining event will be targeted.

that filter-script will be multiple lines in a script command at minimum, the only way to reduce that to a single call is to use a full script in the script editor containing both the filter and the selection window.

once you have the ID of the event there rest is easy - there are already script calls to get the position of an event by ID.
Right. So you're suggesting that the next step should be to request that script?
yes, because it's the only thing that is missing - as said the script commands to get any event position based on event ID are in the topic about the "script equivalents to event commands" somewhere in the Ace boards - as event command it is part of the control variable game data, but since you need to react to an array of IDs returned you can't use event commands directly, only their script equivalent.

and that filterscript is rather simple (it could be done in a script command rather than the script editor), I just have the problem that VXAce and RGSS3 are too old for me to remember the code enough.
Don't have a complete script to offer right now, but maybe a few things that might help:

The thread that Andar mentioned should be this one, although the Character part of Control Variables seems missing there. The script calls look similar to the event command options though, in fact, you already used coordinates in your opening post:
Ruby:
character.x          # <- Map X
character.y          # <- Map Y
character.direction  # <- Direction
character.screen_x   # <- Screen X
character.screen_y   # <- Screen Y

# Replace  character  with:
$game_player          # <- The player
$game_map.events[ID]  # <- Event with the respective ID (without leading 0s)

If you are using Khas' Sapphire Action System, you should be able to get a list (Array) of all enemy events by using $game_map.enemies .
So for example
$game_variables[2] = $game_map.enemies[0].x
would set Variable 2 to the x-coordinate of the first enemy (arrays start at index 0) in the SAS enemy list.

---

As for filtering which enemies would be on the screen:

The easiest option would be to go with the "Screen X" and "Screen Y" coordinates, which are already in pixels. An events official pixel position is at its center bottom. Question would be if that is enough or if you also need to take the size of the event graphic into account?
Ruby:
# Example to select enemies sufficiently visible on screen:
# In this example: X- and Y- tile the event stands on must be half on the screen
# The resulting Array can be processed further or stored in a variable for later use
screen_enemies = $game_map.enemies.select { |event|
  event.screen_x.between?(0, Graphics.width) && event.screen_y.between?(16, Graphics.height + 16)
}

An example to use such an array could be this:
Ruby:
# Note: screen_enemies is a local Ruby variable here and can only be used
# within the same script command, hence storing the array in $game_variables[17] here:
$game_variables[17] = screen_enemies

# Store the number of elements in the array for easy access:
# Array entries are stored starting at index 0, so this number would be 1 past the maximum:
# ($game_variables[17] and screen_enemies mean the same here, assuming the latter is still accessible)
$game_variables[18] = $game_variables[17].length

You could now use a third variable to control your target pointer. So assuming this would be variable 19 in your case, you could use
Ruby:
index = $game_variables[19]
enemy = $game_variables[17][index]

$game_player.jump(enemy.x - $game_player.x, enemy.y - $game_player.y)
to select the Xth enemy in the list and make the player jump to its position.

---

Alternatively you could maybe use the enemy list to create a custom "Show Choices" command (see "Scriptcall Equivalent" thread):
Ruby:
screen_enemies.each { |event|
  $game_message.choices.push($data_enemies[event.enemy.id].name)
}
$game_message.choice_cancel_type = screen_enemies.length + 1
$game_message.choice_proc = Proc.new {|n| $game_variables[19] = n }
wait_for_message
(After this the Index of the enemy should be in Variable 19, or 1 past the maximum if the player canceled the selection)

---

Probably just a starting point here, but maybe you can puzzle somthing together? Not sure if this helps.
Don't have a complete script to offer right now, but maybe a few things that might help:

Thanks for the reply, Fen.

Wow, that's a lot of information in a single post, with instructions that should work well for those who understand Ruby.
For someone who doesn't have a good grasp of Ruby... what you did was basically throw part of a script or several parts of a scripts into the comment xD

I'm not going to lie, I didn't even understand how I should begin, lol

For example:
screen_enemies.each { |event|
$game_message.choices.push($data_enemies[event.enemy.id].name)
}
$game_message.choice_cancel_type = screen_enemies.length + 1
$game_message.choice_proc = Proc.new {|n| $game_variables[19] = n }
wait_for_message
How am I supposed to use this? Is it a large script call code?

Another question: the "target pointer" will not be an image?

I appreciate your answer and I will try to understand how to use these codes.
Thank you.
Ah, yes, the post did derail a bit... Sorry.

Overall, if you use this as a script command
Ruby:
$game_variables[17] = $game_map.enemies.select { |event|
  event.screen_x.between?(0, Graphics.width) &&
  event.screen_y.between?(16, Graphics.height + 16)
}

$game_variables[18] = $game_variables[17].length
$game_variables[19] = 0
then...
Variable 17 contains a list (Array) of all registered enemy events with fitting Screen X/Y coordinates.
Variable 18 contains the number of events the array holds.
Variable 19 is 0, and can be used to as an index to select events in the array (starting at index 0).

To get the X coordinate of an event for example, you can use
Ruby:
# Plain:
$game_variables[17][$game_variables[19]].x

# Same code, but using local variables for better legibility:
target = $game_variables[17][$game_variables[19]]
target.x
You have yet to do the selection yourself though by setting Variable 19.
(Make sure the index is smaller than Variable 18. Variable 18 can be 0 if no enemies are on the screen.)

---

How am I supposed to use this? Is it a large script call code?
To be honest, in retrospect I don't know if that code is a good idea, but if you want to try it, then yes, it is a large script command (although you may have to replace "screen_enemies" with $game_variables[17] or your project equivalent).
It will also not work right if you have 0 enemies on the screen, so you would have to check for that.

Another question: the "target pointer" will not be an image?
So far the code does not yet include any images or details on how you would set Variable 19. (You could even choose the target randomly)

You could build a small target selection event using a picture as a pointer
(and use $game_variables[17][$game_variables[19]].screen_x to position it)

I also have never really worked with Khas' Sapphire Action System, right now I am not even sure what you can do with it, I am not sure if you may need an extra way to pause the combat during selection or anything.

Original thread: https://forums.rpgmakerweb.com/threads/global-variable-that-stores-the-coordinates-of-any-event-or-some-more-easy-method.181533/