Sometimes created objects (undead) don't appear and attack after chest's "OnDeath" is ran.
DarinM1967
Member Posts: 2
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!
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)); } }
0
Comments
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, will ensure that the creature that attacks is the one you just created.
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.
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.