Dynamically Attaching Scripts: Difference between revisions

Jump to navigation Jump to search
m
Convert source tags to syntaxhighlight
imported>Chesko
(Modified code slightly to check if the quest is completely stopped, with failover after 5 seconds. Should result in less waiting and more reliability.)
m (Convert source tags to syntaxhighlight)
 
Line 64: Line 64:
We'll give this the ID <code>'''ApplyingEffect'''</code> and a descriptive Name, and then click OK to accept the changes.  Open the Effect again to add a new a script, which we will title <code>'''ApplyingScript'''</code>:   
We'll give this the ID <code>'''ApplyingEffect'''</code> and a descriptive Name, and then click OK to accept the changes.  Open the Effect again to add a new a script, which we will title <code>'''ApplyingScript'''</code>:   


<source lang="papyrus">Scriptname ApplyingScript extends ActiveMagicEffect   
<syntaxhighlight lang="papyrus">Scriptname ApplyingScript extends ActiveMagicEffect   


Spell Property MonitorAbility Auto
Spell Property MonitorAbility Auto
Line 70: Line 70:
Event OnEffectStart(Actor akTarget, Actor akCaster)
Event OnEffectStart(Actor akTarget, Actor akCaster)
akTarget.AddSpell(MonitorAbility)
akTarget.AddSpell(MonitorAbility)
EndEvent</source>
EndEvent</syntaxhighlight>
Save the script, and click OK to accept all changes.  We will be coming back to this effect to fill its Conditions and script properties later.
Save the script, and click OK to accept all changes.  We will be coming back to this effect to fill its Conditions and script properties later.


Line 98: Line 98:
We'll be giving it the ID <code>'''MonitorEffect'''</code> and a descriptive Name, then click OK to accept the changes.  Open the Effect again to add a new script, which we will title <code>'''MonitorScript'''</code>:
We'll be giving it the ID <code>'''MonitorEffect'''</code> and a descriptive Name, then click OK to accept the changes.  Open the Effect again to add a new script, which we will title <code>'''MonitorScript'''</code>:


<source lang="papyrus">Scriptname MonitorScript extends ActiveMagicEffect   
<syntaxhighlight lang="papyrus">Scriptname MonitorScript extends ActiveMagicEffect   


Actor MySelf
Actor MySelf
Line 125: Line 125:
Debug.Notification("You did " + Damage as Int + " points of damage.")
Debug.Notification("You did " + Damage as Int + " points of damage.")
endif
endif
EndEvent</source>
EndEvent</syntaxhighlight>
Save the script, and click OK to accept all changes.  We will come back to this effect to fill its Conditions later.
Save the script, and click OK to accept all changes.  We will come back to this effect to fill its Conditions later.


Line 182: Line 182:
We can accomplish this by adding the <code>'''CloakAbility'''</code> to the player, waiting a short amount of time, and then removing it. To do this, we will need to add a script to our <code>'''PlayerAlias'''</code>.  Open your quest, and click on the [[Quest_Alias_Tab|'''Quest Alias''']] tab. Double-click on our <code>'''PlayerAlias'''</code> to open up the Reference Alias window.  Add a new script to our alias. We will call it <code>'''PlayerScript'''</code>, and fill it with the following code:
We can accomplish this by adding the <code>'''CloakAbility'''</code> to the player, waiting a short amount of time, and then removing it. To do this, we will need to add a script to our <code>'''PlayerAlias'''</code>.  Open your quest, and click on the [[Quest_Alias_Tab|'''Quest Alias''']] tab. Double-click on our <code>'''PlayerAlias'''</code> to open up the Reference Alias window.  Add a new script to our alias. We will call it <code>'''PlayerScript'''</code>, and fill it with the following code:


<source lang="papyrus">Scriptname PlayerScript extends ReferenceAlias   
<syntaxhighlight lang="papyrus">Scriptname PlayerScript extends ReferenceAlias   


Spell Property CloakAbility Auto
Spell Property CloakAbility Auto
Line 199: Line 199:
RegisterForSingleUpdate(4)
RegisterForSingleUpdate(4)
EndEvent
EndEvent
</source>
</syntaxhighlight>
Now we will save the script and auto-fill the properties. This method of adding and removing the cloak is also used in circumventing the [[#The_.27Brawl_Bug.27|''''Brawl Bug'''']].
Now we will save the script and auto-fill the properties. This method of adding and removing the cloak is also used in circumventing the [[#The_.27Brawl_Bug.27|''''Brawl Bug'''']].


Line 206: Line 206:
Not using the '''No Death Dispel''' flag on effects with scripts can lead to errors.<sup>[[#References|[1]]]</sup>  To avoid these, you should handle the cleanup of your magic effect in the magic effect itself. Example:
Not using the '''No Death Dispel''' flag on effects with scripts can lead to errors.<sup>[[#References|[1]]]</sup>  To avoid these, you should handle the cleanup of your magic effect in the magic effect itself. Example:


<source lang="papyrus">Scriptname MonitorScript extends ActiveMagicEffect   
<syntaxhighlight lang="papyrus">Scriptname MonitorScript extends ActiveMagicEffect   


Event OnEffectStart(Actor akTarget, Actor akCaster)
Event OnEffectStart(Actor akTarget, Actor akCaster)
Line 237: Line 237:
EndState
EndState


</source>
</syntaxhighlight>




Line 266: Line 266:
Now we will wrap our code in <code>'''PlayerScript'''</code> with a condition to run only when this global's value is set to <code>1</code>:
Now we will wrap our code in <code>'''PlayerScript'''</code> with a condition to run only when this global's value is set to <code>1</code>:


<source lang="papyrus">Scriptname PlayerScript extends ReferenceAlias   
<syntaxhighlight lang="papyrus">Scriptname PlayerScript extends ReferenceAlias   


Spell Property CloakAbility Auto
Spell Property CloakAbility Auto
Line 286: Line 286:
RegisterForSingleUpdate(4)
RegisterForSingleUpdate(4)
EndEvent
EndEvent
</source>
</syntaxhighlight>
Don't forget to auto-fill the new '''GlobalVariable''' property on our <code>'''PlayerScript'''</code>.  Users now have the opportunity of pausing the cloak on their own with the console command  <code>set mymod_CloakEffectOn to 0</code>.  
Don't forget to auto-fill the new '''GlobalVariable''' property on our <code>'''PlayerScript'''</code>.  Users now have the opportunity of pausing the cloak on their own with the console command  <code>set mymod_CloakEffectOn to 0</code>.  


Line 326: Line 326:
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:


<source lang="papyrus">Scriptname TreeAliasScript extends ReferenceAlias
<syntaxhighlight lang="papyrus">Scriptname TreeAliasScript extends ReferenceAlias


Keyword Property WeapTypeBattleAxe Auto
Keyword Property WeapTypeBattleAxe Auto
Line 339: Line 339:
endif
endif
endif
endif
EndEvent</source>
EndEvent</syntaxhighlight>


Set the properties for the script.  Since the properties are named exactly the same as the editor IDs of what we want them to represent, just click the '''Auto-Fill All''' button to set all the values automatically.
Set the properties for the script.  Since the properties are named exactly the same as the editor IDs of what we want them to represent, just click the '''Auto-Fill All''' button to set all the values automatically.
Line 355: Line 355:
Attach this script to the quest:
Attach this script to the quest:


<source lang="papyrus">Scriptname UpdateQuestScript extends Quest   
<syntaxhighlight lang="papyrus">Scriptname UpdateQuestScript extends Quest   


Quest Property DASQuest Auto
Quest Property DASQuest Auto
Line 376: Line 376:
DASQuest.Start()
DASQuest.Start()
RegisterForSingleUpdate(5)
RegisterForSingleUpdate(5)
EndEvent</source>
EndEvent</syntaxhighlight>


Remember to set the value of the 'DASQuest' property to the '''DASQuest''' we created earlier.  Check to make sure that '''Start Game Enabled''' is checked in the '''Quest Data''' tab, then click OK to close the quest window.
Remember to set the value of the 'DASQuest' property to the '''DASQuest''' we created earlier.  Check to make sure that '''Start Game Enabled''' is checked in the '''Quest Data''' tab, then click OK to close the quest window.

Navigation menu