Author Topic: Removing specific effects  (Read 389 times)

Legacy_Grani

  • Hero Member
  • *****
  • Posts: 1040
  • Karma: +0/-0
Removing specific effects
« on: September 25, 2013, 09:53:18 pm »


               Is it possible to remove specific effects?
For example, consider an effect "eBonus":
-Increases AC by 2
-is extraordinary
-is permanent

I can apply effect "eBonus" to PC without a problem, but when I try to remove it with the function "RemoveEffect" in another script, it doesn't work - the script compiles properly, but nothing happens.

What is it? Is it impossible to remove just a specific effect and not all effects of type EffectACIncrease?
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Removing specific effects
« Reply #1 on: September 25, 2013, 10:10:41 pm »


               Yes, it's possible. You can't create a duplicate and remove in script, however; instead, you must scan the effects on the creature and remove based on a certain criteria. The most exacting way to do this in vanilla NWN (wtihout NWNX) is, when you create the effect to begin with, to AssignCommand its creation to a specific object with a unique tag. Then, you can check GetEffectCreator to see if that object is the creator, and strip with RemoveEffect if so. I'd post a specific example, but I can't access the toolset at the moment.

If you have NWNX, you can assign new effect spell ids and remove effects that match them - analagous to a unique Effect Creator.

Funky
               
               

               
            

Legacy_Grani

  • Hero Member
  • *****
  • Posts: 1040
  • Karma: +0/-0
Removing specific effects
« Reply #2 on: September 25, 2013, 10:16:00 pm »


               I see! I think I got it, though I'll write here if I encounter any related problems.

Thanks, Funky.
               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Removing specific effects
« Reply #3 on: September 25, 2013, 10:20:31 pm »


               There's examples of the vanilla way on the Lexicon.
               
               

               
            

Legacy_Grani

  • Hero Member
  • *****
  • Posts: 1040
  • Karma: +0/-0
Removing specific effects
« Reply #4 on: September 25, 2013, 10:39:31 pm »


               Looks like I didn't get it after all, haha...

What am I doing wrong? In one script I have:


effect eBonus = EffectACIncrease(GetLocalInt(oPC, "MountedBonus"));
                        eBonus = SupernaturalEffect(eBonus);
                        AssignCommand(GetModule(), ApplyEffectToObject(DURATION_TYPE_PERMANENT, eBonus, oPC));

This works perfectly and applies properly defined AC bonus to PC.
But then I have a script that is supposed to remove that:

void main()
{
  object oPC = GetPCSpeaker();
  effect eEffect;
  eEffect = GetFirstEffect(oPC);
  while (GetIsEffectValid(eEffect))
     {
      if (GetEffectCreator(eEffect)==GetModule()) RemoveEffect(oPC, eEffect);
      eEffect = GetNextEffect(oPC);
     }
}

But this one does not seem to work - it compiles, alright, but no change occurs - the PC is still subject to the said AC bonus.

What am I doing wrong?
               
               

               


                     Modifié par Grani, 25 septembre 2013 - 09:39 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Removing specific effects
« Reply #5 on: September 25, 2013, 11:12:38 pm »


               Are you sure the module is the effect creator?   I see that you have the module applying the effect.  But, I see no prof from the above code that the module is running the original script that is creating the effect.
               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Removing specific effects
« Reply #6 on: September 25, 2013, 11:35:06 pm »


               You're assigning application of the effect to the module, but not the actual creation. Therefore, OBJECT_SELF is still being tagged as the creator. To get around this:

// Create the effect in a function.
void ApplyACBonus(object oPC)
{
    effect eBonus = EffectACIncrease(GetLocalInt(oPC, "MountedBonus"));
    eBonus = SupernaturalEffect(eBonus);
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, eBonus, oPC);
}

void main()
{
    // Assign the effect creation to the module
    AssignCommand(GetModule(), ApplyACBonus(oPC));
}

               
               

               


                     Modifié par Squatting Monk, 25 septembre 2013 - 10:35 .
                     
                  


            

Legacy_Grani

  • Hero Member
  • *****
  • Posts: 1040
  • Karma: +0/-0
Removing specific effects
« Reply #7 on: September 25, 2013, 11:50:42 pm »


               I understand it now and it works just fine!

Now that I look at this, it's perfectly logical, yet I doubt I'd be able to figure it out.

Well, thanks a lot for help. '<img'>
               
               

               


                     Modifié par Grani, 25 septembre 2013 - 10:51 .
                     
                  


            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Removing specific effects
« Reply #8 on: September 26, 2013, 02:52:18 am »


               I would suggest using a uniquely tagged object rather than the module, and Getting it with GetObjectByTag, instead, just FYI. Some publicly-distributed systems tend to use the module as the effect creator, as it's guaranteed to be there, and you'll wind up stripping those effects too, should you happen to use those systems, or if anyone else happened to use the module as an effect creator for anything, which is pretty common.

Funky