So, I'm making some scripts for set items (based from Mad Dog's Fargo) and one of the sets will change the appearance of the player when he equips all necessary items. The thing is: The players is getting it's appearance changed when all set items are equipped but it's appearance is not going back to normal when any set item is unequiped. Here's the script:
#include "x2_inc_switches"
#include "x2_inc_itemprop"
void main()
{
// MDF - If this item event is OnEquipItem...do this stuff
if (GetUserDefinedItemEventNumber() == X2_ITEM_EVENT_EQUIP)
{
// Define Vars based on EQUIP action
object oPC = GetPCItemLastEquippedBy();
int nPCLvl = GetHitDice(oPC);
object oTriggerItem = GetPCItemLastEquipped();
string sTriggerItemTag = GetTag(oTriggerItem);
// Check to see if all items in this set are equipped
// This set uses Amulet and BOTH ring slots
if (
(GetTag(GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC)) == sTriggerItemTag) &&
(GetTag(GetItemInSlot(INVENTORY_SLOT_HEAD, oPC)) == sTriggerItemTag) &&
(GetTag(GetItemInSlot(INVENTORY_SLOT_CHEST, oPC)) == sTriggerItemTag) &&
(GetTag(GetItemInSlot(INVENTORY_SLOT_BELT, oPC)) == sTriggerItemTag) &&
(GetTag(GetItemInSlot(INVENTORY_SLOT_ARMS, oPC)) == sTriggerItemTag)
)
{
SendMessageToPC(oPC, "All items in this set equipped!");
// Apply set item bonuses to PC as Supernatural Effects (cannot dispell and not removed by rest)
// Assigning effect command to item we can track applied effects by owner = the item = tag matching check during removal
SetCreatureAppearanceType(oPC, 465);
AssignCommand( oTriggerItem, ApplyEffectToObject( DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_IMPROVE_ABILITY_SCORE), oPC ) );
// Send short summary text to player explaining what just happened to them
SendMessageToPC(oPC, "Transforms into Lich.");
}
else
{
SendMessageToPC(oPC, "Set item equipped...set still incomplete.");
}
}
// MDF - If this item event is OnUnEquipItem...do this stuff
else if (GetUserDefinedItemEventNumber() == X2_ITEM_EVENT_UNEQUIP)
{
// Define Vars based on UN-EQUIP action
object oPC = GetPCItemLastUnequippedBy();
object oTriggerItem = GetPCItemLastUnequipped();
string sTriggerItemTag = GetTag(oTriggerItem);
effect eEffect = GetFirstEffect(oPC);
string sEffectCreatorTag = GetTag(GetEffectCreator(eEffect));
while(GetIsEffectValid(eEffect))
{
// Check to see if the tag of the effect owner matches the set item just removed
// Only remove effects that were applied by a set item with matching tag, hence of this same set
if ( sEffectCreatorTag == sTriggerItemTag )
{
RemoveEffect(oPC, eEffect);
}
eEffect = GetNextEffect(oPC);
sEffectCreatorTag = GetTag(GetEffectCreator(eEffect));
}
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_PULSE_NEGATIVE), oPC);
// Send short summary text to player explaining what just happened to them
SendMessageToPC(oPC, "Set item unequipped, bonus lost.");
}
}