Scripting a new summoning spell
On to the fourth part-- time to consider that scripting. We'll take a couple of things into account here.
What should the new spell do?
Well, it should summon an alit. Let's say that the alit will need to appear when the spell is cast, fight for the player, and disappear in 60 seconds, like the original Morrowind summoned creatures. In addition, there should be no more than one summoned alit at a time.
We'll need to do the following:
- check for the spell in the player's spellbook
- verify the spell ID in effect on the player
- check for the levitate spell effect on the player
- remove the levitate spell effect
- summon the alit
- a timer to make the alit disappear in 60 seconds
- a way to make the first alit disappear if the player summons another one
Functions used
The scripts use the following functions. Click the function name to open its description at the UESP.
- Disable is used to remove the summoned alit.
- GetDisabled is used to check if we've already removed the summoned alit.
- GetDistance is used to check the distance between two objects.
- GetEffect is used to check for spell effects on the player-- in this case, sEffectLevitate.
- GetHealth is used here to check that the summoned alit's health before setting it to -100.
- GetSpell is used to check if the player knows the spell.
- GetSpellEffects is used to see if the player is currently affected by the spell ID.
- MenuMode checks if the player has the menus open.
- PlaceAtPC is used to place the summoned alit at a given distance and position from the player.
- RemoveEffects is used to remove the levitate spell effect on the player.
- ScriptRunning is used to check if the global script is already running.
- set is used to change the value of the variables.
- SetHealth is used to change the summoned alit's health when time runs out, or if another one is summoned.
- StartScript is used to start the global script.
The spell is broken up into a two scripts-- a local script on "alit_summon", and a global script.
There's a third script attached to the NPC that sells the new spell which will start the global script. This third script is not necessary if you'll be starting the global script through dialogue.
Let's start with a way to track the number of instances of "alit_summon" we have in the game.
Setting up the global variable
Click on the Gameplay menu.
Select Globals.
Click the New button.
The variable name used in the scripts to follow is SumAlitCheckNum.
Type it in the text box, and click OK.
Leave Variable Type to Short.
Leave Value set to 0.
Checking for the spell, and summoning the alit
The global script checks for the spell and places "alit_summon" into the game. A pseudoscript way of looking at it might be as follows:
- If the player has the spell "summon_alit", mark step one as done.
- If step one is done, check to see if the spell "summon_alit" is affecting the player. If so, mark step two as done.
- If step two is done, check to see if the player has the levitate effect assigned to the spell "summon_alit". If so,
- remove the levitate effect,
- add one to the total number of summoned alits in the game, and
- mark step three as done.
- If step three is done, summon the alit. Mark step four as done.
- Reset the script so the spell will work the next time.
The global script summon_AlitScript:
Banishing the alit
Now, we still need to get rid of "alit_summon" after 60 seconds. Also, we should set it up so that there won't be more than one of them floating around at a time.
We'll do the same bit with the pseudoscripting first.
- If there are two or more summoned alits in the world,
- and the health of this summoned alit is greater than or equal to 0
-
set the health of this alit to -100
- and if this alit hasn't been removed from the game yet,
- subtract one from the total number of summoned alits in the game and
- remove this summoned alit.
-
If the summoned alit is in the same cell as the player,
- start the timer.
- If the timer hits 60 seconds, reset the timer and go to the next step.
- If the health of this summoned alit is greater than or equal to 0
-
set the health of this alit to -100.
- If this alit hasn't been removed from the game yet,
- subtract one from the total number of summoned alits in the game and
- remove this summoned alit.
The local script alit_summonScript:
Starting up the global script
We'll need a way to run the script that checks for the spell. It can be done more than one way-- StartScript summon_AlitScript in a Dialogue Result box should do it, or attach a simple script to the NPC that sells the spell.
summonTestNPCScript