Help with a global script to get an npc to heal the player?

Post » Thu Jul 17, 2014 1:38 pm

Hi there,

I've wrote a script which should in theory allow the player to talk to a healer npc, ask for healing and be fully healed.

Here is what should happen:

Player talks to the healer.

If player asks for healing, the global 'NON_ESHealStat' in the script below (I've marked it out) is set to 1, the script is started and dialogue is exited via 'goodbye'.

Here's the script:

Spoiler
Begin NON_ESFullHealing

Float Timer

If ( NON_ESHealStat == 1 ) ; this is a global which is set to 1 if the player requests healing through dialogue
FadeOut, 1.0
DisablePlayerControls
Set Timer to ( Timer + GetSecondsPassed )
If ( Timer > 3 )
MessageBox "Jocelyn attempts to heal you with a mixture of alchemical medicine and restoration spells..."
"NON_ESGuardStatHealer"->Cast, "NON_ESHealing2", "Player" ; this gets a nearby NPC to cast a spell to cure all diseases on the player
Player->AddSpell "NON_ESHealing1" ; this is an ability which rapidly restores player's health and fatigue
Player->AddSpell "NON_ESHealing2" ; same as above but for attributes
Set Timer to 0
Set NON_ESHealStat to 2
Endif
ElseIf ( NON_ESHealStat == 2 )
Set Timer to ( Timer + GetSecondsPassed )
If ( Timer > 3 )
Player->RemoveSpell "NON_ESHealing1"
Player->RemoveSpell "NON_ESHealing2"
Set GameHour to ( GameHour + 1.5 )
EnablePlayerControls
MessageBox "Jocelyn: I've done all I can for you"
FadeIn, 1.5
Set Timer to 0
Set NON_ESHealStat to 3
Endif
ElseIf ( NON_ESHealStat == 3 )
Set NON_ESHealStat to 0
StopScript NON_ESFullHealing
Endif

End

It works perfectly except for one thing: for some reason, right after the screen fades in at the end of the script, the screen fades out again immediately after and remains permanently black. I know the script isn't repeating itself because the messageboxes aren't being spammed.

Just in case I haven't been clear, the problem is: script fades screen out, does its stuff, fades the screen back in and finishes, but for some reason the screen fades back out immediately after fading back in and stays that way.

I've rewrote it a few times and swapped the 'FadeIn/Outs' to 'FadeTo' commands but I can't seem to get it to work. I'd really appreciate some help!

User avatar
Shae Munro
 
Posts: 3443
Joined: Fri Feb 23, 2007 11:32 am

Post » Thu Jul 17, 2014 10:29 pm

Your script appears sound. I tested it in game and had the results as you described. One thing I noticed that you did not mention is the script ran before exiting dialogue. Yes 'Goodbye' is presented as an option, but the script started before I could make the selection. I did not think this is what you want, particularly since an open window stalls animation but does not prevent your timer from running so perhaps this is derailing your code.

I added the following block of code to the top of your script (after the declaration). It is essential to include in order for timers to run reliably, and it is generally added to scripts to make them more efficient (although it does depend on the circumstances):

if ( menumode == 1 )    return ; do not process if menu is openendif

When I tested the script the fadeout still fired before I selected 'Goodbye', but the timer stalled until I closed the dialogue window. Thereafter the script executed as intended and there was no fadeout at the very end.

I do not know why the initial fadeout is firing in menumode. When I introduced a counter to delay the main script code from executing it did as I intended, but the terminal fadeout returned. This is the code I added to the top of your script:

short frameCounter if ( menumode == 1 )    returnendif if ( frameCounter < 3 )    set frameCounter to ( frameCounter + 1 )    returnendif

I will leave you to play with this some more. I am confident that you need the menumode check to prevent the fadeout at the end, but I am not certain what you will need to do to prevent the script from processing while still in dialogue since my first idea restored your original problem.

I should also mention that the fade persisted even after I loaded a saved game, and it regularly caused Morrowind to report an error upon closing. This suggests to me that the engine is still chewing on something – probably related to the fadeout issue.

I hope that I have given you enough insight to eventually fashion a solution.

User avatar
Epul Kedah
 
Posts: 3545
Joined: Tue Oct 09, 2007 3:35 am


Return to III - Morrowind