MZ Need help with altering a Script

SRD HUD Maker Pro

So I'm using SRD HUD Maker Pro, I'm trying to get Icons to display to show what is equipped in my custom menu. I have found a script that works perfect to get the currently equipped weapons ID. I have my Icons set up in order of the weapons, Items, Armors. So weapon 1 would be Icon 1 and Weapon 2 would be Icon 2 and so on, but Items and Armors I would either have to set a bunch of "blank" items before I get to the first item to keep the Icon array going correctly or just add 100 to this script, but I'm not sure where to add the 100?

Script is
JavaScript:
var m = $gameParty.members()[0];
var w = m?m.weapons()[0]:null;
w?w.id:0

And also would changing "weapons" to "items" and "armors" be the correct way to switch between the different types?

Thank you so much in advance!
SRD HUD Maker Pro

So I'm using SRD HUD Maker Pro, I'm trying to get Icons to display to show what is equipped in my custom menu. I have found a script that works perfect to get the currently equipped weapons ID. I have my Icons set up in order of the weapons, Items, Armors. So weapon 1 would be Icon 1 and Weapon 2 would be Icon 2 and so on, but Items and Armors I would either have to set a bunch of "blank" items before I get to the first item to keep the Icon array going correctly or just add 100 to this script, but I'm not sure where to add the 100?
It's a little hard to tell you, because you're not showing the full code where you reference your icon. But wherever it is, you'd just add the 100 in that index (e.g. icons[x+100]
Script is
JavaScript:
var m = $gameParty.members()[0];
var w = m?m.weapons()[0]:null;
w?w.id:0
This seems unnecessarily convoluted to me. I don't see how there could be a situation where you'd be playing the game to see your HUD, but the entire party is empty - so the code checking for the party members to exist seems pointless.
Similarly, there's not a reason to check for your w to exist twice - you could put all of this in one line of code with only one variable.
Code:
var w = $gameParty.members()[0].weapons()[0] ? $gameParty.members()[0].weapons()[0].id : 0;

Also, the last line is not a useful code statement, as far as I know...it's evaluating w but not assigning anything based on that information.
And also would changing "weapons" to "items" and "armors" be the correct way to switch between the different types?
It is for armors, but items work differently. If you look at the menus in your game, there is no concept of ownership for items - you don't have Harold's potion that's associated with him somehow, you just have the party's potions. So those are stored in $gameParty.items().
You can streamline ATT_Turan's line even further with the null-chaining and nullish-coalescing operators:

JavaScript:
const w = $gameParty.leader().weapons()[0]?.id ?? 0
Oho! I knew about the optional chaining, but I didn't know about the second one to convert the undefined to a 0. Cool beans 😀
It's a little hard to tell you, because you're not showing the full code where you reference your icon. But wherever it is, you'd just add the 100 in that index (e.g. icons[x+100]

This seems unnecessarily convoluted to me. I don't see how there could be a situation where you'd be playing the game to see your HUD, but the entire party is empty - so the code checking for the party members to exist seems pointless.
Similarly, there's not a reason to check for your w to exist twice - you could put all of this in one line of code with only one variable.
Code:
var w = $gameParty.members()[0].weapons()[0] ? $gameParty.members()[0].weapons()[0].id : 0;

Also, the last line is not a useful code statement, as far as I know...it's evaluating w but not assigning anything based on that information.

It is for armors, but items work differently. If you look at the menus in your game, there is no concept of ownership for items - you don't have Harold's potion that's associated with him somehow, you just have the party's potions. So those are stored in $gameParty.items().


Hey thanks for the reply!


SRd.png



So I couldn't show the Icon code because its part of the Plugin. So the first script just calls a number of the weapons ID, then I have the Icons in my IconSet in order of the weapons. The number is tied to a variable, and then the plugin changes the image based on what number it pulls.
My biggest issue would be that weapon1 is tied to icon1 in the IconSet using it the way I have it set up, but armors have another set of numbers starting at 1. so if I use an identical script for the armors I would have to have numbers 1-99 as blank armors because those numbers are used by weapons. which is why I was asking how to add to the number.

