MZ [Solved] If I create an event using JS, how do I add a sprite to the event?

I copied an event from one cell to another cell using JS. (Screenshots are inside the spoiler tag.)

How can I add/change the event's image for the cloned event?

Thank you.

Spoiler: Illustration
001.png


002.png
So the question is why? It's quite easy to manipulate the image/pages of an event in the built-in editor, as well as set its contents, so why do it via code?

Is there an actual event there, or are you somehow creating it on the fly during the game? If there's an event, just make a page with the image you want and set the appropriate self-switch.
@ATT_Turan, I hope to make a sandbox game, with sayyy 500 NPCs commuting between multiple maps preserving their stats, names, etc.

This is very easy to accomplish using JS backend with a mere array of NPC objects. But for me such task is absolutely impossible using the built-in editor.

I have already managed to create the event using JS, everything is fine. I am struggling with how to give them an image.
Game_Event inherits from Game_Character which inherits from Game_CharacterBase

Check those areas to determine what calls need to be used to set a character bitmap.
I am suspecting this might do it:

JavaScript:
var sprite = new Sprite_Character(new_event);
SceneManager._scene._spriteset._characterSprites.push(sprite);
SceneManager._scene._spriteset._tilemap.addChild(sprite);
I am suspecting this might do it:

JavaScript:
var sprite = new Sprite_Character(new_event);
SceneManager._scene._spriteset._characterSprites.push(sprite);
SceneManager._scene._spriteset._tilemap.addChild(sprite);

Yup, and you'll see it based on how you set it up.

Give it a go
@Synrec I've been tinkering with it, but gives me an error that I am trying to troubleshoot.

Spoiler: Illustration
004.png

003.png
@Synrec I've been tinkering with it, but gives me an error that I am trying to troubleshoot.

Did you create an instance of the event?

Code:
let eventChar = new Game_Event();
eventChar.setCharacter(fileName, gfxIndex)

const eventSprite = new Sprite_Character(eventChar)
...
@Synrec indeed, I did create the copy of the event -- it works, blocks the way, and talks like the original event.

Still, I might be getting closer.

I.e. the following changes the image on the original character, but for some reason the cloned event is still elusively giving all kinds of errors:

JavaScript:
let image_set= 'People2'
let person_index= 2
$gameMap.event(2).setImage(image_set, person_index);

I.e. the original event's image set (those 8-character large sprite sheets) was "People1" and it used character #4 (these start at 0).

The code above changes the original event's image set to "People2", character #2.

But still, can't change the cloned event.
Turns out the plugin code I was studying had errors in how plugins clone event id.

The original sprite creation method works fine once I eliminated the ID errors.

Sorry, turns out the error was elsewhere.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/solved-if-i-create-an-event-using-js-how-do-i-add-a-sprite-to-the-event.140505/