Help with Getting an Item's Icon Index (Not in the database)

Hello, I'm having a problem with getting an item's icon.

Let me explain a couple of things:

Plugin Involved:
- Yanfly's Self Switch and Variables
- Yanfly's Icon on Event


ss1.png


1. Shows a text.
2. Ask the player to pick an item and store it in a self variable called 'sellingItem'.

ss2.png


This second image shows where I'm having a problem, I can't seem to find the proper way of displaying the item's assigned icon on the event. Thus, as you can see, I have to rely on event pages just to tell the game what icons to display on the event based on the selected item of the player. What I'm doing is 1 item and 1 icon per page and this is so inefficient in doing it plus MV only has a maximum event page of 20 considering the fact that I have hundreds of items to select to.

Please don't give me a plugin to increase the max number of event pages as I mentioned that I find that method too clunky. What I'm looking for is an efficient way of doing this like:

- Fetch the item
- Get the item's icon index and store it somewhere.
- Tell the game to display THAT stored icon on the event using Yanfly's Icon on Event plugin. Another method should suffice if yanfly's plugin can't do it.

In other words, the first line in the second image needs to be flexible instead of being <Icon on Event: 372> (aka manually setting the icon) but rather having it fetches the selected item, get its icon, store it and then output the icon regardless of the selected item I want it to always output the assigned icon of the item.

In even more simpler words, I want to display a selected item's icon on an event.


I'm sorry if I explained badly. Anybody can help me out?
Hello, this might do what you want:
Code:
let target = $gameMap.event(X);
let sellingItem = $gameVariables.value(Y)
let icon = $dataItems[sellingItem].iconIndex
target.setIconOnEvent(icon);
Put this in a script box in the event, bellow the item selection call.
*replace X by the Event ID and Y by your game variable 'Self Var SellingItem' ID.
Hello, this might do what you want:
Code:
let target = $gameMap.event(X);
let sellingItem = $gameVariables.value(Y)
let icon = $dataItems[sellingItem].iconIndex
target.setIconOnEvent(icon);
Put this in a script box in the event, bellow the item selection call.
*replace X by the Event ID and Y by your game variable 'Self Var SellingItem' ID.


Hi, thank you so much for your help. It does get the proper icon of the item correctly but I needed to get the current event ID so I changed some lines.

JavaScript:
let target = this.character(0);
let sellingItem = this.getSelfVariableValue(mapID, this.eventId(), selfvarID);
let icon = $dataItems[sellingItem].iconIndex;
target.setIconOnEvent(icon);

I changed it so it will get the current event ID instead of manually putting it there because I'm using yanfly's event spawner and I'm spawning dozens of events so I don't have to write 1001, 1002, etc.

Without your help, I won't be able to figure out the solution. This saves me alot of time and effort from manually detecting the selected item and doing a bunch of IF's statements. Big thanks :LZSsmile:

Original thread: https://forums.rpgmakerweb.com/threads/help-with-getting-an-items-icon-index-not-in-the-database.117955/