Aller au contenu

Photo

Script help to alter when custom feats take effect


  • Veuillez vous connecter pour répondre
1 réponse à ce sujet

#1
sundancejack

sundancejack
  • Members
  • 1 messages
Hello,

I'm in the process of writing scripts for a few custom feats but have run up against a wall with getting them to fire correctly.  Several of the feats look at what items a character has equipped and then makes changes to the character's statistics based on the result (for example, an armored caster feat similar to the bard/warlock's that checks the ACF on the equipped armor, then adjusts the characters ACF value if the armor is light or medium or heavy depending on the feat).  They work as intended (correct calcuations and adjustments), except I cannot for the life of me figure out how to get them to fire when the character equips/unequips a new item - instead, they only make the adjustments on load/rest/level-up.  Any advice on how I can adjust them to implement correctly?

Thank you so much for your time!

PS - here is the code for one of the feats as is for reference.  It is set up as a persistent feat in feat.2da according to advice given on this board:

//jws_magus_acl
//Script for Magus Class Ability "Armored Caster, light"
//Designed to ignore arcane spell failure when wearing light armor
//Created by John Staples  14-June-2013
//Based on script "nx_s2_immunityfire"

#include "nwn2_inc_spells"
#include "x2_inc_spellhook"

void main()
{
    if (!X2PreSpellCastCode())
    {   // If code within the PreSpellCastHook (i.e. UMD) reports FALSE, do not run this spell
        return;
    }
    
    //Declare major variables
    object oTarget = GetSpellTargetObject();
    object oArmor;
    int nACF;
    int nACF_Debug;
    string sDebug1;
    string sDebug2;
    effect eReduceACF;
    
    // Does not stack with itself
    if (!GetHasSpellEffect(GetSpellId(), oTarget))
    {
           
    //FloatingTextStringOnCreature("Starting Script", oTarget);
    oArmor = GetItemInSlot(INVENTORY_SLOT_CHEST, oTarget);
    //FloatingTextStringOnCreature("Item is " + GetTag(oArmor) + ".", oTarget);
    
    // check to see if armor is light, and do nothing if not
    if(GetArmorRank(oArmor)!= ARMOR_RANK_LIGHT)
        {    
            //FloatingTextStringOnCreature("Not Light Armor, scripted ended", oTarget);
            return;
        }
    else // armor is light, continue
        nACF = GetArcaneSpellFailure(oTarget);
        //sDebug1 = IntToString(nACF);
        //FloatingTextStringOnCreature("ACF = " + sDebug1 + "%.", oTarget);
    
        eReduceACF = EffectArcaneSpellFailure(-nACF);
        eReduceACF = ExtraordinaryEffect(eReduceACF);
        
         //Fire cast spell at event for the specified target
            SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, GetSpellId(), FALSE));
        
        ApplyEffectToObject(DURATION_TYPE_PERMANENT, eReduceACF, oTarget);
        //nACF_Debug = GetArcaneSpellFailure(oTarget);
        //sDebug2 = IntToString(nACF_Debug);
        //FloatingTextStringOnCreature("ACF now = " + sDebug2 + "%.", oTarget);
    return;
    }
}


#2
MasterChanger

MasterChanger
  • Members
  • 686 messages
Firing the script has very little to do with the script itself, but where it's called from. Being that the scripts happen on rest and level-up, that tells me you are using a Persistent feat. Anything that's dependent on equipment should be called instead from the module's OnEquip & OnUnequip. You'd do all your checks there. That way, whenever any piece of equipment is swapped in or out you'd know about it, and if the change isn't relevant to your purposes you can ignore it.