NeptuneTron

The Salticid Scholar of the North
Veteran
Joined
Jan 13, 2018
Messages
81
Reaction score
48
First Language
English
Primarily Uses
RMMV
Is anyone aware of a way to use scripting to change the image of an event? Specifically, I need to be able to designate the image for the event using a variable. Any ideas?
 

glaphen

Veteran
Veteran
Joined
Jan 13, 2019
Messages
326
Reaction score
123
First Language
English
Primarily Uses
RMMV
I use this for all my events.
Code:
var varId = $gameVariables.value(7);
var tId = $gameVariables.value(varId);
var eId = $gameVariables.value(5);
var ttId = $gameVariables.value(eId);
var eeId = $gameVariables.value(6);
$gameMap.event(eeId).setImage('Enemy' + ttId, tId);
If I remember right eeId is enemy ID, 'Enemy' is picture name then the + adds the variable to the end of it and tId is index of picture.
 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,624
Reaction score
502
First Language
German
Primarily Uses
RMMV
It is not with Script but i just wanted to mention it in case it helps:
Create several Eventpages and mark a Variable as Page Condition.
Page1 variable1 = 0
Page2 Var1 = 1
page3 Var1 = 2
...
Every Eventpage can have its own Character Graphic.
When you change the Variable, the Eventpage will change automatically.
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
2,716
Reaction score
2,079
First Language
Portuguese - Br
Primarily Uses
RMMZ
Hi there!
You can change through script call the image of the event:
Code:
$gameMap.event(2)._characterName = "characterimage"

Also, you can change the current index that the event is using in this image:
Code:
$gameMap.event(2)._characterIndex = X

The first one must be a string(a word inside quotes), that has to be the name of an image that it is inside your img/character folder.

In the second one, you have to replace the X for a number of 0 to 7.
gu77JJ0.png


So, to use variables to change the images, you can set a variable value to a string through the script call field(without the file extension) in Control Variable operation. Then, you use this script call:
Code:
$gameMap.event(2)._characterName = $gameVariables.value(x);

And to change the index, you only have to set a number value from 0 to 7 in any variable you want, then you call the script call:
Code:
$gameMap.event(2)._characterIndex = $gameVariable.value(x);

I do not test changing maps to see if the image still prevails.
Hope it helps!
 

NeptuneTron

The Salticid Scholar of the North
Veteran
Joined
Jan 13, 2018
Messages
81
Reaction score
48
First Language
English
Primarily Uses
RMMV
Thank you everyone for your excellent replies!

By cobbling together all of your replies and some other various information, I've managed to write a simple bit of code that will do this.

Ruby:
$gameMap.event(this.eventId()).setImage($gameActors.actor($gameVariables.value(n)).characterName(),$gameActors.actor($gameVariables.value(n)).characterIndex())

That looks complicated, but it's not so bad.

Let's break it down

Ruby:
$gameMap.event(A).setImage(B,C)
This is the basic function itself (Big thank you to glaphen on that one). Here, A is the Event ID of whatever event you're trying to change, and B is the filename where the image you'll be using to replace is located, and C is the index within the file of the specific image (Thanks to Eliaquim for that explanation).

Code:
this.eventId()
This is what you can use to determine the event ID (A) of any event, meaning that you can just copy this script into whichever event you want to use without manually finding the Event ID, or you can even use this in a Common Event (which I would highly recommend, as it will simplify your life greatly)

Code:
$gameActors.actor(D).characterName()
This returns the filename (B) for the image you want to use, where D is the Actor ID you want to use.

Code:
$gameActors.actor(D).characterIndex()
This returns the index (C) within the file image you'll be using, where D is the Actor ID you'll be using.

Code:
$gameVariables.value(n)
This is just a snippet of code that references the n-th variable, which I used to determine/select D. You always want to use the same variable number, but which number specifically used makes no difference. For instance, I used the variable 0006. You'll need to set the value of this variable appropriately, probably using another bit of code, or a common event.

In terms of setting the value of whatever variable you're using to something actually useful, you can use the "Control Variables" event command with the following script.
Code:
$gameParty.leader().actorId()
This will return the Actor ID of whoever is leading your party, to be used as D to define B and C.

