How to create a new event via Script?

Hi everybody,

I'm having trouble trying to create an event via script, at the moment I'm trying through the console but I haven't go any result so far.

I tried doing this:

$gameMap._events[4] = $gameMap._events[3];In the map i'm using for testing events go up only to 3 so with this line i tried to create a new event and copy it from an existing event to fill-out every paramenter in a way that should be functional.

The only thing this made is to speed up the event3, I guessed it had to do with the fact that at the moment of the creation the new event shares the same event Id with the mold, so maybe somewhere in the code his movement is called twice or something like that. At that point i tried to change the event id like this but it resulted in a fatal error:

$gameMap._events[4]._eventId = 4;So I searched for where in the script a new event is created calling the Game_Event constructor ad i found this

Game_Map.prototype.setupEvents = function() {    this._events = [];    for (var i = 0; i < $dataMap.events.length; i++) {        if ($dataMap.events) {            this._events = new Game_Event(this._mapId, i);        }    }    this._commonEvents = this.parallelCommonEvents().map(function(commonEvent) {        return new Game_CommonEvent(commonEvent.id);    });    this.refreshTileEvents();};So I tried this line

$gameMap._events[4] = new Game_Event($gameMap._mapId, 4);but it gave me error until i populated $dataMap.events[4], but still it doesn't seem to work properly.


Any Idea?
Which plugins have you installed for cloning events? Please link to them.


(You'll need a plugin for that as it's not exactly easy to do)
None at the moment, i was trying to do that by myself without any result, are there plugins around to do that?

edit: btw what i need is a way to create a new event via script for some uses, cloning one was just a makeshift solution i tried to do
edit: btw what i need is a way to create a new event via script for some uses, cloning one was just a makeshift solution i tried to do
I really suggest that you forget the idea to create events by script - that is much more complex, and the experience from Ace (where such a script was written by Tsukihime) shows that you're much better off to create the events in the editor and clone them from a master map than creating them by scripting.
The problem is that events can't be simply copied, they need to be cloned with the clone registered as a new event but keeping 99% of the original data (not 100% - that's why you need to clone it with new IDs instead of copying it)..
The idea of copying them from a master map seems not bad, you how could i do that? so far cloning for me has not gone very well lol 😛

Let's say for example i have this master map with like 2 or 3of these events, how can I clone them in the running map? i guess I'll have to do something like copying the $gameMap._events[] and the $dataMap.events[] as well and change the ids.
That is why I suggested to look for a clone event plugin - cloning needs a bit more than just copying data, and if I remember correctly someone already made such a plugin (or is working on one)
Ok I found this plugin http://forums.rpgmakerweb.com/index.php?/topic/46535-orange-custom-event-creator/

I'll try it and see if it works thank for the help!
I've moved this thread to JS/Plugin Support. Please be sure to post your threads in the correct forum next time. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-create-a-new-event-via-script.51494/