Main Menu
  • Welcome to The RPG Maker Resource Kit.

Finding an events ID from the event name

Started by czernobog, November 04, 2011, 12:59:06 AM

0 Members and 1 Guest are viewing this topic.

czernobog

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.

Zeriab

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

czernobog

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.