I think that's pretty much the whole of it. Have a good day, or evening, or whatever time it happens to be.
 

Nemesis666

Veteran
Veteran
Joined
Sep 5, 2019
Messages
87
Reaction score
11
First Language
FR
Primarily Uses
RMMV
Hi, it's very interesting. I'm jumping on this "not that old topic" (watching behind him, if a moderator is not far), but I have a small issue on my side : when I select an Index, the character is putting his leg in front of him like if he was going to "walk" (he is static), but none of the 4 checkboxes are checked : "Walk", "step to step", etc...

Any idea ?
 

NeptuneTron

The Salticid Scholar of the North
Veteran
Joined
Jan 13, 2018
Messages
81
Reaction score
48
First Language
English
Primarily Uses
RMMV
Hi, it's very interesting. I'm jumping on this "not that old topic" (watching behind him, if a moderator is not far), but I have a small issue on my side : when I select an Index, the character is putting his leg in front of him like if he was going to "walk" (he is static), but none of the 4 checkboxes are checked : "Walk", "step to step", etc...

Any idea ?
This is probably the result of how your character images are organized. I believe the default is to select the middle column in whatever direction you're facing, until you walk. There doesn't seem to be a way to easily select/change which one the three states you're using, so you essentially have to design your walking animations with that in mind

As an example

1642495296048.png
If you're using character 0 from this file, the default will be the whatever direction is appropriate for the blue box. If you're using character 3 from this file, it would be the orange box.
 

Nemesis666

Veteran
Veteran
Joined
Sep 5, 2019
Messages
87
Reaction score
11
First Language
FR
Primarily Uses
RMMV
Unfortunately, it takes the image 0 of the character X you choose, but there is a solution (in my example, used with Yanfly Spawn Event) :

$gameMap.LastSpawnedEvent()._originalPattern = 1;
And
$gameMap.LastSpawnedEvent().resetPattern();
The first one fix the issue of the ghost walking, the second one fix the issue of the first one which make images to "clip" xD .

Yes, it's complicated, but in the end, it works :p !

Thx ;) !
 

NeptuneTron

The Salticid Scholar of the North
Veteran
Joined
Jan 13, 2018
Messages
81
Reaction score
48
First Language
English
Primarily Uses
RMMV
I don't think I really understand your problem, how you solved it, or how it relates to the topic of this thread exactly, but I'm glad you somehow got it to work!
 

Nemesis666

Veteran
Veteran
Joined
Sep 5, 2019
Messages
87
Reaction score
11
First Language
FR
Primarily Uses
RMMV
Let's resume :

When you change the image with a variable, you obtain a bug, the software dont select the image "1" of the charset X (let's say "1" for example), it chooses the image 0 of the charset 1.
This is an issue, because this image is a walking pattern image.

The solution is to force him to choose the image 1. => ._originalPattern = 1;

BUT, this create a new bug : the new image is "cliping" each time we call it. This is the moment to reset the pattern sequence. => .resetPattern();

That's it ;) !
 

Latest Threads

Latest Profile Posts

Beep-Beep-Motha-facka.gif

Just finished and uploaded the delivery truck base/sprite sheet. I've been steadily replacing the default assets with early modern alternatives. The air-ship for a biplane, horse-drawn wagon for a delivery truck, and next a sailboat for a steam-powered passenger liner (think of the SS Olympic and RMS Titanic).
I caught a shiny magikarp on pokemonGO today AND finally saw Detective Pikachu and it was so cute and I'm still so hype AHHHHH!!!
one of the coolest things I've learned from the forums is the ability to give yourself a hitbox. I have a move you can do on the fields. shoulder tackle. thanks to the forums, that tackle triggers self A switches on some events. NPC's and the environment now react to the tackle. awesome.
I really liked how this one turned out! :kaopride:
WYqMPf6.png

Character (Yes, this is a character): Nibiru the Primal Being from Yugioh.
Dragon Quest style enemy selection plugin work in progress:

Quest_Targeting.png

It's a simple targeting system from the NES era. Select an enemy group; single-target skills will target the first enemy in that group.

Quest-Targeting-Animated.gif

Forum statistics

Threads
121,936
Messages
1,145,292
Members
160,208
Latest member
kishanth
Top