Difference between revisions of "Casting Spells From An Activator"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>Mrflippy
imported>Darkness X
 
(17 intermediate revisions by 9 users not shown)
Line 1: Line 1:
Casting Spells from an Activator
{{FeatNom}}
 
This is a short tutorial on how to use activators to cast spells. This will allow you to create more complicated spell effects such as lightning strikes or point blank area of effect spells.[[Image:CallLightning01.jpg|thumb|200px|The script you will be creating]]
This is a short tutorial on how to use activators to cast spells. This will allow you to create more complicated spell effects such as lightning strikes or point blank area of effect spells.
[[Image:CallLightning03.jpg|thumb|200px|Another view]]


By the end of this tutorial you should have a working point blank AoE lightning strike spell.
By the end of this tutorial you should have a working point blank AoE lightning strike spell.


[[Image:CallLightning01.jpg|thumb|200px|The spell you will be creating]]
==What you need== {{Tools|req0=[[The Elder Scrolls Construction Set|Construction Set]]|opt0=[[OBSE]]}}
[[Image:CallLightning03.jpg|thumb|200px|Another view]]
During this tutorial we will be creating the following:
 
==What you need==
During this tutorial we will creating the following:
*1 activator object
*1 activator object
*2 spells
*2 spells
Line 15: Line 12:


==Create the Activator==
==Create the Activator==
The first thing we need to do is create the activator object. This object will be used to cast spells.
The first thing we need to do is create a new activator object. This object will be used to cast spells.
 
In the [[Object_Window|Object Window]], Expand the WorldObjects item and select Activator. Right-click in the object list to the right and select "New" from the context menu that pops up.


Set these fields:
In the [[Object_Window|Object Window]], Expand the WorldObjects item and select Activator. Rename the activator with the Editor ID "ActivatorFlameNode0" to "SourceID" by slowly double-clicking on it, changing the name, and selecting "Yes" when the menu comes up.
*<b>ID:</b> Set this to "ActivatorSource"
*<b>NIF:</b> Set this to "magiceffects\null.nif" (This makes the activator invisible)


Leave the rest of the fields alone and click "OK".
We also need to create a reference of the new activator. In the [[Cell View Window]], select "Interior" from the pull-down menu. Then select the Editor ID "TestQuest01" in the box on the left. Right-click it and select "Duplicate Cell". Rename the cell to something you'll remember and double-click it to open it in the [[Render Window]]. Now, drag your new [[Activator]] "SourceID" to the [[Render Window]]. Double-click on the activator to open the "Reference" window. Name it "Source" in the "Reference Editor ID" box. Mark it as a "Persistent Reference" and "Initially Disabled".


==Create the Spells==
==Create the Spells==
Line 53: Line 46:


===The Self Spell Script===
===The Self Spell Script===
This script uses [[PlaceAtMe]] to create an activator and then uses that activator to [[Cast]] the AOE spell.
This script uses [[MoveTo]] to move your activator to the caster and then uses that activator to [[Cast]] the AOE spell.
 
Set the <b>Script Type</b> to <b>Magic Effect</b>


<pre>
<pre>
Line 66: Line 61:
set me to GetSelf
set me to GetSelf


;place an instance of the source activator that we created earlier
        ;set the reference to the activator
set source to me.PlaceAtMe ActivatorSource, 1, 0, 0
        set source to YourActivatorsReferenceEditorID


;add 200 to the height so it is above the actor
;add 200 to the height so it is above the actor
float height
source.MoveTo me 0, 0, 200
set height to me.GetPos z
set height to height + 200
source.SetPos z, height


;have the activator cast the AOE spell now
;have the activator cast the AOE spell now
source.Cast TutCallLightningAoeSpell me
source.Cast TutCallLightningAoeSpell me
;disable the activator so we don't have a bunch laying around
source.Disable
End</pre>
End</pre>


===The Area of Effect Spell Script===
===The Area of Effect Spell Script===
This script will be run on every actor that is hit by the TutCallLightningAoeSpell. This script will then create an activator using PlaceAtMe and use it to cast a lightning bolt at the affected actor. (Remember: This happens for each actor hit!)
This script will be run on every actor that is hit by the TutCallLightningAoeSpell. This script will then move the activator using [[MoveTo]] and use it to cast a lightning bolt at the affected actor. (Remember: This happens for each actor hit!)
 
Set the <b>Script Type</b> to <b>Magic Effect</b>


<pre>scriptname TutCallLightningAoeSpellScript
<pre>scriptname TutCallLightningAoeSpellScript
Line 96: Line 87:
set me to GetSelf
set me to GetSelf


;place an instance of the source activator that we created earlier
        ;set source to the activator
set source to me.PlaceAtMe FlippySource, 1, 0, 0
        set source to YourActivatorsReferenceEditorID


