Jump to content

Home

Conditional Spawning


Silveredge9

Recommended Posts

I believe I've come close, but not close enough... -_-

 

After I've finished talking to an NPC, another NPC needs to be spawned upon entry to a different module.

 

At the moment I have a script that activates after the conversation is over.

void main()
{
   SetGlobalNumber("Exchangemeeting", 1);
}

 

And for the spawning script, I need to know how to arrange the spawning script below with a script that looks up and checks if the above a variable is set to 1 (As set by finishing the convo), and if it is initiate the spawn script, and if it isn't doesn't initiate the spawn script.

 

void main()
{
        if(!GetIsObjectValid(GetObjectByTag("drix")))
	CreateObject(OBJECT_TYPE_CREATURE, "drix", Location(Vector(151.32,90.75,0.27), 160.0));
ExecuteScript("old_k_ptat17_enter", GetModule());
}

 

Thanks for any help in advance.

Link to comment
Share on other sites

And for the spawning script, I need to know how to arrange the spawning script below with a script that looks up and checks if the above a variable is set to 1 (As set by finishing the convo), and if it is initiate the spawn script, and if it isn't doesn't initiate the spawn script.

 

Unless I misunderstand what you want to do, couldn't you just add the check if the spawn should be performed to the script that does the spawning? Like:

 

void main() {
   if ((GetGlobalNumber("Exchangemeeting") == 1) && !GetIsObjectValid(GetObjectByTag("drix"))) {
       CreateObject(OBJECT_TYPE_CREATURE, "drix", Location(Vector(151.32,90.75,0.27), 160.0));
   }
   ExecuteScript("old_k_ptat17_enter", OBJECT_SELF);
}

 

Don't forget to add the Exchangemeeting variable to the globalcat.2da file as well, or it won't work. The script will still compile but the value will never be stored.

 

Unless you check for that variable somewhere else too I'd suggest incrementing it as well when the character has been spawned, unless the character is supposed to remain in that area for the rest of the game. Otherwise a new one would be spawned every time the player enters if it doesn't already exist.

 

It's also safer to use the OBJECT_SELF constant instead of GetModule() in the ExecuteScript() call, unless the script is the OnPlayerEnter script for the Module, rather than the OnEnter script for the area. Otherwise things may get messed up if the old OnEnter script you execute relies on OBJECT_SELF to be the area.

Link to comment
Share on other sites

Thanks, that's pretty much what I needed.

 

There is one problem with the script though that I didn't think of before. The name of the old OnEnter script, old_k_ptat17_enter, is too long. A ResRef can be at most 16 characters, that name is 18, so the Original script would not be run.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...