As probably most of you are aware, there is a bug with damage immunities from items in NWN2, when they stack beyond 100%, the immunity becomes a vulnerability.
I wanted to fix this, by overriding with a spell effect in case the damage immunity from gear surpasses 100%, with a script attached to a dedicated feat (and then give this feat to everyone).
In addition, it's necessary to modify the scripts that handle OnEquip and OnUnequip events (default "x2_mod_def_equ" and the "x2_mod_def_unequ" ) to make them run this script.
EDIT: The previous script used recursive calls that could put a lot of heartbeat strain on the computer/server.
const int ITEMIMMUNITY_FIX = -2395;
void RunImmunityFix(object oChar)
{
int nElement;
int nElement2;
int nEquipment;
int nTOT;
int nITEM;
object oEquipment;
itemproperty iMAIN;
int nSUB;
int nType;
int nTABLE;
effect eImmunity = GetFirstEffect(oChar);
while(GetIsEffectValid(eImmunity))
{
if (GetEffectSpellId(eImmunity) == ITEMIMMUNITY_FIX)
{
RemoveEffect(oChar, eImmunity);
}
eImmunity = GetNextEffect(oChar);
}
while (nElement < 14)
{
if ((nElement!=3)&&(nElement!=4))
{
nTOT = 0;
nEquipment = 0;
while (nEquipment < 11)
{
nITEM = 0;
oEquipment = GetItemInSlot(nEquipment, oChar);
if (GetItemHasItemProperty(oEquipment, ITEM_PROPERTY_IMMUNITY_DAMAGE_TYPE) == TRUE )
{
iMAIN = GetFirstItemProperty(oEquipment);
nType = GetItemPropertyType(iMAIN);
nSUB = GetItemPropertySubType(iMAIN);
while (GetIsItemPropertyValid(iMAIN))
{
if ((nType == ITEM_PROPERTY_IMMUNITY_DAMAGE_TYPE)&&(nSUB == nElement))
{
nTABLE = GetItemPropertyCostTableValue(iMAIN);
nITEM = nITEM + StringToInt(Get2DAString("iprp_immuncost", "Value", nTABLE));
}
else if ((nType == ITEM_PROPERTY_DAMAGE_VULNERABILITY)&&(nSUB == nElement))
{
nTABLE = GetItemPropertyCostTableValue(iMAIN);
nITEM = nITEM - StringToInt(Get2DAString("iprp_damvulcost", "Value", nTABLE));
}
iMAIN = GetNextItemProperty(oEquipment);
nType = GetItemPropertyType(iMAIN);
nSUB = GetItemPropertySubType(iMAIN);
}
}
nTOT = nTOT + nITEM;
nEquipment = nEquipment + 1;
}
if (nElement == 0)
{
nElement2 = DAMAGE_TYPE_BLUDGEONING;
}
else if (nElement == 1)
{
nElement2 = DAMAGE_TYPE_PIERCING;
}
else if (nElement == 2)
{
nElement2 = DAMAGE_TYPE_SLASHING;
}
else if (nElement == 5)
{
nElement2 = DAMAGE_TYPE_MAGICAL;
}
else if (nElement == 6)
{
nElement2 = DAMAGE_TYPE_ACID;
}
else if (nElement == 7)
{
nElement2 = DAMAGE_TYPE_COLD;
}
else if (nElement == 8)
{
nElement2 = DAMAGE_TYPE_DIVINE;
}
else if (nElement == 9)
{
nElement2 = DAMAGE_TYPE_ELECTRICAL;
}
else if (nElement == 10)
{
nElement2 = DAMAGE_TYPE_FIRE;
}
else if (nElement == 11)
{
nElement2 = DAMAGE_TYPE_NEGATIVE;
}
else if (nElement == 12)
{
nElement2 = DAMAGE_TYPE_POSITIVE;
}
else if (nElement == 13)
{
nElement2 = DAMAGE_TYPE_SONIC;
}
if (nTOT > 99)
{
eImmunity = EffectDamageResistance(nElement2, 9999);
eImmunity = ExtraordinaryEffect(eImmunity);
eImmunity = SetEffectSpellId(eImmunity, ITEMIMMUNITY_FIX);
DelayCommand(0.1, ApplyEffectToObject(DURATION_TYPE_PERMANENT, eImmunity, oChar));
}
}
nElement = nElement + 1;
}
}
void main()
{
object oPC = OBJECT_SELF;
DelayCommand(0.1, RunImmunityFix(oPC));
}





Retour en haut