;add 1000 to the height so it looks like the lightning is coming from the sky
;add 1000 to the height to simulate lightning coming from the sky
float height
source.MoveTo me 0, 0, 1000
set height to me.GetPos z
set height to height + 1000
source.SetPos z, height


;have the activator cast the lightning spell at the affected actor
;have the activator cast the lightning spell at the affected actor
source.Cast StandardShockDamageTarget1Novice me
source.Cast StandardShockDamageTarget1Novice me
;disable the activator so we don't have a bunch laying around
source.Disable
End</pre>
End</pre>


Line 154: Line 139:


==Caveats==
==Caveats==
*This spell will hit the player as well as everyone around him. This may or may not be what you want. A simple if check in the TutCallLightningAoeSpellScript will prevent the spell from hitting the player:
*This spell will hit the player as well as everyone around him. This may or may not be what you want. A simple if check directly below the <tt>'''Begin ScriptEffectStart'''</tt> line in the TutCallLightningAoeSpellScript will prevent the spell from hitting the player:
<pre>
<pre>
...
...
Line 163: Line 148:
...</pre>
...</pre>


Note that a more complicated script is required to achieve this if any actor is able to cast this spell.
<B>Note</B> that a more complicated script is required to achieve this if any actor is able to cast this spell.
 
<B>Also Note</B> that this version of the spell will not cause aggro when it hits people. The reason for this is the fact that the player does not directly cast a spell at them. It is the activator above the enemy that casts the spell. Because of this the targets of the attack don't become agro at the player because to them it would seem like they were hit by some sort of magical trap.
 
This problem can be resolved in many ways:
*You could force the target into combat using [[StartCombat]] in TutCallLightningAoeSpellScript, but there are still some problems with that as well.
 
*Another solution to this problem is to only allow the spell to effect current enemies of the player.
This code can be added directly below the avoid hitting player code in TutCallLightningAoeSpellScript.
<pre>
...
; Only hit people who are in combat with the player
If IsInCombat == 1
If GetCombatTarget != player
return
endif
else ;If not in combat
return
endif
...
</pre>
This piece of code will prevent the spell from hitting players who are not currently in combat with the player. This changes the nature of the spell some, but does create a more realistic effect stopping the player from being able to damage people without upsetting them.


*This version of the spell will not cause aggro when it hits people. This can be changed by forcing the target into combat using [[StartCombat]] in TutCallLightningAoeSpellScript, but there are still some problems with that as well.
Other possible solutions include the use of [[GetIsCreature]], [[IsActorEvil]], and [[GetShouldAttack]]


[[Category: Useful Code]]
[[Category: Tutorials]]
[[Category: Tutorials]]
[[Category: Activators]]
[[Category: Activators]]
[[Category: Scripting_Tutorials]]

Latest revision as of 09:26, 15 April 2010

This is a short tutorial on how to use activators to cast spells. This will allow you to create more complicated spell effects such as lightning strikes or point blank area of effect spells.

File:CallLightning01.jpg
The script you will be creating

By the end of this tutorial you should have a working point blank AoE lightning strike spell.

What you need

Tools used in this tutorial

Required

Optional


During this tutorial we will be creating the following:

  • 1 activator object
  • 2 spells
  • 2 spell scripts

Create the Activator[edit | edit source]

The first thing we need to do is create a new activator object. This object will be used to cast spells.

In the Object Window, Expand the WorldObjects item and select Activator. Rename the activator with the Editor ID "ActivatorFlameNode0" to "SourceID" by slowly double-clicking on it, changing the name, and selecting "Yes" when the menu comes up.

We also need to create a reference of the new activator. In the Cell View Window, select "Interior" from the pull-down menu. Then select the Editor ID "TestQuest01" in the box on the left. Right-click it and select "Duplicate Cell". Rename the cell to something you'll remember and double-click it to open it in the Render Window. Now, drag your new Activator "SourceID" to the Render Window. Double-click on the activator to open the "Reference" window. Name it "Source" in the "Reference Editor ID" box. Mark it as a "Persistent Reference" and "Initially Disabled".

Create the Spells[edit | edit source]

Next, we need to create two spells. The first spell summons an activator near the caster and then has that activator cast the second spell. Making this second spell an area of effect spell will give us our point blank AoE spell.

The Self Spell[edit | edit source]

This is the spell that the player or actor will cast.

Expand the Magic list item in the Object Window. Select the Spell item underneath Magic and then right-click in the object list to the right. Select "New"

Fill in the fields:

  • ID: TutCallLightningTriggerSpell
  • Name: Call Lightning
  • Type: Spell

The Area of Effect Spell[edit | edit source]

This is the spell that the activator will cast.

Right-click in the spell listing again and select "New" from the context menu.

Fill in the fields:

  • ID: TutCallLightningAoeSpell
  • Type: Spell

