I’m trying to write a script that is to destroy a door, after a character casts a spell on it. I wanted to use the spell Dispel magic and I started with something like this:
void main()
{
object oDoor = OBJECT_SELF;
object oStarget = GetSpellTargetObject();
int iSpell = GetSpellId();
if (oStarget == oDoor)
{
if (iSpell = SPELL_DISPEL_MAGIC)
{
DestroyObject(oDoor, 0.5);
}
}
}
I placed this script upon the “On Spell Cast At Script” slot on the door. It doesn’t work at all however. I think it might have to do with the spell not being directly aimed at the door, but it dispels the magic in an area where the door is.
You were on the right path. You need to get the spell that was cast. You were trying to get the spell id, but not putting in the spell that had been cast. Try GetLastSpell() instead… Also, this script will only fire if the Door is effected by the cast spell, so the oSTarget should be OBJECT_SELF - the door is calling this script.
//
if (GetLastSpell() == SPELL_DISPEL_MAGIC)
{
DestroyObject(OBJECT_SELF, 0.5);
}
//
I was able to throw it in toolset and try it myself. However, I see what you mean by how you can’t target the door directly, so GetSpellTargetObject() won’t return the door. Maybe the door also needs a magic effect on it to be effected by the Dispel Magic? If I get a chance, I’ll play with this.
Still, it doesn’t seem to work because you can’t cast that spell on the door directly…So, how do you get around that? Do you have to have an enchanted door, and how do you do that in that case? Maybe with a magical item in its inventory or something perhaps?
idk, you could try customizing the spellscript and add OBJECT_TYPE_DOOR …
–
something similar comes up in one of the SoZ mini-dungeons. A door needs Darkness cast on it to open. So the developers start a dialog in the door’s OnFailToOpen, and a node checks if PcSpeaker has some form of Darkness available and if so, and player chooses that node, Darkness is decremented by a dialog-script (and the door opens)
Yeah, I came to the same conclusion… The OnSpellCastAt script fires for a given object only when you call explicitly EventSpellCastAt() for this object inside a spellscript. Since the door objects are skipped in the loop, this event never happens.
Thank you Mannast, Aqvilinus and kevL_s for helping me out!
It worked like you said, kevL_s. Now, I have another problem. The whole thing was to work like this. You have to cast Dispel Magic and Sound Burst on the door for it to be destroyed.
Somehow, in game the game wont recognize the Sound Burst spell. I can’t understand why. Here’s how my script looks at the moment (with debug messages, and that’s how I noticed it):
void main()
{
SendMessageToPC(GetFirstPC(FALSE), "Running the script...");
object oDoor = GetObjectByTag("door_out");
if (GetLastSpell() == SPELL_DISPEL_MAGIC)
{
SendMessageToPC(GetFirstPC(FALSE), "The dispel spell was found");
SetLocalInt(oDoor,"dispel",TRUE);
}
if (GetLastSpell() == SPELL_SOUND_BURST)
{
SendMessageToPC(GetFirstPC(FALSE), "The sound spell was found");
SetLocalInt(oDoor,"sound",TRUE);
}
if (GetLocalInt(oDoor,"dispel") && GetLocalInt(oDoor,"sound"))
{
SendMessageToPC(GetFirstPC(FALSE), "Destroying the door now");
DestroyObject(oDoor, 0.5);
}
}
The game recognizes the Dispel Magic spell, no problem there, but not the Sound Burst spell.