I have a script that is supposed to enable human PCs of either gender to equip/unequip a custom item that uses the PQ neck models pfh0_neck102.mdl & pmh0_neck102.mdl
I had hoped that the tagbased script given below would do the trick, but while the 102 model appears perfectly on the item being equipped, it refuses to go away and be replaced by the PC’s original neck model when the item is unequipped.
If anyone can suggest why this is happening, I will be very grateful indeed.
//////////////////////////////////////////////////////////////////////////
// githtorc.nss
//
// When a PC equips the "Githyanki Torc" item into the Amulet slot,
// his/her current neck model is replaced by either pmh0_neck102.mdl or
// pfh0_neck102.mdl, depending on the gender of the PC.
//
// Conversely, when the item is unequipped, the new neck model is replaced
// by the original neck model.
//
// N.B. The item blueprint MUST have the Tag: githtorc
//
///////////////////////////////////////////////////////////////////////////
#include "x2_inc_switches"
void main()
{
int nEvent = GetUserDefinedItemEventNumber();
if (nEvent == X2_ITEM_EVENT_EQUIP)
{
object oPC = GetPCItemLastEquippedBy();
int iGender = GetGender(oPC);
SetLocalInt(oPC, "OriginalNeck", GetCreatureBodyPart(CREATURE_PART_NECK, oPC));
if (iGender == GENDER_MALE)
SetCreatureBodyPart(CREATURE_PART_NECK, 102, oPC);
if (iGender == GENDER_FEMALE)
SetCreatureBodyPart(CREATURE_PART_NECK, 102, oPC);
}
if (nEvent == X2_ITEM_EVENT_UNEQUIP)
{
object oPC = GetPCItemLastUnequippedBy();
SetCreatureBodyPart(CREATURE_PART_NECK, GetLocalInt(oPC, "OriginalNeck"));
}
}
I think this is one (or two) of the five bugs of SetCreatureBodyPart(). I guess “use latest EE” is not an option (it was fixed in 8193.36 early this year). I guess you can try is changing the entire PC appearance to a non-part-based model for 0.1s and then change it back?
Based on your suggestion, I tried out the script given below - was it what you had in mind?
#include "x2_inc_switches"
void main()
{
int nEvent = GetUserDefinedItemEventNumber();
if (nEvent == X2_ITEM_EVENT_EQUIP)
{
object oPC = GetPCItemLastEquippedBy();
int iGender = GetGender(oPC);
SetLocalInt(oPC, "originalneck", GetCreatureBodyPart(CREATURE_PART_NECK, oPC));
if (iGender == GENDER_MALE)
SetCreatureBodyPart(CREATURE_PART_NECK, 102, oPC);
if (iGender == GENDER_FEMALE)
SetCreatureBodyPart(CREATURE_PART_NECK, 102, oPC);
}
if (nEvent == X2_ITEM_EVENT_UNEQUIP)
{
object oPC = GetPCItemLastUnequippedBy();
int iGender = GetGender(oPC);
if (iGender == GENDER_MALE)
{
SetCreatureAppearanceType(oPC, APPEARANCE_TYPE_HUMAN_NPC_MALE_03);
DelayCommand(0.1f, SetCreatureAppearanceType(oPC, APPEARANCE_TYPE_HUMAN));
SetCreatureBodyPart(CREATURE_PART_NECK, GetLocalInt(oPC, "originalneck"));
}
if (iGender == GENDER_FEMALE)
{
SetCreatureAppearanceType(oPC, APPEARANCE_TYPE_HUMAN_NPC_FEMALE_03);
DelayCommand(0.1f, SetCreatureAppearanceType(oPC, APPEARANCE_TYPE_HUMAN));
SetCreatureBodyPart(CREATURE_PART_NECK, GetLocalInt(oPC, "originalneck"));
}
}
}
Sadly, I got the same result - the item equips perfectly, but still remains on the PC’s neck after it is unequipped.
I only tried this approach because the original method I used (parts of the Community VFX Project) didn’t play nicely with Vaei’s brilliant extra custom animations, which are an absolute must-have in my campaign base modules.
However, if you can think of another way I can get the item to work properly, I’d sure like to hear about it !!!
Don’t know if that fixes the problem but SetCreatureBodyPart() should be called before SetCreatureAppearanceType() (you can’t change body parts for non part-based models).
You are, of course, right Kamiryn, which just goes to show how much I know about scripting!
In the end however, I solved the issue by getting rid of everything except the SetCreatureBodyPart lines and having the OnUnequip part set the neck model to 001.
I’ve tested it with my main PC races/sexes and a variety of armour & clothing and it works fine!!
Case closed, and many thanks again to you and Clippy for taking the time to help.