Keep in mind that we haven't written the scripts yet, so we'll have to come back and set the scripts after we write them. We're creating things in this order because the scripts need to reference the spells, and the spells need to reference the scripts, but it's easier to create the spells and add the scripts in later.

Write the Scripts[edit | edit source]

Now it's time to write the scripts. Open up the script editor by selecting the "Gameplay->Edit Scripts..." menu. Once in the script window, select "Script->New..." from that window's menu.

The Self Spell Script[edit | edit source]

This script uses MoveTo to move your activator to the caster and then uses that activator to Cast the AOE spell.

Set the Script Type to Magic Effect

scriptname TutCallLightningTriggerSpellScript
;Casts an aoe spell at the caster which calls lighting down in a radius around him.

ref me			;holds a reference to the actor who is casting
ref source		;holds a reference to the activator

Begin ScriptEffectStart
	;get a reference to the caster
	set me to GetSelf

        ;set the reference to the activator
        set source to YourActivatorsReferenceEditorID

	;add 200 to the height so it is above the actor
	source.MoveTo me 0, 0, 200

	;have the activator cast the AOE spell now
	source.Cast TutCallLightningAoeSpell me
End

The Area of Effect Spell Script[edit | edit source]

This script will be run on every actor that is hit by the TutCallLightningAoeSpell. This script will then move the activator using MoveTo and use it to cast a lightning bolt at the affected actor. (Remember: This happens for each actor hit!)

Set the Script Type to Magic Effect

scriptname TutCallLightningAoeSpellScript

;Calls lightning down from the sky on a single target

ref me			;holds a reference to the actor who affected by this spell
ref source		;holds a reference to the activator

Begin ScriptEffectStart
	;get a reference to this actor
	set me to GetSelf

        ;set source to the activator
        set source to YourActivatorsReferenceEditorID

	;add 1000 to the height to simulate lightning coming from the sky
	source.MoveTo me 0, 0, 1000

	;have the activator cast the lightning spell at the affected actor
	source.Cast StandardShockDamageTarget1Novice me
End

Attach the Scripts to the Spells[edit | edit source]

Now that we have the scripts created, we need to attach them to the spells.

The Self Spell Script[edit | edit source]

Edit the TutCallLightningTriggerSpell spell. Right-Click in the Effects list and select "New" from the context menu.

Fill in the fields:

  • Effect: Script Effect
  • Range: Self
  • Duration: 0
  • Script: TutCallLightningTriggerSpellScript
  • Effect Name: Call Lightning
  • School: Destruction
  • Visuals Effect: NONE

Click OK in the Effect dialog and the spell dialog to save the spell.

The Area of Effect Spell[edit | edit source]

Edit the TutCallLightningAoeSpell. Right-click in the Effects list and select "New" from the context menu.

Fill in the fields:

  • Effect: Script Effect
  • Range: Target
  • Area: 100 (or 200, whatever you want. This is the area around the caster that the spell will affect)
  • Duration: 0
  • Script: TutCallLightningAoeSpellScript
  • Effect Name: Lightning Strike
  • School: Destruction
  • Visuals Effect: NONE

Click OK in the Effect dialog and the spell dialog to save the spell.

Save the Plugin[edit | edit source]

This is an important part of modding! Save your plugin with a descriptive name like "TutActivatorSpell"

Test the Spell[edit | edit source]

At this point, the spell should be ready to cast. You'll need to determine the Form ID of the TutCallLightningTriggerSpell spell. Refer to the Form ID page for more information.

Once you know the Form ID, you can use the following console command to give yourself the spell:

player.addspell FormID

Caveats[edit | edit source]

  • This spell will hit the player as well as everyone around him. This may or may not be what you want. A simple if check directly below the Begin ScriptEffectStart line in the TutCallLightningAoeSpellScript will prevent the spell from hitting the player:
...
set me to GetSelf
if me == player
    return
endif
...

Note that a more complicated script is required to achieve this if any actor is able to cast this spell.

Also Note that this version of the spell will not cause aggro when it hits people. The reason for this is the fact that the player does not directly cast a spell at them. It is the activator above the enemy that casts the spell. Because of this the targets of the attack don't become agro at the player because to them it would seem like they were hit by some sort of magical trap.

This problem can be resolved in many ways:

  • You could force the target into combat using StartCombat in TutCallLightningAoeSpellScript, but there are still some problems with that as well.
  • Another solution to this problem is to only allow the spell to effect current enemies of the player.

This code can be added directly below the avoid hitting player code in TutCallLightningAoeSpellScript.

...
; Only hit people who are in combat with the player
If IsInCombat == 1
	If GetCombatTarget != player
		return
	endif
else	;If not in combat
	return	
endif
...

This piece of code will prevent the spell from hitting players who are not currently in combat with the player. This changes the nature of the spell some, but does create a more realistic effect stopping the player from being able to damage people without upsetting them.

Other possible solutions include the use of GetIsCreature, IsActorEvil, and GetShouldAttack