Spawn Event

Last Updated: 2012.02.08
Download Link
Github Link

For those who would like to spawn pre-made events from the current map or even other maps, this script allows you to do so. With the option of spawning the events at specific locations or a random spot marked by a certain region, you can have events spawn using simple script calls. The events remain until a map change.

The following lines are script calls:

spawn_event_location(x, y, event_id)
spawn_event_location(x, y, event_id, map_id)

This causes a new event to be created at location x and y on the current map. The event to be created will use the event data from event_id. If no map_id is used, then the current map’s event will be used to spawn the new event. The event cannot spawn on top of another event or vehicle. If there is an event or vehicle in place, then no event will be spawned at all.

spawn_event_region(region_id, event_id)
spawn_event_region(region_id, event_id, map_id)

This causes a new event to be created at a random location with a matching region_id. The event to be created will use the event data from event_id. If no map_id is used, then the current map’s event will be used to spawn the new event. If the region_id does not exist on the current map, then no event will be spawned. The event will not spawn on top of another event nor on top of a vehicle. If there is not enough room to spawn an event, then no event will be spawned at all. This process takes slightly longer on larger maps.

And that’s all, folks!

34 comments on “Spawn Event

  1. Nice script! I’m also working on an event spawner, although it’s not doing exactly the same thing as this script (whew!). Just wanted to let you know about something I found out when working on my script. Look at this line from your script:

    key_id = @events.size + 1

    The problem with this is that if the game creator makes a bunch of events they will get ids in ascending order. But if an event is deleted (from the editor) the ids stay the same, so there’s a “gap” in the events id hash.

    So if you use the total size of the hash to calculate the event id there’s the risk of getting an id that is already used (because the size of the events hash can be less than the max id in the hash).

    So what I did was to get the maximum id in the hash, and then increment that value by 1. That way there’s no risk of getting an id that is already in use.

  2. Could this also work by setting the event to spawn near/where the player is? So, something like this:

    spawn_event_location(player_x, player_y-1, 1)
    spawn_event_location(player_x+2, player_y, 1)

    • Just make it appear anywhere, with a parallell process of teleporting to the player. Would solve it, and does also solve the “Can’t be spawned on another event”

  3. 1. Is there a way to make the events have separate ids? because atm the act like the are all one event. (if you activate a self switch on one of them it gets activated at all of them)
    2. it does not work inside parallel processes but i think that cant be fixed that easily.

  4. Very cool script! This looks to be a good starting point for some awesome scripts. For example, I could see this being modified so that monsters spawn within a given range of the player and despawn if they get too far away (sorta like overland encounters in Tales of Vesperia).

    It’s a bit problematic though. As Rodi mentioned, the copied events all have the same ids. But even worse, the events copied from the other map could potentially share the same id as events that already exist on the current map. This results in any commands that are event_id specific affecting not only the copies, but the pre-existing event too.

    I can see this is because the event_ids are stored in the map.rvdata2 file and that the id values are brought right into the Game_CharacterBase class when calling There aren’t any checks for uniqueness or anything done to correct it.

    I’ve only just started learning RGSS scripting, so I’m not sure how to fix it. Perhaps in your spawn_event method you could also track the highest event_id on the map and then update the copied to the next higher value before calling I’d try it, but I’m not sure on what the syntax would be. Ruby and RGSS are easy enough to follow, but knowing how to do what you want to do is another matter…

  5. This script has some issues.
    If you already have an event with id:09 and you use spawn_event(x,y,9,otherMap) the event with id 9 !on your current map! will get the code. It will still create the event from the other map, with graphics on the right position, but with no code.
    Guess theres something messed up whith the eventIDs when the script copies the code to the new event.

    • Strange. The script itself works fine. But together with your Event Chase Player i have some issues. (Trying to create an Npc who simply follows you on some maps.)
      I’ve created a small testmap which shows my problem.
      On map 1 theres an NPC you can talk with. After talk she will follow you. If you switch to map 2 the other event will follow you, not the one which gets created during autorun.

  6. Hello Yanfly,
    could you please repair problem with self switches? :( This script could be really useful, but withouts self switches its kind of pointless. Please, answer.

  7. I’m trying to create a psuado-random dungeon generator by using the Random Generator on template maps then copying & pasting them onto a 500×500 map to make different generated areas. I’m using 100×100 maps so I can fit up to 25 different areas on one map. This script would help randomly place my events around but I rely on a randomly generated variable to determine which section the player gets transferred to. I want to label the floor tiles in each section with Region IDs so they won’t get placed in walls & ceilings, but the script requires you to specify only 1 predetermined Region ID. I need to label each section with a different region ID so that the events get placed in the right section.

    So I was wondering if you could set an option that would check a custom variable to determine which region ID the events get placed on. It would be too difficult to try to make separate events for each section (1 staircase, 1 recovery point, 20 chests & 40 enemies to randomly place). That would be WAY too many events on one map, & would be equally difficult to try to use eventing to workaround it. So if you could add this option to the script I would appreciate it very much. Thank you.

  8. They commit their selves to specific exercise and a healthy diet to help them regain their
    body shape and curves before they got pregnant. She tearfully mentioned that she is
    not responsible of murdering or stealing. It is important that you
    have a healthy emotional outlook before you have any surgery.

  9. Success in business is determined by what you communicate to your consumer – he must
    be convinced that you have what he needs. You may want to make another research
    on this topic. So if you were able to get your business started, you can expect that you will have a better performance when it comes
    to making sales.

  10. Compared to popular 2-piece bikinis or backless swimsuits, modest swimwear covers much more skin, yet still delivers a lot of style.
    4 Easy Principles of Eating to Eliminate Body weight.

    The majority of fabric of the top and bottom is a solid black background with
    gorgeous pink roses.

  11. Mesh swimwear are formed like consistent swimwear but areas of it
    are manufactured out of a complicated mesh of the same exact
    correct fiber. Swimwear Galore knows the worth of great water
    gear, from Jessica Allen’s Jets swimwear to the men’s Funky Trunks line.
    Find a style that would enhance your figure like a plain top with thin straps then focus on your bottom.

  12. There are many types of gifts that can be given for Father’s Day.

    Cufflinks, money clips, and business card cases are just a few gift items that are possible to personalize these days.
    A while back I dated a guy for about two years,
    he was the best “gift giving” guy I’ve ever met in my life.

  13. , Hays are giving away other exciting prizes: you could also win holiday vouchers,
    an i – Pod, i – Pad and i – Phone. Find hotels that cater to the traveling businessperson. different companies give you their estimates over the phone.

  14. The faculty shall prepare you in realizing your aspiration by offering you a conducive mastering natural environment for holistic
    growth. It may also imply you have a chance to take part in pursuits or go to attractions that weren’t previously on your to
    do list because of costs. If you do not require a rental, a really good agent will
    make sure there are shuttles to and from your hotel
    before reserving a room.

  15. Internet affiliate marketing refers to choosing someone else’s product or service and marketing it for them online.
    This is exactly where you find the work at online home jobs dropping out of helping hand.
    Treasury note are sold with maturities of 2 to 10
    years and Treasury bonds have a 30-year maturity.

  16. They are not meant to be employed on a regular foundation. Penile surgery can achieve three important things for you: penis enlargement,
    penis enhancement and correction of penis curves. Some
    men who suffer from impotence use the penis pump to get an erection by
    placing a compression ring at the base of the penis and use the vacuum pump.

  17. Uhh, i need some help with this script
    it’s absolutely necessary that I get this to work for my game too or find something like this, so I’m kinda desperate :S
    I have an event that has variables set to the players position to place the event at their feet
    the event is currently on the same event as the player, too, btw
    I have the script as “spawn_event_location($game_variables[1],
    $game_variables[2], 3)”
    but nothing seems to happen when the event is activated.
    I’ve tried subtracting from the X variable so that it’ll be placed next to them instead because I thought it might be conflicting with the player itself, but still nothing.
    I’m not really sure how to get it to do how it’s supposed to do and I need to get this figured out by the end of this week, so can you help me out if you have the time?
    I’m not really sure what I’m doing wrong.

  18. Whenever I try to get an event from a different map it seems to replace or eliminate events from the current map. Such as autoruns and parallel events. I’ve played with it 2 hours, stripped out all other scripts and even started a game from scratch and I still have the same problem when spawning events from different maps.

  19. YanFly Hi I have problem when spawning event on diffrent map it spawn but hisa page is set to the last – as a switch A for example… why’s that ? and how change that ?

  20. I identified the following problem: when the event is spawned on the map, its ID receives the same ID that the ID of the last event created in the map, so that, the spawned event overwrites the already existing event, causing malfunction. My solution was to add and empty event at when I finish to insert all the events taht I want, avoiding further problems in the map.

  21. One limitation of rpg maker is that npc’s can’t be referenced as events. You can however make an event appear as an npc but it can’t be called because events can only be triggered. Which is a real bummer, because essentially you can’t create dynamic characters.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s