The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: ahref on March 04, 2008, 09:09:03 PM

Title: Get event name at (x,y)?
Post by: ahref on March 04, 2008, 09:09:03 PM
Im currently making a small edit to game_player. the goal is to only allow the player to get off his ship when hes at a port event. Im attempting to do this by inserting PORT in the event names of ports which my script would then check using regular expressions.

the only problem is i need to check the existence of an event at the place the character wishes to land and then determine its name.

How do I do this?

heres an image to explain things clearer:

(https://rmrk.net/proxy.php?request=http%3A%2F%2Fi25.photobucket.com%2Falbums%2Fc69%2Fiframe%2F4308.png&hash=c80b6cf93104e1fdec80f7fdc2ce3af26ded6caf)
red = player
blue = event
Title: Re: Get event name at (x,y)?
Post by: modern algebra on March 04, 2008, 09:53:57 PM
Hmm, there might be some built in way to do it. A problem is that even when you retrieve the event, you're out of luck because the event name is located in a private class variable. So here, try this:


#========================================================================
# ** Game_Event
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Summary of Changes:
#      new method : data
#========================================================================

class Game_Event < Game_Character
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Data
  #----------------------------------------------------------------------------------------------------------------------------
  #  Allows public, read-only access to the class variable, @event
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def data
    return @event.dup
  end
end

#========================================================================
# ** Game_Map
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Summary of Changes:
#      new method - check_for_events
#========================================================================

class Game_Map
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Check for Events
  #      x : the x coordinate of the square you want to check
  #      y : the y coordinate of the square you want to check
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def check_for_events (x, y)
    # Make an array to store all events on that square
    events_on_square = []
    # Determine which, if any, events are located at [x, y]
    @events.each_value { |i| events_on_square.push (i.data) if i.x == x && i.y == y }
    return events_on_square
  end
end


That will return in an array all of the events located at [x, y]. Keep in mind it only returns the base data since that is all you asked for. The code below will return everything related to the event, but to get to the base data you will need to use the code event.data


#========================================================================
# ** Game_Event
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Summary of Changes:
#      new method : data
#========================================================================

class Game_Event < Game_Character
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Data
  #----------------------------------------------------------------------------------------------------------------------------
  #  Allows public, read-only access to the class variable, @event
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def data
    return @event.dup
  end
end

#========================================================================
# ** Game_Map
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Summary of Changes:
#      new method - check_for_events
#========================================================================

class Game_Map
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Check for Events
  #      x : the x coordinate of the square you want to check
  #      y : the y coordinate of the square you want to check
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def check_for_events (x, y)
    # Make an array to store all events on that square
    events_on_square = []
    # Determine which, if any, events are located at [x, y]
    @events.each_value { |i| events_on_square.push (i.dup) if i.x == x && i.y == y }
    return events_on_square
  end
end


Also, data is probabably a poor name for the method, but you can play around with it.
Title: Re: Get event name at (x,y)?
Post by: ahref on March 04, 2008, 10:35:11 PM
thanks once again :D

i <3 you.
Title: Re: Get event name at (x,y)?
Post by: modern algebra on March 04, 2008, 11:24:34 PM
 :-[ Don't be. I just checked and discovered that the feature to check for events on a square is already built in:

$game_map.events_xy (x, y) does pretty much the same thing as the second code.

So really, all you need is the modification to Game_Event.
Title: Re: Get event name at (x,y)?
Post by: ahref on March 05, 2008, 12:04:00 AM
doh :( i tried using that but forgot to mention it and how i was trying to use it. however it still works now:D which got me out of a sticky spot