Dynamically Attaching Scripts: Difference between revisions
Jump to navigation
Jump to search
m
added links
imported>Fg109 (added second section, various edits) |
imported>Fg109 m (added links) |
||
| Line 1: | Line 1: | ||
There are times that we may want to dynamically attach scripts to objects and actors. This could be because we don't want to alter the vanilla records, or because we think it's going to be too much work to edit every single vanilla record, or because we want our mod to work on objects added by other mods. | There are times that we may want to dynamically attach scripts to objects and actors. This could be because we don't want to alter the vanilla records, or because we think it's going to be too much work to edit every single vanilla record, or because we want our mod to work on objects added by other mods. | ||
| Line 12: | Line 10: | ||
=== Create a Reference Alias === | === Create a Reference Alias === | ||
First we need to create a reference alias. This step is not actually necessary, but it is easier to just load up the mod with the player already having the ability, rather than using the console to add the ability to the player. (Another way this could be done would be to create a quest script using [[AddSpell - Actor|AddSpell]].) | First we need to create a [[Quest_Alias_Tab#Reference_Aliases|reference alias]]. This step is not actually necessary, but it is easier to just load up the mod with the player already having the ability, rather than using the console to add the ability to the player. (Another way this could be done would be to create a quest script using [[AddSpell - Actor|AddSpell]].) | ||
Create a quest and | In the [[Object_Window|'''Object Window''']], navigate to [[Quest|'''Quest''']] under the '''Character''' category. Create a new quest by right-clicking on the list and choosing 'New'. Make sure that '''Start Game Enabled''' in the [[Quest_Data_Tab|'''Quest Data''']] tab is checked. Click on the [[Quest_Alias_Tab|'''Quest Alias''']] tab, then right-click in the empty list and choose to create a new reference alias. Make sure that the '''Fill Type''' is '''Specific Reference''' and choose the reference 'PlayerRef' in the '(any)' cell. | ||
Click OK to create the reference alias, and OK again to close the quest window. Hereafter, we will refer to the quest as '''DASQuest''' and the reference alias as '''PlayerAlias'''. | Click OK to create the reference alias, and OK again to close the quest window. Hereafter, we will refer to the quest as '''DASQuest''' and the reference alias as '''PlayerAlias'''. | ||
| Line 20: | Line 18: | ||
=== Create the First Ability === | === Create the First Ability === | ||
Next, we create the ability that we're going to put on the player. Navigate to '''Spells''' which is under '''Magic''' in the '''Object Window'''. Right-click in the list and choose to create a new spell. Change the '''Type''' to 'Ability', making sure that '''Casting''' is 'Constant Effect' and that '''Delivery''' is 'Self'. For now, we can leave the list of effects blank. | Next, we create the ability that we're going to put on the player. Navigate to [[Spell|'''Spells''']] which is under '''Magic''' in the '''Object Window'''. Right-click in the list and choose to create a new spell. Change the '''Type''' to 'Ability', making sure that '''Casting''' is 'Constant Effect' and that '''Delivery''' is 'Self'. For now, we can leave the list of effects blank. | ||
After closing the spell window, navigate to '''Magic Effects''', under '''Magic''' in the '''Object Window'''. Right-click in the list and choose to create a new magic effect. Change the '''Effect Archetype''' to 'Cloak'. The '''Casting Type''' should be 'Constant Effect' and '''Delivery''' 'Self'. Check the flag for '''Hide in UI'''. Click OK to accept the effect as is for now. | After closing the spell window, navigate to [[Magic_Effect|'''Magic Effects''']], under '''Magic''' in the '''Object Window'''. Right-click in the list and choose to create a new magic effect. Change the [[Magic_Effect#Effect_Archetypes|'''Effect Archetype''']] to 'Cloak'. The '''Casting Type''' should be 'Constant Effect' and '''Delivery''' 'Self'. Check the flag for '''Hide in UI'''. Click OK to accept the effect as is for now. | ||
Go back to the ability we just created, and in the effects list, add in the magic effect we just created. There doesn't have to be any conditions or duration, but the '''Magnitude''' needs to be changed. For now, give magnitude the value of 192.0. | Go back to the ability we just created, and in the effects list, add in the magic effect we just created. There doesn't have to be any conditions or duration, but the '''Magnitude''' needs to be changed. For now, give magnitude the value of 192.0. | ||
| Line 91: | Line 89: | ||
Remember to set the value of the 'MonitorAbility' to the '''MonitorAbility''' that we created earlier. Click OK to close the magic effect window. | Remember to set the value of the 'MonitorAbility' to the '''MonitorAbility''' that we created earlier. Click OK to close the magic effect window. | ||
Go back to the spell we just created, and add this new magic effect to its effects list. The magnitude and duration can be left at 0, but this time we need to add a condition. The condition is: | Go back to the spell we just created, and add this new magic effect to its effects list. The magnitude and duration can be left at 0, but this time we need to add a [[:Category:Conditions|condition]]. The condition is: | ||
HasMagicEffect MagicEffect: 'MonitorEffect' == 0 | [[HasMagicEffect]] MagicEffect: 'MonitorEffect' == 0 | ||
Make sure that it's set to run on '''Subject'''. If we don't want the spell to run on dead actors, we should add another condition run on '''Subject''': | Make sure that it's set to run on '''Subject'''. If we don't want the spell to run on dead actors, we should add another condition run on '''Subject''': | ||
GetDead NONE == 0 | [[GetDead]] NONE == 0 | ||
Hereafter we will refer to this spell as '''ApplyingSpell''' and the magic effect as '''ApplyingEffect'''. | Hereafter we will refer to this spell as '''ApplyingSpell''' and the magic effect as '''ApplyingEffect'''. | ||
| Line 116: | Line 114: | ||
=== Create a FormList === | === Create a FormList === | ||
First, we're going to create a | First, we're going to create a [[FormList]] of trees that we want to give out firewood. We will be using this later to fill the reference aliases we create. | ||
Navigate to '''FormList''' under '''Miscellaneous''' in the '''Object Window'''. Right-click on the list and select 'New' to create a new formlist. Now navigate to '''Landscape''' under '''Tree''' which is under '''World Objects''' in the '''Object Window'''. | Navigate to '''FormList''' under '''Miscellaneous''' in the '''Object Window'''. Right-click on the list and select 'New' to create a new formlist. Now navigate to '''Landscape''' under '''Tree''' which is under '''World Objects''' in the '''Object Window'''. Highlight everything in the list, then click and drag them into the new formlist. | ||
Click OK to create the formlist. Hereafter we will refer to this formlist as '''TreesList'''. | Click OK to create the formlist. Hereafter we will refer to this formlist as '''TreesList'''. | ||
| Line 128: | Line 126: | ||
Go to the '''Quest Alias''' tab, then right-click on the empty list and choose to create a new reference alias. Check the flag for '''Optional'''. For '''Fill Type''', choose '''Find Matching Reference''' and check the flags for '''In Loaded Area''' and '''Closest'''. Under '''Match Conditions''', right-click the list and select 'New' to create a new condition: | Go to the '''Quest Alias''' tab, then right-click on the empty list and choose to create a new reference alias. Check the flag for '''Optional'''. For '''Fill Type''', choose '''Find Matching Reference''' and check the flags for '''In Loaded Area''' and '''Closest'''. Under '''Match Conditions''', right-click the list and select 'New' to create a new condition: | ||
IsInList 'TreesList' | [[IsInList]] 'TreesList' == 1.00 | ||
Click OK to close the alias window. Then double-click on the alias in order to open it again. We need to do this step because when we first create an alias, we can't attach a script to it. Attach this script to the reference alias: | Click OK to close the alias window. Then double-click on the alias in order to open it again. We need to do this step because when we first create an alias, we can't attach a script to it. Attach this script to the reference alias: | ||