My next issue I'm running into is I want to show armors, hats, shields, and so on so forth. but the script I found only shows the very first thing equipped. how would I denote between each subtype of armors.


You can streamline ATT_Turan's line even further with the null-chaining and nullish-coalescing operators:

JavaScript:
const w = $gameParty.leader().weapons()[0]?.id ?? 0

Where would I add the +100 in this script?

This works to pull the very first item equipped. It works perfect for Weapons, but I still have the isssue with Armors described above. How do I tell the script which armor it should be looking at?
So the first script just calls a number of the weapons ID, then I have the Icons in my IconSet in order of the weapons. The number is tied to a variable, and then the plugin changes the image based on what number it pulls.
I appreciate the screenshot, but I don't understand from looking at it where any of your code goes. Does it have a pre-defined variable that you reference for the icon ID?
My biggest issue would be that weapon1 is tied to icon1 in the IconSet using it the way I have it set up, but armors have another set of numbers starting at 1. so if I use an identical script for the armors I would have to have numbers 1-99 as blank armors because those numbers are used by weapons. which is why I was asking how to add to the number.
I'm a bit confused by your confusion. At some point, you have to know whether the thing you're looking at is a weapon or armor - otherwise you wouldn't have any place to say "I'm typing .weapons() here and .armor() here." Wherever you're planning to use the ID for the armor...you add 100.
My next issue I'm running into is I want to show armors, hats, shields, and so on so forth. but the script I found only shows the very first thing equipped. how would I denote between each subtype of armors.
You change the number in the brackets. So you can look at actor.armor()[0], actor.armor()[1], etc. You can also use actor.equips()[X] to look at the actor's equipped item regardless of type, and this follows the order that you see in your Database, Types, Equipment Types.
Where would I add the +100 in this script?
You wouldn't, this is just a more efficiently-written version of the code you supplied in your first post. It is still only looking at the first equipped weapon.
I appreciate the screenshot, but I don't understand from looking at it where any of your code goes. Does it have a pre-defined variable that you reference for the icon ID?

I'm a bit confused by your confusion. At some point, you have to know whether the thing you're looking at is a weapon or armor - otherwise you wouldn't have any place to say "I'm typing .weapons() here and .armor() here." Wherever you're planning to use the ID for the armor...you add 100.

You change the number in the brackets. So you can look at actor.armor()[0], actor.armor()[1], etc. You can also use actor.equips()[X] to look at the actor's equipped item regardless of type, and this follows the order that you see in your Database, Types, Equipment Types.

You wouldn't, this is just a more efficiently-written version of the code you supplied in your first post. It is still only looking at the first equipped weapon.

Ok, Let me slow down and fully explain what I'm trying to do, instead of what I'm doing.

I'm building a custom menu with SRD HUD Maker Pro. Within this menu I want a picture of my character surrounded by Equipment slots. Weapon, Hat, Shield, Shirt, Gloves, Boots, Ring, Necklace Etc...

I have Icons that I want to show up in each slot that shows what is in the slot, and when you hover over the slot it'll show a Weapon Description. (I have the Hover option working don't need the help there.) So after some internet sleuthing I found that you could only call IconIndex when drawing a Window. I may have bad information in this sense. I had found the original code I posted online, and it does work nicely but only for the very first item equipped.

Ideally I would like to figure out how to just find out what IconIndex the equipped weapon and armors have. This would be the cleanest way to do what I'm envisioning. However if I cant call the IconIndex with this method, I figured the next best option would be to have a Variable inside RPGMZ call a script to find out the WeaponID of what is currently equipped. Then have the HUD maker, display an icon dependent on the WeaponID. So weapon1 would be icon1, weapon2 would be icon2, Armor1 would be icon 100 armor2 would be icon 101.... ETC...

I quickly realized though that Armor would only call the very first Armor piece equipped, and I had no idea on how to get it to call the second, third, fourth, etc... piece equipped. I am very new to JavaScript but I feel as if I learn quickly and I'm enjoying puzzling through things to get them to work. Its just this particular function I'm doing seems to be some advanced Javascript and I'm very lost on how to achieve this.

