NPC scripting conflict (MAO+Starfires NPC Additions) ->

Post » Sat May 16, 2015 6:26 pm

As some others have reported, I was having a lot of trouble with PeterBitt&Logitech's MAO (that is awesome!) scriptextender crashing very frequently (every few minutes). I'm not sure for others, but in my case I isolated the main culprit as an incompatibility between the MAO scriptextender and Starfire's NPC Additions. It seems as Starfire's NPC additions got periodically deleted the scripts attached to them through the MAO scriptextender were apt to CTD. The only way I could figure out how to fix this incompatibility was to modify Starfire's NPC additions to first disable the NPC for a few seconds before deleting them AND the MAO scriptextender NPC attached scripts to check if the NPC was disabled and stop the script before they were deleted. This seems to be the best practice on both ends as described in the venerable MSFD (all praise and thanks to GhanBuriGhan, Yacoby and melian!).

After I got this working, I did a grep for setdelete on my other installed mods (over 250) and found a discouraging large number of creature and npc scripts that appear to either have no disable before delete or immediately delete after disable without any timeout. The number of mods I have potentially attaching scripts to unrelated NPCs/Creatures (grepping MWSE xFirstNPC/xNextRef) without disable check seems quite a bit less but still not zero. Ideally I think I should go through and fix these all as described above, but before doing so I wanted to check with the community if this is a problem that has already been solved or is better solved another way?

User avatar
krystal sowten
 
Posts: 3367
Joined: Fri Mar 09, 2007 6:25 pm

Post » Sat May 16, 2015 4:24 pm

I think MAO checks for script detaching on reload using a NPC size. Maybe adding a GetHealth <= 0 test (or any other function not crashing on a deleted reference that could return something useable) could help with the problem

[EDIT] Or/and you could try adding the delay to all mods using setdelete. I think in theory a fix would be better placed in the script causing the crash, but maybe best solution depends on how easy to code/how often changes to MAO happen compared to changing MCA/Starfire and similar mods code.

[EDIT2]Some talk about setdelete also http://www.gamesas.com/topic/1505207-wipz-unofficial-morrowind-patch/?p=23952796

User avatar
Jeffrey Lawson
 
Posts: 3485
Joined: Tue Oct 16, 2007 5:36 pm

Post » Sat May 16, 2015 7:36 pm

Good work, sveng. MCA / Starfire is part of KINGPIX's overhaul compilation, right? This explains why so many people have problem with this particular plugin even though it is stable for us.

As abot said, maybe I could add some additional check in MWSE scripts that would be able to detect if reference is no longer viable (although it can't be GetHealth - that check need to be later in the script). In such case even that GetDisabled won't be necessary (but it's still good to have it there). This way you wouldn't need to edit any other mods. I will send you newest MAO for tests with your mods if you want to help us with this task. Check your PM box for more details (btw. this is the best way to contact with me - I've almost missed your topic).

If we find a proper solution for this problem I will post it here, so other modders who use MWSE targeted scripts know how deal with it.

edit: ok, here is a result of my tests:
- there is no way to check if reference still exists in game inside targeted script. I've tried some commands like GetItemCount, GetScale, GetHealth - they all show values that were true for reference before it has been deleted.

- if you use SetDelete on NPC without disabling him first than the NPC will be still rendered in game. If you activate such reference the game will crash.
- reloading the game or exiting and than loading won't remove target script from deleted NPC reference and it won't change what the script returns. My test code was still able to show following messagebox after reload:

    set fVar to GetFatigue    set fVar2 to GetItemCount "common_shirt_05"    set fVar3 to GetScale    set fVar4 to GetHealth    MessageBox "fVar = %g, fVar2 = %g, fVar3 = %g, fVar4 = %g" fVar fVar2 fVar3 fVar4

- the game doesn't crash if above commands are used via targeted script even if reference has been deleted
- crash occurred when I've tried to use RemoveItem command on deleted reference
- only workaround for target scripts seems to be detecting GetDisabled that shows up correctly and stopping the script as soon as possible (before one of the commands that crashes the game is triggered).

So what is mentioned in Morrowind Scripting for dummies is true - if someone want to create mods compatible with other plugins there must be some delay before deleting the reference. In MAO case all that is required will be 1 frame, so if the mod uses something like:

        if ( GetDisabled == 0 )            Disable            return        else ; doesn't matter if the mod checks GetDisabled, this is just an example showing how it can be done without additional variables            SetDelete 1            return        endif

than it will work correctly with the newest, unreleased MAO (other mods with targeted scripts may need more time after delete, depending how they were coded, so it's better to add some additional delay). But this code would crash the game (not only MAO but many other mods that use targeted scripts):

    Disable    SetDelete 1
User avatar
Nicholas C
 
Posts: 3489
Joined: Tue Aug 07, 2007 8:20 am

Post » Sun May 17, 2015 1:52 am

Hi Abot,

Thanks for the link. It's definitely helpful to understand this issue better. Also, please see my question below..

Hi Logitech,

Yeah, Starfire's scripts definitely seem problematic, that need to be fixed even with MAO NPC scripts checking for disable. All except one include variations of setdelete without disable such as:

if ( GameHour >= 22 )  SetDelete 1	endif ... return

I originally added a 1.5sec delay between disabling and deleting NPCs in my modified Starfire's scripts but I just confirmed that a single frame delay appears to work OK, too. Since I can't see any disadvantage I'll probably stick with the longer delay between disable and deletion, just in case, as others have suggested.

It's a shame because Starfire's NPCs is a really nice and popular mod. Since I've already edited the scripts I'd be happy to share the fix with others. Since I'm new to this maybe someone with more experience in the community could advise me the best way to do that.

I quickly spot checked Neoptolemus' MCA scripts and they seem to adhere a good practice:

if ( GetDisabled == 1 )	SetDelete, 1	Returnendifif ( GameHour < 7 )	Disable	Returnelseif ...

Checking my other installed mods for instances of 'setdelete' on NPCs or creatures more carefully, I think there may only be a few questionable scripts in a couple of the more popular mods but need to look into it more carefully before I make any claims.

Hi again Abot,

It seems you take good care of this in your many excellent mods I have installed (although I must admit the logic between disable and delete is a bit complex for me to follow in some of them). One point I noticed (also brought up in the link you provided above) is the time delay you set between disabling some objects (creatures) and deleting them related to the sound(s) they are emitting, such as in your abotboats ab01boBoat01Script attached to your Long Boat creatures:

if ( de_count > 0 )elseif ( GetDisabled )	if ( SayDone == 0 )		return	elseif ( GetSoundPlaying "ab01BoatHull" )		StopSound "ab01BoatHull"		return	elseif ( t1 < 7 ) 	; boat sounds are < 5 sec		set t1 to ( t1 + GetSecondsPassed )		return	endif	set t1 to 0	setdelete 1	returnendif

So in your experience is it good practice after disabling an object, to wait for it to finish any sound(s) it is emitting before deleting it? I didn't notice any problem with my modified Starfire's NPC scripts deleting NPCs one frame after disabling them, and I guess they are more or less constantly emitting >1frame sounds, so probably I'm missing the point; or maybe I just didn't test for long enough and eventually I'd end up with a CTD?.. Thanks.

User avatar
Andrew Lang
 
Posts: 3489
Joined: Thu Oct 11, 2007 8:50 pm


Return to III - Morrowind