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
57
Reaction score
28
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,250
Reaction score
1,209
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
57
Reaction score
28
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
168
Reaction score
100
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
57
Reaction score
28
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
168
Reaction score
100
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
57
Reaction score
28
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
168
Reaction score
100
First Language
English
Primarily Uses
RMMV

Sepheyer

Veteran
Veteran
Joined
Jul 20, 2021
Messages
57
Reaction score
28
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
57
Reaction score
28
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,023
Reaction score
5,905
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

thought I'd upgrade to mz from mv cause of the nice quality of life features but ****ing hell why couldn't they allow old plugins to work in it and secondly how come in over a year since it's release has there been no mz version of something so crucial as a non grid based movement plugin. I guess I'll stick with mv. (why wasnt mz just an update to mv anyway literally nothing substantial changed..)
Something might be coming...
Hallo.png
A new day for creating :)
2021 has been the runner-up for the worst year of my life. 2015 may take that title, but '21 is pushing it. Excuses really don't justify how much of a jerk I've been this year to a lot of people.

I'm sorry. I don't intend to be a jerk forever, but I'd rather back up my intent with actions, not words.

Forum statistics

Threads
116,020
Messages
1,094,980
Members
151,337
Latest member
Laura1999
Top