Author Topic: Removing one specific visual effect from an object  (Read 6094 times)

Offline Ryu Hayabusa

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
    • http://
Removing one specific visual effect from an object
« on: January 09, 2007, 04:22:06 PM »
I have this code in the module "on_activate".  It turns the user of the item into "plot" on first use, and removes "plot" on the second use.

Code: [Select]
void main()
{
    object oUsed = GetItemActivated();

    // * Script for activation of item
    if (GetTag(oUsed) == "item")
    {
        effect eVis = SupernaturalEffect(EffectVisualEffect(VFX_DUR_AURA_BLUE));
        effect eEffect;
        object oSelf = GetItemActivator();
        object oTarget = GetItemActivatedTarget();

        if (oSelf == oTarget)
        {
            if (GetPlotFlag(oSelf))
            // * Unplot user and remove specific visual effect
            {
                SetPlotFlag(oSelf, FALSE);

                eEffect = GetFirstEffect(oSelf);
                while (GetIsEffectValid(eEffect))
                {
                    if (eEffect == eVis){
                        RemoveEffect(oSelf, eEffect);
                    }
                    eEffect = GetNextEffect(oSelf);
                }
            }
            else
            // * Turn user into plot and apply visual effect
            {
                SetPlotFlag(oSelf, TRUE);
                ApplyEffectToObject(DURATION_TYPE_PERMANENT, eVis, oSelf);
            }
        }
    }
}

The script has no problem applying the visual effect, but it fails to find the visual effect when trying to remove it.  Does anyone know why?

Sorry for spamming the forum.  I'm a pure noob at scripting.

Offline 420

  • Hero Member
  • *****
  • Posts: 4087
    • View Profile
    • Email
Removing one specific visual effect from an object
« Reply #1 on: January 10, 2007, 02:29:20 AM »
To remove an effect you must cycle through all the effects on an object and check to see if it is the one you want to remove. The easiest way that I have found is to check for the effect's creator.

Then you can use something like this to remove a specific effect:
Code: [Select]
void main()
{
object oTarget = GetItemActivatedTarget();
object oCreator = GetObjectByTag("PlotMaker");

effect ePlotVFX = GetFirstEffect(oTarget);
while(GetIsEffectValid(ePlotVFX))
    {
    if(GetEffectCreator(ePlotVFX) == oCreator)
        {
        RemoveEffect(oTarget, ePlotVFX);
        }
    ePlotVFX = GetNextEffect(oTarget);
    }
}
Now, the tricky part is determinig what object is creating the effect. Depending on which object executes the tagged based scripts, it could be the module, the item being activaed or the item's activator.

I haven't tested the default Bioware tagged based script system and I use my own custom system that makes the activator execute the script.

Alternately you can make a DM-only area where you can place various invisible objects that apply and remove specific effects. In the above example the invisible object's tag is PlotMaker. You can make an invisible object execute scripts on objects through the tag-based script system by using ExecuteScript and passing it a local variable for the target.

-420

EDIT: Just to clarify a bit, what your code is doing is declaring a brand new effect at the beginning then checking for that newly declared effect on the target. I know it sounds weird but then the people that invented computer programming were fucked in the head.
« Last Edit: January 10, 2007, 02:33:32 AM by 420 »

Offline Ryu Hayabusa

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
    • http://
Removing one specific visual effect from an object
« Reply #2 on: January 13, 2007, 11:17:11 AM »
Very clever, 420!  Thank you so much.

Quote
EDIT: Just to clarify a bit, what your code is doing is declaring a brand new effect at the beginning then checking for that newly declared effect on the target. I know it sounds weird but then the people that invented computer programming were fucked in the head.
[snapback]33451[/snapback]

So I guess when I compare effects, NWN is comparing the pointer address to the effects and not the actual effects themselves?

Anyway, after a few days of learning how to script, I have a small 9 AC dueling module up (on most weeknights and weekends) based on the GS rules:

Module Name: "--Ryu's 9AC Legit Dueling Released!--"
Tab: "Action"

I'm surprised that a number of former GS duelers have logged on.  I guess many people still miss the place.

Come visit when you guys have time!

Offline 420

  • Hero Member
  • *****
  • Posts: 4087
    • View Profile
    • Email
Removing one specific visual effect from an object
« Reply #3 on: January 13, 2007, 05:42:19 PM »
Quote
So I guess when I compare effects, NWN is comparing the pointer address to the effects and not the actual effects themselves?
That's correct.

Quote
Anyway, after a few days of learning how to script, I have a small 9 AC dueling module up (on most weeknights and weekends) based on the GS rules:

Module Name: "--Ryu's 9AC Legit Dueling Released!--"
Tab: "Action"

I'm surprised that a number of former GS duelers have logged on.  I guess many people still miss the place.

Come visit when you guys have time!
[snapback]33463[/snapback]
I'll check it out right now!

-420

Offline Anheg

  • Hero Member
  • *****
  • Posts: 2417
    • View Profile
    • Email
Removing one specific visual effect from an object
« Reply #4 on: January 14, 2007, 01:15:15 AM »
Im starting to wish I hadn't uninstalled NWN but I refuse to try NWN 2 again until I hear something drastic changed...Something along the lines of Talon hosting a server again.
My PS3 Game Library:
Call of Duty 4, Guitar Hero 3, Mirrors Edge, Motor Storm, Resistance 2, Rock Band 2, Soul Calibur 4, Valkyria Chronicles