Jump to content

Scripting - Moving NPC crashes game (MakeGlobal/MoveGlobal/DestroySelf)


Recommended Posts

Hi again,

I work on my first small mod for BG1 part of BGT and I'm still learning modder world. I encountered a game grash when I wrote a moving NPC to another area baf script.

From the beginning: I need to remove joinable NPC from the world (from any place) after entering to my area. There are 3 posibilities on how I should handle such NPC:

1. I've never enter area where NPC spawns. This is easy - to disable NPC I've just set "BGTNPCxxxx" variable to 1
2. I've met NPC but disallowed to join the party. As I understand, NPC is not included in GAM file yet so I've tried to do this by MakeGlobal() function. Then I can call MoveGlobal on my area.
3. NPC joined my party so script from 2 bullet is applied and it looks like game adds NPC to GAM file twice. 

 

As an example let's consider Alora NPC. I extended top AR7230.bsc (Hall of Wonder) script with this snippet:

IF
    Global("MyMod_AloraIsGlobal", "GLOBAL", 0)
    Exists("Alora")
THEN
    RESPONSE #100
    ActionOverride("Alora", MakeGlobal())
    SetGlobal("MyMod_AloraIsGlobal", "GLOBAL", 1)
    Continue()
END

As Alora is now Global I should be able to move her with MoveGlobal. My area's script contains:

IF
    !InPartyAllowDead("Alora")
    Global("MyMod_AloraDestroyed", "GLOBAL", 0)
THEN
    RESPONSE #100
    MoveGlobal("MyAR", "Alora", [0.0])
    ActionOverride("Alora", DestroySelf())
    SetGlobal("MyMod_AloraDestroyed", "GLOBAL", 1)
    Continue()
END

As of now everything works. However when I allowed Alora to join, kicked her from party later, and I moved to my area (to remove her from world) and came back to AR7230 - game crashes.

 

Is it related to doubled NPC entry in GAM file?

I can't find what exacly causes the crash, last TobEx entry is "[Sun 28 Jun 2020 18:46:43] AREA-TRANSITION: CInfGame::SetVisibleArea" 

How can I fix this? Is there any good solution to track position of NPC (NPC could be in party or not).

Thanks!

 

Link to comment

Did youn debug to make sure this is causing this? I.e. does the area crash if your script did not run etc.?

I wouldn't know why MakeGlobal() would lead to a crash, but I also wasn't aware that it might make double entries in the GAM file.

Link to comment

 

39 minutes ago, jastey said:

Did youn debug to make sure this is causing this? I.e. does the area crash if your script did not run etc.?

I don't know what tools can be used to debug it further. Without my logic game runs correctly. My setup contains only TobEx + BG2fixpack + BGT + my mod.

 

39 minutes ago, jastey said:

I wouldn't know why MakeGlobal() would lead to a crash, but I also wasn't aware that it might make double entries in the GAM file.

I'm not sure if the root cause is MakeGlobal(). Maybe "ActionOverride("Alora", DestroySelf())" causes that BGT AR7230 script crashes because it checks for Alora existence... 
It is my deduction that MakeGlobal and then NPC joining will add entry twice in GAM because in EE there is MakeGlobalOverride() which prevents this, right?

 

I will check later if moving NPC (without destroy) causes this crash.

Link to comment

It is really weird... I have changed my script to not use a MakeGlobal function at all. I observed that game still crashes but there was no Alora's DestroySelf() call by my script. I uses CLUAConsole:MoveToArea() to access some areas for testing my scripts. Can it be related to this?

Link to comment

Whoa... You're right - BGT crashes without my mod. Traveling with worldmap works good.

 

I think AR7230.bcs script is still running even in the another area. Probably game does not unload the scripts from previous location when moved via console. I edited BGT script to check if Alora IsActive() to prevent double activation when Alora is not in AR7230. And it looks like working solution. I will push my fix to BGT repo later.

 

Thanks a lot!

Edited by Roberciiik
Link to comment

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...