// Tag-based script template. // This is intended to be a starting point for writing an item's tag-based script. // Copy this to a script whose name is the tag of the item in question. // Edit the event handlers (scroll down to find them) as desired. //#include "x0_i0_spells" #include "x2_inc_switches" #include "prc_inc_spells" // ----------------------------------------------------------------------------- // This first part is standard and generic. // There should be no need to edit it; just skip down to the next part. // ----------------------------------------------------------------------------- // The individual event handlers. void OnAcquire(object oEventItem, object oAcquiredBy, object oTakenFrom, int nStackSize); void OnActivate(object oEventItem, object oActTarget, location lActTarget, object oActivator); void OnEquip(object oEventItem, object oEquippedBy); void OnHit(object oEventItem, object oHitTarget, object oCaster); int OnSpellCast(object oEventItem, int nSpell, object oCaster); void OnUnacquire(object oEventItem, object oLostBy); void OnUnequip(object oEventItem, object oUnequippedBy); int GetIsAbleToHear(object oCreature); int GetIsAbleToHear(object oCreature) { effect eSearch = GetFirstEffect(oCreature); while(GetIsEffectValid(eSearch)) { switch(GetEffectType(eSearch)) { case EFFECT_TYPE_SILENCE: case EFFECT_TYPE_DEAF: return FALSE; } eSearch = GetNextEffect(oCreature); } return TRUE; } // The main function. void main() { int nEvent = GetUserDefinedItemEventNumber(); // Spells might continue to their spell scripts. All other events are // completely handled by this script. if ( nEvent != X2_ITEM_EVENT_SPELLCAST_AT ) SetExecutedScriptReturnValue(); // Determine which event triggered this script's execution. switch ( nEvent ) { // Item was acquired. case X2_ITEM_EVENT_ACQUIRE: OnAcquire(GetModuleItemAcquired(), GetModuleItemAcquiredBy(), GetModuleItemAcquiredFrom(), GetModuleItemAcquiredStackSize()); break; // Item was activated ("activate item" or "unique power"). case X2_ITEM_EVENT_ACTIVATE: OnActivate(GetItemActivated(), GetItemActivatedTarget(), GetItemActivatedTargetLocation(), GetItemActivator()); break; // Item was equipped by a PC. case X2_ITEM_EVENT_EQUIP: OnEquip(GetPCItemLastEquipped(), GetPCItemLastEquippedBy()); break; // Item is a weapon that just hit a target, or it is the armor of someone // who was just hit. case X2_ITEM_EVENT_ONHITCAST: OnHit(PRCGetSpellCastItem(), PRCGetSpellTargetObject(), OBJECT_SELF); break; // A PC (or certain NPCs) cast a spell at the item. case X2_ITEM_EVENT_SPELLCAST_AT: if ( OnSpellCast(PRCGetSpellTargetObject(), PRCGetSpellId(), OBJECT_SELF) ) SetExecutedScriptReturnValue(); break; // Item was unacquired. case X2_ITEM_EVENT_UNACQUIRE: OnUnacquire(GetModuleItemLost(), GetModuleItemLostBy()); break; // Item was unequipped by a PC. case X2_ITEM_EVENT_UNEQUIP: OnUnequip(GetPCItemLastUnequipped(), GetPCItemLastUnequippedBy()); break; } } // ----------------------------------------------------------------------------- // Event handlers // ----------------------------------------------------------------------------- // This second part is where you add your desired functionality. Each event // has its own function with relavant information passed as parameters. // ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- // oEventItem was acquired (by a PC or an NPC). // Run by the module. void OnAcquire(object oEventItem, object oAcquiredBy, object oTakenFrom, int nStackSize) { // Default: do nothing. } // ----------------------------------------------------------------------------- // oEventItem was activated ("activate item" or "unique power"). // Run by the module. void OnActivate(object oEventItem, object oActTarget, location lActTarget, object oActivator) { // Default: do nothing. } // ----------------------------------------------------------------------------- // oEventItem was equipped by a PC. // Run by the module. void OnEquip(object oEventItem, object oEquippedBy) { // Default: do nothing. } // ----------------------------------------------------------------------------- // oEventItem is a weapon that just hit a target, or it is the armor of someone who // was just hit by someone else's weapon. // Run by the caster. void OnHit(object oEventItem, object oHitTarget, object oCaster) { int nLevel = GetHitDice(oCaster); if (nLevel > 35) nLevel = 35; //Declare major variables effect eVis = EffectVisualEffect(VFX_IMP_STUN); effect eHowl = EffectStunned(); effect eDur = EffectVisualEffect(VFX_DUR_CESSATE_NEGATIVE); effect eDur2 = EffectVisualEffect(VFX_DUR_MIND_AFFECTING_DISABLED); effect eImpact = EffectVisualEffect(VFX_FNF_HOWL_MIND); effect eLink = EffectLinkEffects(eDur2, eDur); int nHD = GetHitDice(OBJECT_SELF); int nDC = 15 + (nHD/4); int nDuration = 2; float fDelay; ApplyEffectToObject(DURATION_TYPE_INSTANT, eImpact, OBJECT_SELF); //Get first target in spell area object oTarget = GetFirstObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_COLOSSAL, GetLocation(OBJECT_SELF)); effect scaledEffect; int scaledDuration; while(GetIsObjectValid(oTarget)) { if(oTarget != OBJECT_SELF && spellsIsTarget(oTarget, SPELL_TARGET_STANDARDHOSTILE, OBJECT_SELF)) { fDelay = GetDistanceToObject(oTarget)/10; //Fire cast spell at event for the specified target SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, SPELLABILITY_HOWL_STUN)); //Make a saving throw check if(GetIsAbleToHear(oTarget) && !PRCMySavingThrow(SAVING_THROW_WILL, oTarget, nLevel, SAVING_THROW_TYPE_MIND_SPELLS, OBJECT_SELF, fDelay)) { scaledDuration = PRCGetScaledDuration(nDuration , oTarget); scaledEffect = PRCGetScaledEffect(eHowl, oTarget); scaledEffect = EffectLinkEffects(eLink, scaledEffect); //Apply the VFX impact and effects DelayCommand(fDelay, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oTarget)); DelayCommand(fDelay, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, scaledEffect, oTarget, RoundsToSeconds(scaledDuration))); } } //Get next target in spell area oTarget = GetNextObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_COLOSSAL, GetLocation(OBJECT_SELF)); } } // ----------------------------------------------------------------------------- // Someone cast a spell at oEventItem. // This usually only fires if a PC cast the spell, but it also fires for // DM-possessed NPCs and NPCs in an area with the "X2_L_WILD_MAGIC" local integer set. // // Return TRUE to prevent the spell script from firing. // Return FALSE to proceed normally. // // This fires after the UMD check, module spellhook, item creation, and // sequencer handlers decide they do not want to handle/interrupt this spell. // This fires before the check to see if this is a spell that normally can // target items (and before the spell script itself runs). // // Run by the caster. int OnSpellCast(object oEventItem, int nSpell, object oCaster) { // Default: just proceed normally. return FALSE; } // ----------------------------------------------------------------------------- // oEventItem was unacquired/lost (by a PC or NPC). // Run by the module. void OnUnacquire(object oEventItem, object oLostBy) { // Default: do nothing. } // ----------------------------------------------------------------------------- // oEventItem was unequipped by a PC. // Run by the module. void OnUnequip(object oEventItem, object oUnequippedBy) { // Default: do nothing. }