The RPG Maker Resource Kit

RMRK RPG Maker Creation => Requests => Script Request => Topic started by: czernobog on November 04, 2011, 12:59:06 AM

Title: Finding an events ID from the event name
Post by: czernobog on November 04, 2011, 12:59:06 AM
I am trying to find the ID of a map event by using that event's name. I might have "Enemy1" be event # 005 on one map, but it might be event # 002 on another. So I am hoping to use "Enemy1" from the name box to help me find that event's ID#.

I have been trying so far and have only gotten this

  def find_enemy_event_ID(i)
    # Determine the enemies' event IDs
    $events ||= load_data('data/MapInfos.rxdata')
    for key, value in $events
      return key if value == "Enemy" + (i).to_s
    end
      return 000
  end
 

Where i would be the enemy# I am looking for
I don't know if this is just incorrect coding or if it is even possible to retrieve the information I need like this. I am trying to modify some code Zeriab previously helped me with, but I do not know where the information I need is stored.

Any help would be greatly appreciated.
Title: Re: Finding an events ID from the event name
Post by: Zeriab on November 05, 2011, 02:13:53 PM
MapInfos.rxdata contains the information needed for building the map tree you see in the editor. It does not contain the information you are looking for.
Assuming you need to look at the events on the current map then need to expose the name in Game_Event (present in its internal @event which is an RPG::Event).
After that you can just look at the events in $game_map. (You can consider making a method there for finding what you want)

Do consider the case where multiple events has the name you are looking for. What then?
Do you want a particular one?
All of them?
Any one, doesn't matter which?
The name you are looking for should be unique? (In that case consider throwing an error if $DEBUG to let the game dev know of the problem)

P.s. be careful about leading zeroes. 000 is just fine, but try 009 and you'll see what I mean.

*hugs*
 - Zeriab
Title: Re: Finding an events ID from the event name
Post by: czernobog on November 06, 2011, 05:19:56 PM
Thank you for the help. I'm still trying to get this figured out, but I will post when I get some kind of results.