Preplaced Widget Indexer

Referencing preplaced objects is a pain, especially in Lua, where you cannot convert triggers to code, and you have to keep references to preplaced objects in GUI triggers. In addition, looking up the correct variable names is quite cumbersome.

PreplacedWidgetIndexer is a simple system that enumerates all units, destructables, and/or items at the beginning of the game and compiles them into a list that can be easily accessed with the GetPreplacedWidget function. This function accepts widgetType ids, fourCC codes, widget names, as well as hero proper names.

Simply copy this script into your map and you can do:
Lua:
Tyrande = GetPreplacedWidget("Etyr")
--or
Tyrande = GetPreplacedWidget(1165261170)
--or
Tyrande = GetPreplacedWidget("Priestess of the Moon")
--or
Tyrande = GetPreplacedWidget("Tyrande")
ATTENTION: Because default widget names and proper names may get localized and be different for different players, using names as the parameter is only safe to use with your custom units. If you're unsure, use fourCC codes instead.

This should cover 90% of all use-cases. But if there are multiple objects with the same type id on the map, you need to specify an index. This index can be generated in three ways:
  • By sorting widgets based on their position on the map, with the lowest index being assigned to those in the bottom-left corner of the map. This is quick to do, but bears the danger that indices get messed up as you modify your map.
  • By setting the percentage health of the preplaced widget to the desired index in the World Editor. This allows you to have full control over the indices that are assigned. The widgets are healed to full right after the system has indexed them. Does not work for items.
  • By creating a rect with the World Editor around a widget and giving it a name containing "forceIndexN", where N is the desired index.

If you're using A.L.I.C.E, you can enable the debug mode to view the generated indices by clicking on objects. Otherwise, you'll have to print them out somehow. They're stored in the PreplacedIndex table.
Contents

PreplacedWidgetIndexer (Map)

PreplacedWindgetIndexer (Binary)

Reviews
Wrda
Preplaced objects is one of the challenges one has when one writes code, because the world editor needs a GUI trigger with a reference to the unit somehow. This system solves that issue conveniently. Approved
The way Blizzard did it in WarChasers was they drew a region over each important unit. I would advise that over manipulating game-relevant data like max health. Your system could use that technique to enumerate a unit based on its region.

Btw I absolutely love the pic you made for this!
 
Last edited:
I can add the regions as an option. The health thing is just another option. If someone wants to preplace units with missing health, they shouldn't use it. I could make it so that a region disables the health filter on units in those regions, so you can use the health thing for all other units.

I also did some more tests just now, and it looks like the order of units in the unordered list is always the same as the gg_ variable indices, so gg_unit_nogr_0000 will be [1], gg_unit_nogr_0001 will be [2] etc. For items and destructables, this doesn't hold true, I guess because you can't iterate over them with FirstOfGroup.
 
Top