Neverwinter Nights > NwN Building
Removing one specific visual effect from an object
(1/1)
Ryu Hayabusa:
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: ---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);
}
}
}
}
--- End code ---
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.
420:
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: ---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);
}
}
--- End code ---
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.
Ryu Hayabusa:
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]
--- End quote ---
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!
420:
--- Quote ---So I guess when I compare effects, NWN is comparing the pointer address to the effects and not the actual effects themselves?
--- End quote ---
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]
--- End quote ---
I'll check it out right now!
-420
Anheg:
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.
Navigation
[0] Message Index
Go to full version