Complete Example Scripts: Difference between revisions
Jump to navigation
Jump to search
→Good Usage of Properties to Make Scripts Compact: ' Good Usage of Properties to Make Scripts Compact' compacted.
imported>JustinOther m (→Show Gift Window and Identify Items Given: 'Self' unnecessary. RemoveItem called implicitly) |
imported>JustinOther (→Good Usage of Properties to Make Scripts Compact: ' Good Usage of Properties to Make Scripts Compact' compacted.) |
||
| Line 317: | Line 317: | ||
= | =Usage of Arrays to Make Scripts Compact= | ||
In this example you can see how to use a simple script property to reduce the number of scripts you need to write and thus the amount of properties you need to set, which can be time-consuming. Below I was having to do things to things to about 30 different draugrs: | |||
In this example you can see how to use a simple script property to reduce the number of scripts you need to write and thus the amount of properties you need to set, which can be time-consuming. | |||
* turn their AI on and make them visible | * turn their AI on and make them visible | ||
* turn their AI off and make them invisible | * turn their AI off and make them invisible | ||
I have different conditions within my level for when each of these two actions should occur. I could divide this into two scripts, but instead I wrote one script and passed a property to the script with each instance of the script to determine which aspect of the script would run. | |||
<source lang="papyrus">Actor[] Property DraugrArray Auto ; Contains 30 elements filled in CK with the 30 Draugr | |||
Bool Property bEnableBeasts Auto ; Can be set from another script and/or initialized true or false | |||
Event OnTriggerEnter(ObjectReference akActionRef) | |||
If akActionRef == Game.GetPlayer() | |||
Int iIndex = DraugrArray.Length ; Will return 30 | |||
While iIndex > 0 | |||
iIndex -= 1 ; 29'th element is 30'th Draugr | |||
Actor rDraugr = DraugrArray[iIndex] | |||
rDraugr.EnableAI(bEnableBeasts) | |||
rDraugr.SetAlpha(bEnableBeasts As Float) | |||
EndWhile | |||
EndIf | |||
EndEvent</source> | |||
Note that bEnableBeasts is a property so one can decide with each instance which way the script should work. One could use a FormList rather than an array or simply set one Draurg as the enable parent of the other 29 and enable/disable him, thus all the children refs simultaneously. | |||
Event | |||
; | |||
EndEvent | |||
</source> | |||
'''How to Make This Script Work''' | '''How to Make This Script Work''' | ||
* You will need to fill the array elements in the Creation Kit with the chosen creatures. | |||
* You will need to | * Then you will need to chose for each instance of the script whether the boolean property should be false or true, this setting process shows up a simple checkmark box in the editor. | ||
* Then you will need to chose for each instance of the script whether the boolean property should be false or true, this setting process shows up a simple checkmark box in the editor | |||
= A helper script with functions to get the current moonphase, sync between the two moons and day of the week = | = A helper script with functions to get the current moonphase, sync between the two moons and day of the week = | ||