Scripts: Animate dead body spell

Post » Sun Sep 11, 2011 8:00 pm

Hello again, forum's users.
I'm trying to make completely new spell book (in my mod of course) divided by magic schools in order to create some kind of magic school specialisation (for example train in necromancy). For the best realism I've manage to put all necro-summoning spells only in the nearness to dead body. Here goes my question:

What's the easiest way to make spell, working only in nearness to the dead body, summoning undead creature precisely where the body lies?

One way is to set AddSpell and RemoveSpell for the player in a specified radius only when creature is dead ( where OnDeath will set specific state, listening for GetDistance function). However, still I don't know how to put creature in the place of the body.
User avatar
!beef
 
Posts: 3497
Joined: Wed Aug 16, 2006 4:41 pm

Post » Sun Sep 11, 2011 9:01 pm

Hello again, forum's users.
I'm trying to make completely new spell book (in my mod of course) divided by magic schools in order to create some kind of magic school specialisation (for example train in necromancy). For the best realism I've manage to put all necro-summoning spells only in the nearness to dead body. Here goes my question:

What's the easiest way to make spell, working only in nearness to the dead body, summoning undead creature precisely where the body lies?

One way is to set AddSpell and RemoveSpell for the player in a specified radius only when creature is dead ( where OnDeath will set specific state, listening for GetDistance function). However, still I don't know how to put creature in the place of the body.

Hey there,

What you're trying to make is not something that the vanilla Morrowind scripting engine can handle. You will need to search the current cell for NPCs (and/or creatures) and determine their eligibility for your spell based on their alive/dead status, vicinity to the player character, and possibly some other things. Morrowind script is quite powerful but this is beyond its limitations.

Luckily, we have MWSE. MWSE can both search the current cell for object references of any type and carry out targeted scripts on any references it may have found.

Here's a sample script that should do roughly what you said (although keep in mind I did not test this):

Begin raisedead_global_scriptlong templong npcreffloat npctestStopScript, "raisedead_global_script"set npcref to 0setx temp to xFirstNPCwhilex ( temp )    xSetRef, temp    set npctest to GetHealth    if ( npctest < 1 )        set npctest to 1    else        set npctest to 0    endif    ifx ( npctest )        xSetRef, temp        set npctest to GetDistance, "player"        if ( npctest < 768 )            set npctest to 1        else            set npctest to 0        endif        ifx ( npctest )            set npcref to temp            set temp to 0        else            setx temp to xNextRef, temp        endif    else        setx temp to xNextRef, temp    endifendwhileif ( npcref == 0 )  MessageBox, "No valid target found."  ReturnendifxSetRef, npcrefPlaceAtMe, "raisedead_cre", 1, 0, 0End


Something like that. The script should be run using StartScript when the player casts the spell. You can create a start script that checks whether the spell affects the PC using the GetSpellEffects function and start the global script only when it does (also removing the spell from the player so it only does so once per casting).

There can be further things implemented like removing the corpse once it's been animated, etc. If you do decide to use MWSE and implement this script or something similar in your mod, just keep in mind that MWSE scripts must be compiled in MWEdit, and you should not load any master files along with your plugin while doing so.
User avatar
Hearts
 
Posts: 3306
Joined: Sat Oct 20, 2007 1:26 am


Return to III - Morrowind