Aller au contenu

Photo

Despawn NPC?


  • Veuillez vous connecter pour répondre
14 réponses à ce sujet

#1
Xeneize

Xeneize
  • Members
  • 133 messages

As the title says, I am trying to learn how to make a NPC despawn. I am not interested in destroying it, but from a conversation, when the player is ported away, I need that NPC to despawn otherwise multiple NPCs will end up spawning due to a different event which gets the PC to a place and spawns in the NPC that talks to him.

 

Is there any way I can make a NPC despawn?

 

Thanks in advance again guys :)



#2
AGhost_7

AGhost_7
  • Members
  • 62 messages

You could hide the NPC using SetScriptHidden then move it around.



#3
Tchos

Tchos
  • Members
  • 5 063 messages

You can create a room or other area where the PC can't go, and jump the NPC to that room until you need it again, with or without script-hiding it.



#4
Xeneize

Xeneize
  • Members
  • 133 messages

I can't just create an area for the purpose of keeping a NPC, unless there really isn't any way to get rid of it other than destroying it? (Which for some reason I can't seem to succeed at either)



#5
Tchos

Tchos
  • Members
  • 5 063 messages

There are ways.  As AGhost_7 mentioned, SetScriptHidden.  And I didn't suggest creating an entire area for the NPC.  Any spot or room in an existing area where the PC can't see or go would work.  I have several such places in my module.



#6
Dann-J

Dann-J
  • Members
  • 3 161 messages

I often create a single-tile room somewhere in an unused corner of a winding interior area (cave tunnels, mines, crypts, etc). As long as there's no direct connection to any of the accessable areas, it will never show up on the area map or minimap. Not unless you script the entire area to be visible via ExploreAreaForPlayer().

 

Isolated rooms like that are the natural habitat of the faction pig.



#7
PJ156

PJ156
  • Members
  • 2 985 messages

Creating an area for npc's that are not in game is my standard method. Especially for uncle FB's npc control where script hidden is available but could be a little flaky.

 

I even put some furniture in there for them in one module.

 

PJ



#8
Loki_999

Loki_999
  • Members
  • 430 messages
// MAP 3/27/2009
// Get a creature from limbo by 0-based position .  Check the results of this function
// with GetIsObjectValid; do not use a comparison to OBJECT_INVALID.
// Note that if an invalid creature is returned in any position, that
// does not mean that there are no more creatures, only that the creature in the position
// provided is not valid.
// To remove a creature from limbo, use ActionJumpToLocation on the returned object.
// Note that this will not change the number of creatures in limbo until after
// script execution completed.
// Finally, note that at this time creatures cannot be recalled from Limbo via scripting
object GetCreatureInLimbo(int nTh = 0);
// MAP 3/27/2009
// returns the number of creatures in limbo. Not all creatures are
// guaranteed to be valid objects.
int GetLimboCreatureCount();
// MAP 6/1/2009
// Recall a creature from Limbo. Creature must be in limbo,
// and must be a creature.
void RecallCreatureFromLimboToLocation(object oCreature, location loc);
void SendCreatureToLimbo(object oCreature);

;)



#9
Claudius33

Claudius33
  • Members
  • 258 messages

Use ActionForceExit  in a script. You need to include ginc_actions. The NPC is directed to a waypoint then is despawned, example :

 

#include "ginc_actions"

 

object oNPC = GetObjectByTag("MyNPC");

AssignCommand(oNPC, ActionForceExit("WP_npc_exit", TRUE) ); // if the second parameter is set true, the NPC runs otw he walks.

 

Alternatively, you can use ga_force_exit in a conversation. Be sure that the NPC is no more involved in the conversation. As a rule of thumb call ga_force_exit from the very last line of the conversation. It works well,  even for companions (who can be retrieved later on).
 



#10
Tchos

Tchos
  • Members
  • 5 063 messages

Xeneize said that he didn't want to destroy the NPC, and that's what the ForceExit commands do to non-roster creatures.  I like the general structure of the commands, though, and I rewrote copies of them to jump my NPCs to the holding area instead of destroying them.



#11
Claudius33

Claudius33
  • Members
  • 258 messages

Xeneize also said he intended to respawn the NPC depending on further events.

 

Anyway both ways despawn / respawn or hidden location work.



#12
Tchos

Tchos
  • Members
  • 5 063 messages

If you stored any local variables on a non-roster NPC, or changed the inventory through script or conversation, or applied any permanent effects to the NPC, etc., then that information would be lost when it is destroyed with ForceExit and would not exist on the newly spawned copy, because it is a copy, and not a respawn as it would be if it were a roster NPC.  The purpose of the hidden location is to preserve that information.



#13
Claudius33

Claudius33
  • Members
  • 258 messages

Sure. However hidden location only works for a single module unless the NPC always stays in the same module. For a campaign multi instances or despawn/respawn or a dummy companion never entering the party  belonging to a 'neutral' faction might be more suitable. So it ultimately depends on Xeneize needs and preferences.



#14
Tchos

Tchos
  • Members
  • 5 063 messages

Agreed, moving NPCs with their stored information across modules requires special considerations.

 

Also, Xeneize, another difference between the methods (for the sake of choosing a method for the situation) is that moving to a hidden location will work even if there is no blueprint for the NPC (i.e. it was placed and customised directly in the world, and not spawned from a blueprint), whereas destroying/spawning a new copy needs a blueprint.  (In most cases, though, I advocate spawning from a blueprint through an On Client Enter script, not placing NPCs directly.)



#15
Loki_999

Loki_999
  • Members
  • 430 messages

Guys, the limbo functions deal with all these issues with no need to mess around with setting script hidden or creating special areas.