Skip to content

OnSpellCastAt() script help -

ZephiriusZephirius Member Posts: 411
edited March 2022 in Builders - Scripting
Just trying to get a creature to spawn in if you cast dispel magic on placeable (OBJECT_SELF)
I'm having a hell of a time of it...
...then again, no one has ever accused me of being a true code monkey! Ha! Lol!

code so far...
#include "nw_i0_2q4luskan"
#include "nw_i0_generic"
#include "x2_i0_spells"
void main()
{

    object oPC = GetLastSpellCaster();
    int nSpell = GetLastSpell();

    if (!GetIsPC(oPC) && (nSpell == SPELL_DISPEL_MAGIC))
    {
         SetPlotFlag(OBJECT_SELF, FALSE);

         location lLoc = GetLocation(GetWaypointByTag("COC_LOC"));

         effect eFX = EffectVisualEffect(VFX_IMP_DEATH);

         ApplyEffectToObject(DURATION_TYPE_INSTANT, eFX, OBJECT_SELF);
         DelayCommand(0.5, DestroyObject(OBJECT_SELF, 1.0));

         DelayCommand(1.0, CreateObjectVoid(OBJECT_TYPE_CREATURE, "cockatrice001", lLoc));
         DelayCommand(1.3, AssignCommand(GetObjectByTag("COCKCATRICE_01"), ActionAttack(oPC)));
    }
}


Yikes! I suck...

Yeah, nothing happens after casting Dispel magic. I do receive an error message saying that FUNNY_PARROT, (that's the placeable) is divided by zero.

Thanks guys... you know who you are. :blush:
Post edited by Zephirius on

Comments

  • ProlericProleric Member Posts: 1,282
    As the code stands, nothing will happen if the caster is a PC - !GetIsPC(oPC) should probably read GetIsPC(oPC).

    I don't see a zero divide in this code, so maybe that's some other script?

    Once you're over that hurdle, remember that dead / destroyed objects can't do stuff. There are exceptions, of course, but the safest way is to AssignCommand(GetModule(), FUNCTION()); where FUNCTION kills / destroys the object then executes or queues all the other things you want to happen.

    That way, the module controls everything. The module never dies, and is rarely disobeyed by other objects.
  • ZephiriusZephirius Member Posts: 411
    Removing ! from oPC worked. Everything spawns correctly now. ;)
Sign In or Register to comment.