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,835
Reaction score
1,659
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
194
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
194
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
194
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,116
Reaction score
5,971
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 Posts

Latest Profile Posts

party time.png
If you've played Knight Shift Chapter 1 this image'll mean something to you. If not, that's also fine!
Here's a medical question for ya: Why do I start lightly coughing after I drink coffee?
Well, someone "reviewed" my game. Didn't credit me anywhere in the video and spent 2 minutes insulting it. Going to ignore that and move on.
To cut down on map lag, I've been researching how to implement a lighting layer as a single map overlay instead of a bunch of individual lights. Hopefully I'll have a screenshot soon!
Imagine having a game broken up into a whole bunch of chapters? Like Chapter 11 should be about the party members going bankrupt.

Forum statistics

Threads
117,264
Messages
1,105,951
Members
153,440
Latest member
VicArt
Top