Home‎ > ‎

Morrowind Scripting Tips

While playing with Morrowind mods, I've come across a few gotchas and tips, and I'll share them here.

GetSoundPlaying is unreliable on some systems

I first noticed this problem while playing as a vampire because two of the mods that I was using, "Vampire Embrace" (VE) and "Vampire Realism" (VR) weren't working correctly for me.

VE allows you do do a "combat bite", where, if you punch someone until their fatigue goes below 10, then you will automatically move close to them and do the neck biting animation and suck their blood. However, this feature was very unreliable for me. I would often punch someone until they fall down, they'd get back up, I'd punch them until the fall down again, and this could go on dozens of times before a combat bite initiated. Even the Readme suggests that this may happen occasionally, and if so, to just try again. But for me, the problem happened the vast majority of times with some NPCs.

VR has a "staking" feature, where you can't kill a vampire unless you hit them with a special stake. You're supposed to fight them until they are knocked down, then use the stake on them, and that will kill them. However for me, I'd fight them, they'd go down, I'd use the stake on them, nothing would happen, they'd get back up, I'd do it all over again. Sometimes I would get a kill, other times the vampire would just keep getting back up, they were virtually immortal.

So I went to PES and looked through all the comments there, and it turns out that some small but significant population of the users of these mods have the same problems.

Looking at the scripting code in these mods, the common factor was that they both used GetSoundPlaying to recognize the event when the NPC was hit.

I still have not found an elegant solution, but I've been able to change the scripts in VE and VR so that they work pretty well now without using GetSoundPlaying. For VE, I use OnKnockout and combine that with checking if ( Player->GetWeaponType == -1 ) [I have a patch for VE's combat bite on my mods page]. For VR, I just commented out the use of GetSoundPlaying as it was essentially superfluous, since HitOnMe was previously checked. I still have more testing to be done.

Looking at code in Bethesda's original scripts, we see that GetSoundPlaying is never used to detect events, it is only used for managing when sounds are played. Sometimes it checks to see if a sound is not playing, so the sound can be started, like this:

    if ( GetSoundPlaying "ghostgate sound" == 0 )
        playloopsound3dvp "ghostgate sound" 1.0 1.0
    endif

and sometimes it checks to see if a sound is playing, so it can be stopped, like this:

    if ( GetSoundPlaying "heart" == 1 )
        StopSound "heart"
    endif

So my conclusion is that GetSoundPlaying is best used only for sound management, and should not generally be used to detect events unless you also offer some alternative method of detection. Also, it is probably pretty safe to check if a sound is not playing. The biggest trouble seems to be when it is used to check if a sound is playing, i.e. event detection. But many user mods already do use GetSoundPlaying for event detection, and I suspect that my opinion on the matter will be highly unpopular with scripters!


Scripts on Doors break other scripts that use CellChanged

I encountered this problem with a mod that was adding scripts to a number of doors, including the doors that go to Vivec Arena. Vivec Arena is used in a few quests because duels take place there, such as between you and Bolyn Venim (for House Redoran quests), or between you and Trebonius (for Mage Guild quests).

There is a special ring (common_ring_01_arena) buried under the floor of the Arena cell that is an activator that runs the VivecArenaScript script. At the top of VivecArenaScript it checks CellChanged to see if the script is executing on the frame when the player enters the arena, and if not, it simply returns. Thus the body of the script should only execute once as the player enters. The body of the script triggers the appearance of your dueling opponent given the appropriate quest stage. When a user mod adds a script to the arena doors, it acts like it "eats" the frame where CellChanged takes place, so when VivecArenaScript runs, CellChanged is always 0, and the script never executes its body and your opponent never appears. This breaks multiple quests that use the Arena.

Needless to say, my conclusion is that you should never, ever attach scripts to doors, unless you are absolutely sure no other mod now or ever will use the CellChanged function. Conversely, one should be aware when using CellChanged, that if you or anyone attaches a script to a door in your cell, CellChanged will always be 0.

Original posting about this at Bethsoft forums

Email your Comments or Suggestions to: john . moonsugar @ gmail . com

Comments