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.

Random Events?

Zymgo

Member

Greetings all,
Im a noob to RMXP, only found it a couple of months ago, and Ive been playing with it. Im a programmer and I have created a random level generator that seems to work fairly well (i still need to work on the algorithms) but now I need to create random events on the map.

From what I can see, events are held in a hash of RPG:Event objects, but Im not sure how to create a new event object, with its other necessary objects (RPG::Event::Page,RPG::Event::Page::Condition, etc) so I can add it to the hash. Any clues are appreciated.

I was also wondering if the event objects are organised in the hash in any particular way (IE. by x,y coords, autorun events first, etc).

Many Thanks in Advance :)
 
Correctly ^^

The events are organized by its ID. When you create a new event the RMXP looks for the smallest available ID and make that new event´s id that number. Like, you have events 1, 2 and 4. When you create a new event it´ll be 3, got it?

Technically a way of creating random events could be close to impossible, but it´s just CLOSE. All the RPG module classes are hardcoded, they´re automatically generated when you alter anything on the game and saves it. Most of the things in the contents of an event are really complicated, how they correlates...

This event array is put into a property in RPG::Map called events. As you may know each map event has several pages created by you. Each page is represented by a RPG::Event::Page object, and is inside the property pages of RPG::Event. RPG::Event::Page defines the actual event graphics, several conditions and the commands it will do. The conditions are held at RPG::Event::Page.condition, that has a RPG::Event::Page::Condition object. Graphics data is held at RPG::Event::Page.graphic, that has a RPG::Event::Page::Graphic object. By other means...

RPG::Event
PAGE 1
* RPG::Event::Page
> RPG::Event::Page::Graphic
> RPG::Event::Page::Condition​

PAGE 2
* RPG::Event::Page
> RPG::Event::Page::Graphic
> RPG::Event::Page::Condition​

PAGE 3
* RPG::Event::Page
> RPG::Event::Page::Graphic
> RPG::Event::Page::Condition​

... And so on...


Each time a map is loaded Game_Map loads the map´s file and create a new Game_Event for each RPG::Event in that map´s event hash. Those Game_Event objects are all put into another hash in Game_Map that can be accessed via Game_Map.events.

How Game_Event works doesn´t matter at all, but you should study how is the data inside RPG::Event and make a process that creates a new event and arbitrarily defines its properties. After that, before loading a map in Game_Map, you should make your objects to be added in Game_Map.events to make them really make part of the map. Game_Map should do all the rest.

In case you want to add a random event on any time (not only at the load), you must add a method in Game_Map to add a new event (transform that RPG::Event into a Game_Event and add it to Game_Map.events), and also add a method in Spriteset_Map (for you to add a new sprite for that new event, or else it won´t show up in the screen). That should be almost all you need to do, i think the painful part will be the event generator.

I could explain it in more depth but now i´m really tired, i have to sleep ^^ I´ll make that later.
 
I just finished my new event spawner system. It allows you to do anything you could do in event wizard, and is extremely organized and documenting.

With that, you more or less could use one of my built-in functions to create events by setting up an array of possible events, and just randomly choosing placement on tiles and randomly choosing which event.

It wouldn't be much work for you at all. ^_^
 

Zymgo

Member

Linkin_T
Great info, that does help. I understand the structure, but im not sure how to fill the objects with their appropriate values. Complicated is an understatement LOL

SephirothSpawn
That sounds like exactly what i need, especially something well documented and organised. Bravo!! Were you perhaps going to release it, and if so could I bother you for a copy??

A little clarification. Im not really trying to create random events, but specific events randomly tossed around on the map. I will need teleport events for leaving the map, npc events, chests, traps, etc... that will be placed on the map once it is created. I wont be adding events after the initial map creation.

Linkin_T;113802 said:
I think he kind of want to make it by himself... (or am i wrong?)

Not Necessarily, I dont see any need to 'reinvent the wheel'. Ive been a programmer for a long time and if there is already code out there that does what i want I will use it. Basically im lazy LOL

Please do not double post. Use the Edit button.
 

Zymgo

Member

Apologies for the double post, I was posting my first response when Linkin_T posted, so I didnt see it till I had submitted my response.

I will wait patiently for Sephiroth to repost his test bed.

Many Thanks!
 
So i´m the only one that finds fun on "reinvent" things on my own way, that wants to practice real scripting to really learn instead of just copy-and-paste things.

But surely, that should be a timesaver for you.
 
You aren't alone Linkin. Many of my scripts are works others have done. I was simply offering my work as something to use, or use as a refrence. I know an event spawner system is nothing anybody wants to do (This script itself is under 300 lines, where I have almost 1000 in commenting and documentation of the event command code, parameter description, etc.)

Since you have been so patient, I will try to upload it tonight for you and post the script text file here for you before I go to bed. There is going to be a slight delay on the test bed, since my boss took away my days off and made me work almost 2 weeks straight... :(
 

Zymgo

Member

Actually I will probably use it as a reference, since i will be coding for a very specific purpose, but im sure it will show me how to do what i want to do. And the documentation of the events and parameters will be most helpful, im sure. Im not really a cut n paste kinda guy, I have to understand it before i will use it. And i love to just play with code, just to see what i can make it do.

I actually built an object oriented side scrolling game engine about 10 years ago (in pascal no less), and im pretty impressed with RMXP.

Seph, I appreciate it. And if you dont get to it right away, no worries, I have PLENTY of other coding to do LOL
 
Ok. As I said, it is a rather large script due to the comment lines.

Event Spawner BETA

The few event commands between the #▼▼▼ are not yet commented on. I will finish that tomorrow.


It can create, clone and permanetely save events on the map data. There's a bunch of stuff to go through, but I won't go through this quite yet.


For you and your random event creation, you would only need to do something like this:

Code:
presets = Event_Spawner::Presets
events = ['presets.event_a', 'presets.event_b', 'presets.event_c', ...]
x.times do
  event = events[rand(events.size)]
  map_x = <pick_valid_x>
  map_y = <pick_valid_y>
  eval event
end

There's a bit more to do, but that is close to about it. The Event_Spawner::Presets module serves as nothing more than a bunch of preset script calls, but more powerful as you can assign method parameters to assign things like x and y locations (See Example in script).


If you have any questions, just let me know. I didn't make this as n00b friendly (not that you are) as I did scripter friendly. (I haven't had time to fully test this, so if you see any errors, let me know)
 

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