Hitherto, creating random dynamic NPC appearances (for wandering citizens etc) has been buggy, especially if variable heads and clothing are required.
Even with workarounds, missing or misaligned body parts couldn’t easily be eliminated entirely.
Now, with EE, an entirely different approach is possible, which seems to be much more robust, albeit very slightly slower to spawn (tested for a random town population of 20).
The trick is to start with a basic character template, load it into a Json, then tweak all the fields including head and clothing before spawning the NPC.
// sTemplate is the resref of the creature template to be edited
// nHead, nHair, nSkin, sTalk and nGender are randomly-determined values
// sDress is the clothing resref chosen at random
// PORTRAIT_BLANK = 515 removes the need to select a portrait matching the head
// oWaypoint is a waypoint object at which the NPC is to spawn
json jTemplate = TemplateToJson(sTemplate, RESTYPE_UTC);
jTemplate = GffReplaceByte (jTemplate, "Appearance_Head", nHead);
jTemplate = GffReplaceByte (jTemplate, "Color_Hair", nHair);
jTemplate = GffReplaceByte (jTemplate, "Color_Skin", nSkin);
jTemplate = GffReplaceByte (jTemplate, "Color_Tattoo1", nSkin);
jTemplate = GffReplaceByte (jTemplate, "Color_Tattoo2", nSkin);
jTemplate = GffReplaceResRef(jTemplate, "Conversation", sTalk);
jTemplate = GffReplaceByte (jTemplate, "Gender", nGender);
jTemplate = GffReplaceResRef(jTemplate, "Equip_ItemList/value/0/EquippedRes", sDress);
jTemplate = GffReplaceWord (jTemplate, "PortraitId", PORTRAIT_BLANK);
JsonToObject(jTemplate, GetLocation(oWaypoint));
This simple example assumes that the original creature template has one (and only one) item equipped. Note the syntax “value/0” when refering to a GFF array element.
It’s just one illustration of how we can now edit templates in game, changing any fields, not just the ones that can be modified by explicit NWScript functions.