[All Games] Taking out a hub NPC when a certain character is on your team

Started by Enchlore, March 27, 2020, 05:38PM

Previous topic - Next topic
There are a lot of mods that add characters that were originally just NPCs to your game, like Vision and Hank Pym. It's all nice and well except that for some of those, you'll encounter them in a hub, leading to there being two of the same character... fortunately there's a very simple solution!

First you have to find the script that spawns the NPC. It will often be called sc_(name of the character).py (i.e. sc_vision.py, sc_pym.py, sc_wingfoot.py), but sometimes the NPC is spawned through other script. Clea in MUA1, for example, is spawned in strange2.py. These scripts are located in scripts -> actX -> level name (actX depending on what act the level is in, and level name being, obviously, the level's name, like "stark" for Stark Tower, "sanctuary" for Sanctuary in XML2 etc).

If your NPC has a sc_XXXX.py spawn script, all you have to do is put this code at the top of the script:
XXXX = isActorOnTeam("XXXX" )
if XXXX == 1
remove ("YYYY", "" )

Replace XXXX with the internal name for the character on your team (for example, Maegawa's Vision mod's internal name is "visiondlc"). If you're unsure, check the actors folder or the herostat.
Replace YYYY with the NPC's name (for example, Hank Pym's internal name is "hank"). If you're unsure, check some scripts to see how they're referred to.

Here's what my sc_vision.py script looks like, for reference:
visiondlc = isActorOnTeam("visiondlc" )
if visiondlc == 1
remove ("vision", "" )
playanim (  "EA_ZONE13", "vision", "LOOP", "" )

The code for removing the NPC when Vision is on the team is there at the top, then the rest of the script is left alone after the "else" line.

With some NPCs, like Clea in MUA1, it's a little bit more delicate. Clea is spawned in strange2.py, and to remove her NPC when her character mod is on the team, you have to add the code in the right spot. If you're not very experienced with scripts and coding (like me!), finding the right place might take some trial and error. Here's what a strange2.py script that removes the Clea NPC if she's on your team looks like:
setRecallActive("FALSE" )

waittimed ( 0.250 )
murder_done = getObjective("Murder_Obj40", "COMPLETE" )
clea2 = isActorOnTeam("clea2" )
if clea2 == 1
remove ("clea", "" )
if murder_done == 1
     copyOriginAndAngles("clea", "clea_sitting" )
     playanim (  "EA_ZONE2", "clea", "LOOP", "" )
     second_intro = getGameFlag("strange", 12 )
     if second_intro == 0
          setGameFlag("strange", 19, 1 )
          setGameFlag("strange", 12, 1 )
          cameraFocusToEntity("weasel_intro_cam", 50.000, 15.000, 180.000, 0.500 )
          startConversation("act2/strange/2_strange2_220" )
          setWaypointPath("weasel", "weasel_talk", 1 )
     intro = getGameFlag("strange", 11 )
     if intro == 0
          setGameFlag("strange", 19, 1 )
          setGameFlag("strange", 11, 1 )
          cameraFocusToEntity("clea", 120.000, 15.000, 180.000, 0.500 )
          startConversation("act2/strange/2_strange2_010" )
          setWaypointPath("weasel", "weasel_talk", 1 )
          copyOriginAndAngles("clea", "clea_sitting" )
          playanim (  "EA_ZONE2", "clea", "LOOP", "" )
spawn_ghostrider = getObjective("mephisto_obj30", "COMPLETE" )
if spawn_ghostrider == 1
     act("sp_ghostridersimple01", "" )
book_ready = getObjective("strange_obj30", "HIDDEN" )
if book_ready == 0
     got_book = getGameFlag("strange", 2 )
     if got_book == 1
          remove ( "vision_book", "" )
          remove ( "green_book", "" )
          setEnable("vision_book", "TRUE" )

As you can see, I had to find the right spot to place my code or else it wouldn't work as intended. It also had the side effect of completely skipping her short intro, Weasel conversation included, but otherwise it works well.

That's it! It's pretty simple, and I hope this little tutorial was easy to understand.
I'm a modder from Brazil. Check out my mods!

Another thing to add is that new spawn codes for an NPC can be added in a map's engb file found in the Maps folder (and appropriate sub-folders). It's best to look at other codes and compare them before making your own. The hardest part is determining spawn coordinates

I'm so glad I stumbled upon this tutorial!

There are so many roster decisions I've made based on hating the NPC being present when the character is on my team- Vision chief among them.

This is a godsend! You've made some of my favorite little coding discoveries. Thank you for sharing your knowledge in such detail!