Skip to content

Sometimes created objects (undead) don't appear and attack after chest's "OnDeath" is ran.

Neverwinter Nights EE: Version: 81.8193.16 (Steam)
Windows 10 Home: 10.0.19042 Build 19042

Hey everybody!

Having an issue and hoping it's just me. What I'm trying to create is an OnDeath script for a placeable, say for instance a chest. When it is destroyed by bashing a number of skeletons and zombies appear and attack the destroyer of the chest. Some playthroughs the undead appear and attack, sometimes they don't appear, and I want to know why. Here is my script. If anyone could take a look at it, maybe test it on multiple play throughs in normal game and test builds then let me know what I am doing wrong, so that I can learn from it, I would be very grateful. Thank you in advance!
/* Put this into some placable "on_death" script section,
   make sure the placable is hostle to whomever attacked it, and can be broken
   When it gets destroyed it will summon a bunch of undead (zombies & skeletons)
   to surround the attacker and attack them.
*/



void main()
{
    // How many undead we want to surround the player
    int nUndead = 2;
    // Is used to track the number of undead created
    int nCount2 = 0;

    // Creature that last attacked me
    object oCreature = GetLastAttacker(OBJECT_SELF);

    // Get the location of where the last attacker
    location locAttacker = GetLocation(oCreature);

    // Time to summon the undead to attack the last attacker
    for(nCount2 = 0; nCount2 < nUndead; nCount2++)
    {
        // Summoning a skeleton
        CreateObject(OBJECT_TYPE_CREATURE, "nw_skeleton", locAttacker, FALSE, "CT_SKELETON");

        // Have them attack the last attacker
        AssignCommand(GetObjectByTag("CT_SKELETON"), ActionAttack(oCreature));

        // Summoning a zombie
        CreateObject(OBJECT_TYPE_CREATURE, "nw_zombie01", locAttacker, FALSE, "CT_ZOMBIE");

        // Have them attack the last attacker
        AssignCommand(GetObjectByTag("CT_ZOMBIE"), ActionAttack(oCreature));
    }
}

Comments

  • ProlericProleric Member Posts: 1,281
    I find it more reliable to instruct the module (not the placeable) to issue those commands. For example,
    ExecuteScript("myscript", GetModule());
    

    or put the code in a function, then AssignCommand to the module.

    In general, dying objects can't request future events. It may not be a timing issue here, though. For some reason, creatures are sometimes reluctant to take orders from placeables. At any rate, orders issued by the module always seem to work.

    For good order,
    object oUndead = CreateObject(...
    AssignCommand(oUndead...
    
    will ensure that the creature that attacks is the one you just created.
  • DarinM1967DarinM1967 Member Posts: 2
    Proleric, thank you for explaining this type of issue and what may cause it, and also for the work around. I was able to create a script that the placeable was able to call, the module to run, when it was destroyed. The script creates the skeletons and zombies every time, but I had to use the location of the placeable because it wouldn't work with the nearest creature of the placeable. They also wouldn't attack the nearest creature using the command, but since the undead faction is hostile they detected the player, who was the destroyer and attacked them. I was able to change the undead's facing in the right direction, which was for some reason the opposite of direction the "blue arrow" of the placeable pointed. Anyway thanks again Proleric for helping me understand how-to call scripts from the module to work around this issue. :)
  • FreshLemonBunFreshLemonBun Member Posts: 909
    If I'm not mistaken createobject and assigncommand occur after the script completes. By which time the situation may have changed.

    This generally applies to references too when it involves things that don't occur immediately. AssignCommands should also have some quirks when you're effectively queuing actions, while functions should be immediate when actually assigned.
  • meaglynmeaglyn Member Posts: 149
    No, createobject happens in line.

    The result of the assigncommand may or may not but the assignment of the command also happens in line in the script. Depends on what the command assigned is. Sometimes the assigned command will happen right then as well. But other times, such as adding an action to an object's action queue, it won't happen until that object gets to it in its queue.

    DestroyObject is the one that doesn't happen until the script ends.
  • FreshLemonBunFreshLemonBun Member Posts: 909
    Right, I think assign might happen right away when it's not assigned to another object. When it's assigned to another object it will happen after the script finishes, and if it's an action it will queue the action. Tested to reconfirm this, wrapped messages for an assigned function are sent after messages in the actual script after the assign function. CreateObject's issue was the OnSpawn event can sometimes complicate things.
Sign In or Register to comment.