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

Status
Not open for further replies.

Sepheyer

Veteran
Veteran
Joined
Jul 20, 2021
Messages
59
Reaction score
29
First Language
English
Primarily Uses
RMMZ
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.

001.png

002.png
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,746
Reaction score
1,611
First Language
English
Primarily Uses
RMMV
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.
 

Sepheyer

Veteran
Veteran
Joined
Jul 20, 2021
Messages
59
Reaction score
29
First Language
English
Primarily Uses
RMMZ
@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.
 

Synrec

Veteran
Veteran
Joined
Nov 6, 2019
Messages
193
Reaction score
128
First Language
English
Primarily Uses
RMMV
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.
 

Sepheyer

Veteran
Veteran
Joined
Jul 20, 2021
Messages
59
Reaction score
29
First Language
English
Primarily Uses
RMMZ
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);
 

Synrec

Veteran
Veteran
Joined
Nov 6, 2019
Messages
193
Reaction score
128
First Language
English
Primarily Uses
RMMV
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
 

Sepheyer

Veteran
Veteran
Joined
Jul 20, 2021
Messages
59
Reaction score
29
First Language
English
Primarily Uses
RMMZ
@Synrec I've been tinkering with it, but gives me an error that I am trying to troubleshoot.

004.png
003.png
 

Synrec

Veteran
Veteran
Joined
Nov 6, 2019
Messages
193
Reaction score
128
First Language
English
Primarily Uses
RMMV

Sepheyer

Veteran
Veteran
Joined
Jul 20, 2021
Messages
59
Reaction score
29
First Language
English
Primarily Uses
RMMZ
@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.
 

Sepheyer

Veteran
Veteran
Joined
Jul 20, 2021
Messages
59
Reaction score
29
First Language
English
Primarily Uses
RMMZ
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.
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
9,112
Reaction score
5,963
First Language
Dutch
Primarily Uses
RMXP

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.

 
Status
Not open for further replies.

Latest Threads

Latest Profile Posts


It's a Spanish devlog don't get scared!.
Just read the forum rules just for kicks and rule 14 reminds me of this:
150.jpg
I'm in the process of converting all locks and intimidate/persuade dialogue options into D20 DC based success/fail (modified by player skill). Before, it required a certain flat amount you had to meet, but with rolls, it offers more freedom. For instance, you can repeatedly try to unlock a door instead of just not meeting the requirement to unlock it.
Since we get very close: If you want to enjoy the advent calendar as it is intended, wait til your date and the day in the URL line up, so you have the final day on actual christmas and not the day before... time zones ;3
1638170340913.png
Crossover Inn is getting very crowded, and I love it

Forum statistics

Threads
117,050
Messages
1,104,139
Members
153,003
Latest member
Santii
Top