Let's try to do it as follows then.
Create a script and rename it, say, on_equip:
/*
adds the characters intelligence modifier to their armor class while they also have a shield in their left hand
*/
const int FEAT_DEFEND_FLANK = 2858;
/* Boolean function to check if the creature passed in paramater wields a shield
and has got the feat "defend flank".
Returns TRUE is that is the case, FALSE otherwise */
int IsShieldEquipped(object oPC)
{
// get the type of item wielded in the left hand
object oItem = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oPC);
int nType = GetBaseItemType(oItem);
// check if (holding a shield) and (having the right feat)
if (((nType == BASE_ITEM_LARGESHIELD) || (nType == BASE_ITEM_SMALLSHIELD)
|| (nType == BASE_ITEM_TOWERSHIELD)) && (GetHasFeat(FEAT_DEFEND_FLANK, oPC)))
{
return TRUE;
}
else
{
return FALSE;
}
}
/*
Apply / remove the bonus for having a shield equipped and the FEAT_DEFEND_FLANK
*/
void main()
{
object oPC = GetFirstPC(FALSE);
if (IsShieldEquipped(oPC))
{
int nAbility = GetAbilityModifier(ABILITY_INTELLIGENCE,oPC);
effect eEffect = SupernaturalEffect(EffectACIncrease(nAbility, AC_DEFLECTION_BONUS, AC_VS_DAMAGE_TYPE_ALL,FALSE));
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEffect, oPC, HoursToSeconds(12));
SendMessageToPC(GetFirstPC(), "Defend flank activated!");
}
else
{
SendMessageToPC(GetFirstPC(), "Defend flank deactivated!");
}
}
I'd probably put it in the OnEquip and OnUnequip slots of the module rather than the OnHeartbeat.
First reason: it will only fire when an item is equipped / unequipped, so the changes will be immediate.
Second reason: although it will not make any difference, it will not fire unnecessarily and delay other heartbeat scripts.
If you go that route, you might want to add a call to the above script from the existing OnEquip / OnUnequip scripts (in my toolset, they're "x2_mod_equ" and "x2_mod_unequ").





Volver arriba







