Getting icon names in NWScript

The CopyItemAndModify() function, among other things, allows one to create a copy of a simple item with a different inventory icon. It uses an index number to determine which item icon the new item will have. Those numbers correspond (as best I can tell) to the order the icons appear in the Toolset for a given baseitem type. For instance, if I use CopyItemAndModify on a ring and use 1 as the index, the new ring will look like a gold ring, the first inventory icon for rings.

Is there a way for a script to determine how many icons there are for a particular base item? It will change depending on HAKs, etc. For instance, I think CEP takes the ring index up to 238. But, how would I know that without opening up the HAK files and counting all of the icons whose names start with iit_ring_?

(BTW, the CopyItemAndModify() function doesn’t fail to produce an object if it is given an index that is out of range. It seems to use a default icon. So, using that function in a loop until it fails to generate a valid object doesn’t work.)

Is this information in a 2DA somewhere? Is there a nice way of determining it? Preferably within NWScript at runtime?

Sadly, that information isn’t in a 2da. For item appearances, the toolset builds its drop-down list from all the models it finds, so no 2da is necessary. There can be gaps, so even if 238 is valid, there’s no guarantee that 237 exists.

I had the same problem with choosing random heads by script. The only solution I found was to make an explicit list (as a string, pseudo-array or custom 2DA). Obviously, that only works for a specific set of haks. In that case, it was worth the extra effort, because not all heads look right for every situation.

Shoot. I was worried that that would be the case. I guess I will have to hand-tune the scripts and know that they may be invalid the next time CEP or BeamDog adds or removes an icon.

Is it at least true that the baseitem.2da DefaultIcon column provides the prefix (e.g. the value of that string without the trailing digits) for the icon images for that base item type? Or is that defined somewhere else?