Skip to content

Delay Spawn by Chapter

CallirgosCallirgos Member Posts: 105
Hi Quick Question

Is there a method I could use to delay the spawn of an NPC or Companion to require a specific chapter?

For Examples,
If I'd like Gurke to appear only after Chapter 4.
If I'd like Kivan to only apear after Chapter 3.

Comments

  • CallirgosCallirgos Member Posts: 105
    hhmmm.. If I remember Officer Vai is created after chapter 3. I'll see if I can figure that out.
  • sarevok57sarevok57 Member Posts: 5,975
    im going to go with yes

    you would no doubt have to go into the area script where they would be spawned in and insert some sort of command of;

    check chapter X
    spawn creature at location

    sort of deal
  • jmerryjmerry Member Posts: 3,822
    For specifically using the chapter, that's tracked by the global variable "Chapter". Condition either spawning or activating the NPC on that, and you're good.
    sarevok57
  • The_Baffled_KingThe_Baffled_King Member Posts: 147
    edited May 2021
    Yes, and no. It's important to understand that NPCs appear via different mechanisms, although at the point when you encounter them they are always .CRE files.

    I'll start with joinable NPCs, which I'll refer to using your term "companions". With the exception of the BG:EE companions (ie not Dorn and the other 3), the locations of companions in BG1 are stored in the .GAM file. I haven't looked into modifying the .GAM file, so I won't say anything further about it, although it can certainly be done. Realistically, you are likely to be looking at removing the companion from the .GAM file, and having it appear via a different mechanism.

    Next you have those groups of generic enemy NPCs that are randomly generated. These are created by something called a "Spawn Point". Information on spawn points is stored in .ARE files. These don't really seem to be what you're asking about, so I'll say nothing more regarding them.

    Then you have NPCs that are created via actions in a dialog, in the script of a creature, or in the script of an area. I'll address the latter mechanism, as the others don't seem relevant. Not all areas have scripts. Those that do have scripts named after the code for the area (the one you see if you use the cheat console). For example, the script for the upper floor of Feldepost's Inn is AR3352.BCS. If an NPC is created via an area script, it is easy to change the conditions by which it appears, and in the below spoiler I'll show you how.

    Finally, you have NPCs which are saved in the .ARE file (area file) and loaded with the area when it is visited for the first time during a game. These are known as "Actors". Most non-generic NPCs you encounter, as well as all of the generic friendly NPCs (commoners), are Actors. It's more difficult to modify an Actor in the way that you want to do it. A sort of hackish way to do so would be to change the appearance schedule of the Actor so that it never appears, and then create the NPC using the area's BCS script. There are also other methods to edit Actors, but it's easier to add Actors than to remove them.

    How to make a .CRE appear during a specific chapter:
    This is the code block in AR3352.BCS that creates Tranzig in Chapter 3. Look at the third line. Change the number from 3 to whatever you want. It really is that simple. Most blocks in an area's .BCS that create an NPC are meant to run only once, for obvious reasons. The usual method for accomplishing this is to have the IF condition for creating the NPC check for a variable, and have the Response block that creates the creature set that variable. That is what is going on below with "TranzigSpawn" changing from 0 to 1. The variables usually follow that naming convention (ie the name of the creature followed by the word "Spawn"), although they could realistically be anything you want.

    IF
    	Global("TranzigSpawn","GLOBAL",0)
    	Global("Chapter","GLOBAL",3)
    THEN
    	RESPONSE #100
    		SetGlobal("TranzigSpawn","GLOBAL",1)
    		CreateCreature("TRANZI",[200.580],S)  // Tranzig
    END
    

    You can edit BCS scripts using NearInfinity, or in Notepad before pasting into NearInfinity. It's important to use Notepad rather than a word processing program (like Word).

    IF YOU ARE GOING TO DO THIS, MAKE SURE YOU HAVE A BACKUP COPY OF YOUR GAME SAVED ELSEWHERE.

    It seems to me that you're asking about tweaking something for your own use rather than making a mod for other people, so that's how I've pitched my answer.
  • The_Baffled_KingThe_Baffled_King Member Posts: 147
    Having scanned this subforum, I've seen that you're dabbling in making combat scripts, so I think I should say a bit more. The reason I said that its harder to remove Actors than to add or to modify them is that Weidu is shipped with pre-written functions to add Actors (fj_are_structure) or edit them (ALTER_AREA_ACTOR), but I don't believe it has a comparable pre-written function to remove Actors. You might want to bear that in mind if you're looking to install with Weidu at some point.

    However, as you only want to delay the appearance of an Actor, then have it appear in the area that it normally appears in, the script actions to deactivate and activate creatures could be useful for you. I'm going to use Gurke as an example. This script, added to AR3304.BCS, deactivates Gurke and then activates him once you visit the Jovial Juggler in Chapters 5-7:
    IF
    	Global("GurkeHide","GLOBAL",0)
    	Exists("Gurke")  // Gurke
    THEN
    	RESPONSE #100
    		SetGlobal("GurkeHide","GLOBAL",1)
    		Deactivate("Gurke")  // Gurke
    END
    
    IF
    	GlobalGT("Chapter","GLOBAL",4)
    	Global("GurkeHide","GLOBAL",1)
    	Exists("Gurke")  // Gurke
    THEN
    	RESPONSE #100
    		SetGlobal("GurkeHide","GLOBAL",2)
    		Activate("Gurke")  // Gurke
    END
    

    You could use one variable to hide Gurke, and another to get him to reappear, if that's what you prefer.

    A similar but better thing that you can do is put a script on the Actor itself. Actors have a "specifics script", which creatures lack, and BG:EE that script slot is often unused, although the script could be added to the .CRE itself. This is better than editing an area script for a number of reasons, such as: (a) you can duplicate the same script for multiple creatures; and (b) you can have the script remove itself after it's done what you need. So here is an example for you:
    IF
    	Global("Hide","LOCALS",0)
    THEN
    	RESPONSE #100
    		SetGlobal("Hide","LOCALS",1)
    		Deactivate(Myself)
    END
    
    IF
    	GlobalGT("Chapter","GLOBAL",4)
    THEN
    	RESPONSE #100
    		Activate(Myself)
    		ChangeAIScript("",SPECIFICS)
    END
    

    Unfortunately it does take about a second for the creature to hide itself. Often that won't matter, but it's noticeable with creatures that are visible as soon as you enter an area - you see them pop in or out of existence. If it bothers you, the thing to do might be to edit the Actor so it begins the game invisible, and have the script that activates the creature remove the invisible state. But it remains problematic if the Actor begins to do something (especially initiate dialog) before being hidden.
  • CallirgosCallirgos Member Posts: 105
    This is very useful. Thank you!
    The_Baffled_King
Sign In or Register to comment.