SetCreatureBodyPart function

I think something is weird with the SetCreatureBodyPart function.

I was having problems with Bloodsong’s “body tailor” ( https://neverwintervault.org/project/nwn1/script/body-tailor-body-modifications ) and after some testing I think I’'ve found a very weird bug with the SetCreatureBodyPart function.

I have the following script on a lever (single player, no haks, module with only one area, only the script and the lever…)

void main()
{
    object oPC = GetLastUsedBy();

    SetCreatureBodyPart(CREATURE_PART_RIGHT_HAND, CREATURE_MODEL_TYPE_SKIN, oPC);

    SetColor(oPC, COLOR_CHANNEL_SKIN, 36);
}

well, with this script, the skin color of the PC is not changed… I’m only able to see the change on the skin color if I comment the line with the SetCreatureBodyPart function like this.

void main()
{
    object oPC = GetLastUsedBy();

    //SetCreatureBodyPart(CREATURE_PART_RIGHT_HAND, CREATURE_MODEL_TYPE_SKIN, oPC);

    SetColor(oPC, COLOR_CHANNEL_SKIN, 36);
}

Any idea of what is happening here? bug? :S

I have no idea what’s causing that. :thinking: Try adding a slight delay to SetColor:

DelayCommand(0.1, SetColor(oPC, COLOR_CHANNEL_SKIN, 36));

1 Like

it works with the DelayCommand :open_mouth:

1 Like

The engine seems to be quite fragile when changing the appearance of part-based creatures. Here, for example, is part of the code I use to generate citizens of random appearance. Took a lot of fine tuning to get this working correctly.

      // Appearance bugs seem to be greatly reduced if each change is applied as a separate command
      // Head is most buggy, so we do that first, hoping the remaining commands will reset any bad appearance
      AssignCommand(oNPC, ActionDoCommand(SetCreatureBodyPart(CREATURE_PART_HEAD, nHead, oNPC)));
      AssignCommand(oNPC, ActionDoCommand(SetColor(oNPC, COLOR_CHANNEL_SKIN,     nSkin)));
      AssignCommand(oNPC, ActionDoCommand(SetColor(oNPC, COLOR_CHANNEL_HAIR,     nHair)));
      AssignCommand(oNPC, ActionDoCommand(SetColor(oNPC, COLOR_CHANNEL_TATTOO_1, nSkin)));
      AssignCommand(oNPC, ActionDoCommand(SetColor(oNPC, COLOR_CHANNEL_TATTOO_2, nSkin)));

(Purists will see at once that this could be done as one AssignCommand, executing a function with all the ActionDoCommand lines in it, but frankly this code is so fragile that if it ain’t bust, don’t fix it.

2 Likes

Thank you Proleric. I’ll test your code.

In fact, what I’m trying to solve is a very weird bug a player reported to me: when applying the changes done using the body tailor, if you are wearing an armor, the armor is PERMANENTLY modified (hands and neck in my case) I know, I know… the SetCreatureBodyPart and SetColor functions have nothing to do with items.

But there is no “CopyItemAndModify” function in the script…