Jump to content

Home

Help With Looping


Star Admiral

Recommended Posts

      // Get the first spell effect on the player.
     effect eBuff = GetFirstEffect( OBJECT_SELF );

     // Loop through all spell effects on the player.
     while( GetIsEffectValid( eBuff ) ) {
        // Remove any other form currently active on the player.   *** Needs memory token. ***
        switch( GetEffectSpellId( eBuff ) ) {
           case 132: { RemoveEffect( OBJECT_SELF, eBuff ); break; }
           case 133: { break; }
           case 134: { RemoveEffect( OBJECT_SELF, eBuff ); break; }
           case 135: { RemoveEffect( OBJECT_SELF, eBuff ); break; }
        }
        // Get the next spell effect on the player.
        eBuff = GetNextEffect( OBJECT_SELF );
     }

 

So, I've got this switch statement inside a while loop. Basically, I want this spell, when casted, to check if the player already has this spell active, and if so, remove it. In addition, it will also check for the existence of three other spells and remove them if needed. The script compiles without issue, so it's not a syntax error, but unfortunately, it does not remove the effect, so I have a stacking effect. Any clues?

 

Thanks.

 

- Star Admiral

 

      // Set the effect and icon for Determination Proficiency.
     effect eForm = EffectAttackIncrease( 2, 0 );
     eForm = EffectLinkEffects( eForm, EffectBlasterDeflectionDecrease( 2 ) );
     eForm = EffectLinkEffects( eForm, EffectACIncrease( 2, 0 ) );
//      eForm = SetEffectIcon( eForm, 64 );   // *** Needs memory token. ***

  object oSelf = GetSpellTargetObject();  

  // Deactivate the form if it is active.   *** Needs memory token. ***
  if( GetHasSpellEffect( 132, oSelf ) ) {
//      Sp_RemoveSpellEffectsGeneral( 132, oSelf );
     RemoveEffect( oSelf, eForm );
     SendMessageToPC( GetFirstPC(), "This is removal." );
  }

 

Okay, I've simplified to code to just remove its own effect, yet it still doesn't work. The message to PC fires each time, so the program is going through this if statement, but for some reason, the effect isn't removed. Is it because I've linked some effects together?

 

   else {
     // Signal the spell casting event.
     SignalEvent( oSelf, EventSpellCastAt( oSelf, GetSpellId(), FALSE ) );
     // Apply the form to the player.
     ApplyEffectToObject( DURATION_TYPE_INSTANT, eForm, oSelf );
     SendMessageToPC( GetFirstPC(), "This is casting." );
  }

 

 

Or is it because I'm not signaling the event properly? :confused:

 

- Star Admiral

 

Use the "edit" function in future please, don't double post. -- j7

 

EDIT: Sorry about that, J7!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...