Jump to content


Photo

Spawning joinable BG2 NPCs in a seamless fashion


  • Please log in to reply
No replies to this topic

#1 CamDawg

CamDawg

    ALL GLORY TO THE HYPNOTOAD

  • Modder
  • 1505 posts

Posted 20 May 2004 - 08:12 AM

I'm a big fan of seamless integration of mods into the game, to the point where it's difficult to tell modded content from original. One thing that's bothered me is that I have yet to see a seemless integration of joinable NPC spawning in BG2. The original characters will always join at a level appropriate to the PC by using four CRE files and some some info in the baldur.sav file. Once they join, they stay at the same level for the rest of the game.

For mod NPCs, to avoid messing with baldur.sav I've observed two approaches. The first involves creating a single CRE file, and then adding XP appropriate to match the PC's. The drawback to this approach is that you can have an NPC join and then have to do level-ups, which says "mod!" The second approach is to create multiple CRE files and then spawn the NPC using the CRE file closest in XP to the PC. The drawback to this approach is that if the PC leaves and returns later to pick up the NPC, the NPC could be several levels behind the PC.

After talking and brainstorming with Grim, he got me thinking about a better way to spawn joinable NPCs. The goal is to have the NPC spawn and join in a similar fashion to Bioware NPCs--their initial joining will be at a similar level to the PC's and then stay the same for the rest of the game if they're kicked out of the party. I haven't seen this approach on any of the NPC mods yet, so apologies if this is already known and/or used. ;)

So here's the code I'm using to spawn Delainy at the Mithrest Inn. C!DELA10 to C!DELA15 are creature files for Delainy at different levels and her death variable is C!Delai.

IF
   !Global("C!DelainySpawn","AR0704",1)
   Global("C!DelJoinedOnce","GLOBAL",0)
   XPLT(Player1,280001)
THEN
   RESPONSE #100
      ActionOverride("C!Delai",DestroySelf())
      CreateCreature("C!DELA10",[387.809],6) // Delainy
      SetGlobal("C!DelainySpawn","AR0704",1)
END

IF
   !Global("C!DelainySpawn","AR0704",2)
   Global("C!DelJoinedOnce","GLOBAL",0)
   XPGT(Player1,280000)
   XPLT(Player1,600001)
THEN
   RESPONSE #100
      ActionOverride("C!Delai",DestroySelf())
      CreateCreature("C!DELA11",[387.809],6) // Delainy
      SetGlobal("C!DelainySpawn","AR0704",2)
END

IF
   !Global("C!DelainySpawn","AR0704",3)
   Global("C!DelJoinedOnce","GLOBAL",0)
   XPGT(Player1,600000)
   XPLT(Player1,1000001)
THEN
   RESPONSE #100
      ActionOverride("C!Delai",DestroySelf())
      CreateCreature("C!DELA13",[387.809],6) // Delainy
      SetGlobal("C!DelainySpawn","AR0704",3)
END

IF
   !Global("C!DelainySpawn","AR0704",4)
   Global("C!DelJoinedOnce","GLOBAL",0)
   XPGT(Player1,1000000)
THEN
   RESPONSE #100
      ActionOverride("C!Delai",DestroySelf())
      CreateCreature("C!DELA15",[387.809],6) // Delainy
      SetGlobal("C!DelainySpawn","AR0704",4)
END

Upon the party's entrance to the Mithrest, Delainy is spawned at a level on par with the PC. Should the experience of the PC change to a higher range, then Delainy will be destroyed and recreated at the appropriate level. All this is dependent on Delainy never having joined. Once Delainy joins, the global variable C!DelJoinedOnce is bumped to 1 to prevent Delainy from continuously respawning.

This solution is still not without drawbacks. While unlikely, if the PC were to gain XP and exceed one of the breakpoints while in the presence of Delainy, they could see her disappear and reappear. From a scripting and dialogue standpoint, this approach makes LOCALS variables and the NumTimesTalkedTo trigger worthless, because the NPC could be destroyed and recreated. The workaround is to use GLOBAL variables for triggers and actions until the NPC joins the party.

Discussion and comments are encouraged at the tutorials forum at The Gibberlings Three.

Why is this Hypnotoad video so popu... ALL GLORY TO THE HYPNOTOAD.
____
The Gibberlings Three - Home of IE Mods

The BG2 Fixpack - All the fixes of Baldurdash, plus a few hundred more. Now available, with more fixes being added in every release.