Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Getting the X + Y Coordinates of an event

I'm developing a script that needs the following, and ive been stuck as of how to do it.

There are a few ways I think it could be done but this is the only one I can think of.:

Store the X + Y coordinates of all the events on the map in seperate variables (or an array?) aka: ev001's x would be RSE_event_x[1] = 12
ev002 y would be RSE_event_y[2]

They all need to be in seperate variables for another part of this script.

or, to skip this part.... I need to know the difference between each event and the player.
eg:

@event_x_diff = $player_x - $event_x
@event_y_diff = $player_y - $event_y
@total_diff = @event_x_diff + @event_y_diff
@total_diff = @total_diff.abs


excuse my poor scripting grammer, I'm still learning. Getting there though ;)
 
Use
Code:
$game_map.events[id].x
$game_map.events[id].y
to get the x/y position of an event. I suggest to put those variables into a hash instead of an array; events are stored in a hash.
Try to put this in Game_Map, at the end of def initialize:
Code:
@events_pos = {}
for i in @map.events.keys
  @events_pos[i] = []
  @events_pos[i] << @events[i].x
  @events_pos[i] << @events[i].y
end

Then add
Code:
attr_accessor :event_pos
just below class Game_Map. You should now be able to use $game_map.events_pos[event_id] to get an event's position.
 
Thanks. Just noticed, the
Code:
 at the end needs a / before it to make the code box =]

I'll tell you if I have any problems

edit: It doesn't seem to work with putting it under def initalize, half the variables havn't been set.. . that portion of the script seems to run through if you put it under def setup (at the bottom)...

How do you get "id" to be the id of the event that started the script?
 
hmm... better to explain a little more... It's sorta a variation of the view range script... Find out how far away the player is from a certain event...

Edit: something along the lines of:

event_id = $self.id
or whatever it would be. so you store the id of the event that calls the script
 
mmm if you're using it with events (Call Script), you can do this:
Code:
x_diff = $game_player.x - $game_map.events[@event_id].x
y_diff = $game_player.y - $game_map.events[@event_id].y
total_diff = x_diff.abs + y_diff.abs
 
Code:
    x_diff = $game_player.x - 
    $game_map.events[$event_ref_id].x
    y_diff = $game_player.y - 
    $game_map.events[$event_ref_id].y
    total_diff = x_diff.abs + y_diff.abs
is in a proper script.

and each event is going to have the following data.

It's going to store it's variable inside the $event_ref_id

Then a filepath under a different variable, then call teh script. (for a seperate part of it) so there needs to be several instances of the script running. one for each event.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top