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,261
Reaction score
1,214
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,025
Reaction score
5,906
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

FL Studio is a huge step up from LMMS but I'm having such a tough time with it D:<
The new Dune movie reminds me of the game Dune 2 made by Westwood. A quality product on its own, but extremely disloyal to its source of inspiration.
Terrible Writing Advice, you've done it again.
1635026211997.png
Feeling like my new profile picture is nice. Thinking of making it semi-permanent, does any one has an opinion? Does it look too evil or does it work as a public profile picture? :)
Bishiba.png

Forum statistics

Threads
116,033
Messages
1,095,125
Members
151,368
Latest member
aj1913
Top