So in summary I would like to figure out either:

1. If Player has Hat equipped show Icon Index based on the Hat Id
If Player has Shirt equipped show Icon Index based on Shirt ID
etc... for each different Subtype of Armor.

2. If player has Hat equipped, get Armor ID of equipped item.
if Player has Shirt equipped, get Armor ID of equipped item.
etc... for each different Subtype or Armor.

I hope this clears up any confusion or misunderstanding! I'm truly grateful for your help thus far as well.
Ok, Let me slow down and fully explain what I'm trying to do, instead of what I'm doing.
Perfect!
Ideally I would like to figure out how to just find out what IconIndex the equipped weapon and armors have.
That's easily done. However, a quick caveat:
I figured the next best option would be to have a Variable inside RPGMZ
This is the first time you've mentioned that you're using MZ, your profile that shows up when you write posts says you use MV, so I've been giving you code with that presumption. I'll give you how to implement this, but I don't have MZ to see if any of the code for these parts is different. See if it works.
So in summary I would like to figure out either:

1. If Player has Hat equipped show Icon Index based on the Hat Id
If Player has Shirt equipped show Icon Index based on Shirt ID
etc... for each different Subtype of Armor.
So this is all much simpler than you thought when you were asking - obviously an item has to know what its icon is, otherwise how would the game ever display it? 😉 There's no need to add anything to anything, just reference the icon index member variable.
Then you're just going to use the array I told you about in my previous post: actor.equips(). Nothing very advanced, as I described, it contains every piece of equipment on the actor in the order you have it listed in your database, Types tab. I'm presuming from the way you've described things that your game only has one character in the party at a time. So:
Code:
$gameParty.leader().equips()[0]?.object().iconIndex ?? 0
will give you the icon index of the item they have equipped in the first slot on the list (default is weapon) - if nothing is equipped, it returns 0.
Code:
$gameParty.leader().equips()[1]?.object().iconIndex ?? 0
is the next slot in the list (default is head), and so forth. Simply modify for whatever your Equipment Types list looks like.
Perfect!

That's easily done. However, a quick caveat:

This is the first time you've mentioned that you're using MZ, your profile that shows up when you write posts says you use MV, so I've been giving you code with that presumption. I'll give you how to implement this, but I don't have MZ to see if any of the code for these parts is different. See if it works.

So this is all much simpler than you thought when you were asking - obviously an item has to know what its icon is, otherwise how would the game ever display it? 😉 There's no need to add anything to anything, just reference the icon index member variable.
Then you're just going to use the array I told you about in my previous post: actor.equips(). Nothing very advanced, as I described, it contains every piece of equipment on the actor in the order you have it listed in your database, Types tab. I'm presuming from the way you've described things that your game only has one character in the party at a time. So:
Code:
$gameParty.leader().equips()[0]?.object().iconIndex ?? 0
will give you the icon index of the item they have equipped in the first slot on the list (default is weapon) - if nothing is equipped, it returns 0.
Code:
$gameParty.leader().equips()[1]?.object().iconIndex ?? 0
is the next slot in the list (default is head), and so forth. Simply modify for whatever your Equipment Types list looks like.
Hey!

I was just coming to Edit my post but saw you replied. I figured it out!! But being the newbie with JavaScript I am it might not be correct so please look at it to see if anything looks weird.

Code:
$gameActors.actor(1).equips()[2]?.iconIndex

It was so much simpler than I was making it out to be! This part is referencing my "Hat" item. When I equip the hat the image shows up in the right spot and when I unequip the image goes away. I also had a text displaying the number so I knew it was pulling the correct index.

and my apologies for the mix up on platform. I originally started with MV for the switch. However it was to limited for what I was trying to do so I ended up buying MZ, cuz why not? lol.

I truly appreciate every bit of help you've given me!

Original thread: https://forums.rpgmakerweb.com/threads/need-help-with-altering-a-script.138297/