I have a little problem with a NPC which I want to leave the party, go to the nearest door and finally disappear
It runs from a conversation, lost_child reffers to the NPC. The NPC do gets fired and do move to the nearest door, but never gets destroyed.
FireHenchman (oPC, lost_child);
AssignCommand (lost_child, ActionMoveToObject (GetNearestObject(OBJECT_TYPE_DOOR, lost_child), FALSE, 0.5));
DestroyObject (lost_child, 5.0);
Any ideas?
Make sure they’re destroyable (SetIsDestroyable) else DestroyObject fails. This can be a property of the creature blueprint.
That’s the main thing.
Depending which henchman system you’re using, it may be important for the henchman not to be destroyable until fired, so putting SetIsDestroyable in this script is safer than tweaking the blueprint.
Other potential improvements:
- ActionForceMoveToObject can be better, to work around collisions or pathfinding errors
- EffectCutsceneGhost is belt-and-braces (but can look odd)
- ActionDoCommand on the DestroyObject will synchronise arriving and vanishing
- ActionDoCommand(SetCommandable) at the end of the script prevents interruption by PCs, heartbeats or whatever
It really depends on how mission-critical it is that the NPC disappears.
Also ClearAllActions()
to clear the queue. It never hurts, but lack of it backfires often.
It is also not a bad idea to issue an additional “failsafe” DestroyObject()
(with a timer) to ensure that the target is gone in case of unexpected events.
The good thing is that DestroyObject()
checks whether the target is destroyable when it’s internal clock runs out (BTW, unaffected by SetTime()
), not when it is called, so it’s best to just call it before doing anything else with the creature.
1 Like
Thanks to all…
I think I’m gonna stay with this option:
FireHenchman (oPC, lost_child);
AssignCommand (lost_child, ActionMoveAwayFromObject (oPC, FALSE, 10.0));
AssignCommand (lost_child, SetIsDestroyable(TRUE, TRUE, FALSE) );
AssignCommand (lost_child, DestroyObject (OBJECT_SELF, 5.0) );
Looks fine, as long as it works and you’re happy there’s some “safer” ways (such as ExecuteScript so AssignCommand isn’t needed and my notes below) but frankly this will work 99.9% of the time anyway.
The only little things I might add to make it a little safer is remove all the effects (eg: Paralysis may mean AssignCommand fails, and if it doesn’t it’ll look weird anyway them standing there then magically going) and use SetCommandable(TRUE) on them so they can accept commands like ActionMoveAwayFromObject just in case something else has messed with it.