Changing Event Images with Variables

NeptuneTron

The Salticid Scholar of the North
Veteran
Joined
Jan 13, 2018
Messages
40
Reaction score
25
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
120
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,492
Reaction score
408
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
1,695
Reaction score
1,113
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.


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
40
Reaction score
25
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.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,849
Messages
1,016,975
Members
137,563
Latest member
cexojow
Top