Good way to add dynamic events to the map?

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,848
First Language
English
Right now I'm working with dynamic event spawning on the map.



I could always pre-create some static events and then just move them around as needed, but if I want the event to be spawned in any map, I'd rather just keep the event in one "set up" map and then just generate a new event using that as a template.


Ok, so creating a new event involves picking an ID. I could probably safely assume the length of the event list + 1, unless I'm really generating a lot of events and I hit some limit.


Once an ID is picked, I just need to create a Game_Event object and then assign it to the array of events.


Now, how would I have the spriteset know to draw it?


The spriteset is held by the current scene


1. I could have a method in Spriteset_Map constantly poll the map for any new events that need to be added.


2. I could have tell SceneManager to tell the current scene to call a certain method in the current spriteset.


3. I could explicitly access the current scene through the SceneManager and tell the spriteset to do something (which is like #2 except I'm being more intrusive)


For me, #2 makes the most sense. The SceneManager is in charge of managing the scene, so if I need the scene to do something, I can go tell the scene manager to do it.



I don't like #1 because polling requires constant resource use, and "event spawning" should ideally just fire a trigger that sends a new task to the spriteset, and it's up to the spriteset to determine whether there are any tasks to do.


However, this means that the spriteset is still going to be polling its own list of tasks to do, which is no different from just having it poll the map for any changes in the first place (maybe a bit better in design)


Having the map create a new event is easy, but how should I tell the spriteset to generate new sprites?
 

Quxios

Veteran
Veteran
Joined
Jan 8, 2014
Messages
1,055
Reaction score
785
First Language
English
Primarily Uses
RMMV
In my ABS I went with your #2 method. I would call a function that looked like:


QuasiABS.Manager.addLoot = function(loot) {
var scene = SceneManager._scene;
if (scene.constructor !== Scene_Map) return;
loot._eventId = $gameMap._events.length;
this.loot.push(loot);
$gameMap._events.push(loot);
var sprite = new Sprite_Character(loot);
scene._spriteset._tilemap.addChild(sprite);
};


the loot was already a Game_Character object. I was also unsure with what to use for the Id, but I just went with the event list size.
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,848
First Language
English
For #2 I was thinking something like this


SceneManager.addSomeEvent = function(ev) {
this._scene.addSomeEvent(ev);
};

Scene_Base.prototype.addSomeSprite = function(ev) {
// stub. Other scenes can use if needed
};

Scene_Map.prototype.addSomeSprite = function(ev) {
// do stuff with ev
};


And all requests would go through SceneManager.


So if someone had like their own map scene, they could handle new stuff just by adding an implementation to the method I provide.
 
Last edited by a moderator:

Quxios

Veteran
Veteran
Joined
Jan 8, 2014
Messages
1,055
Reaction score
785
First Language
English
Primarily Uses
RMMV
Ah yes, I was originally writing it in a similar way as that. But then I was like, this is too many functions, I'll just keep as in a single function. Though I was expecting anyone to be using any of my functions.
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,848
First Language
English
One concern I have with using the length of the array plus 1 as event ID is that if lots of events were being spawned, you might run into a scenario where you have a huge array.


Not sure if that would actually be a problem in general, especially for things like loot where you probably aren't going to have millions of loot being dropped on the same map, without having changed maps and refreshing that array.


I'm currently standardizing event deletion to just null out the element, which allows me to re-use that index again.
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,546
Reaction score
3,717
First Language
Java's Crypt
Primarily Uses
RMMZ
I've been through this before, when building the OrangeCustomEvents plugin.


Back on Ace, I had modified your script to use my own event Id list starting at 1000. When I made the same thing on MV, some people reported having some lag.


I didn't want to simply use Length + 1, because I had a lot of problems with that on Ace: If you create an event via script, save your game and then modify the map to add a new event, that new event would pick the save ID I picked for my event and it wouldn't appear at all when the player reloads the game. Using event ID's starting at 1000 solved the problem for Ace, but in MV I had to do something else:


Game_Map.prototype.getIndexForNewEvent = function() {
var index = 1;
while (index < this._events.length && !!this._events[index]) {
index++;
}

return index;
};




I iterate over all existing events to get the first ID that is not used by any event. To avoid the problem I mentioned earlier, everytime the game is loaded or the player enters a new map, I pick a fresh ID for all of my events:


var oldGameMap_setupEvents = Game_Map.prototype.setupEvents;
Game_Map.prototype.setupEvents = function() {
oldGameMap_setupEvents.call(this);

var customEvents = $gameSystem.getCustomEvents(this._mapId);
for (var eventId in customEvents) {
if (customEvents[eventId] === undefined) continue;
var newEventId = this.getIndexForNewEvent();

customEvents[eventId].eventId = newEventId;
this._events[newEventId] = new Game_Custom_Event(this._mapId, newEventId, customEvents[eventId]);
}
};




This solved both the lag and the problem of events not appearing when loading old save files.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.

Forum statistics

Threads
106,035
Messages
1,018,454
Members
137,821
Latest member
Capterson
Top