Complete Example Scripts: Difference between revisions

Jump to navigation Jump to search
m
→‎Cycle Through a List of Objects and Perform an Action on Each Object(FormLists): Condensed to prevent carpel tunnel/standardized capitalization for legibility
imported>JustinOther
imported>JustinOther
m (→‎Cycle Through a List of Objects and Perform an Action on Each Object(FormLists): Condensed to prevent carpel tunnel/standardized capitalization for legibility)
Line 124: Line 124:


===Cycle Through a List of Objects and Perform an Action on Each Object(FormLists)===
===Cycle Through a List of Objects and Perform an Action on Each Object(FormLists)===
This example script cycles through a List of objects, known as a [[Formlist]], and enables them all if they are disabled, and disables them if they are enabled, each time the player character walks through a chosen trigger volume.  
This example script cycles through a List of objects, known as a [[Formlist]], and enables them all if they are disabled, and disables them if they are enabled, each time the player character walks through a chosen trigger volume.  
If you use a [[Formlist]] of special effects, this would cause all the many special effects you have in the formlist to disappear or reappear each time you walk through the trigger volume.
If you use a [[Formlist]] of special effects, this would cause all the many special effects you have in the formlist to disappear or reappear each time you walk through the trigger volume.
<source lang="papyrus">ScriptName RamaFormListExampleScript extends ObjectReference


<source lang="papyrus">
Int iCurIndex
 
Int iTotal
Scriptname RamaFormListExampleScript extends ObjectReference 
FormList Property ListOfObjectsFLST Auto ; see notes after script for more info on this property
 
ObjectReference akReference
;-------- Properties
 
;--- see notes after script for more info on this property
 
FormLIST property listOfObjectsFORMLIST auto
 
;-------- Vars
 
ObjectReference curRef
int curIndex
int total
 
;--------
 
Event onTriggerEnter(ObjectReference objRef)


if(objRef == game.getplayer())
Event onTriggerEnter(ObjectReference akActionRef)
If akActionRef == Game.GetPlayer())
;--- test index 0 entry to see if all are enabled or disabled
akReference = ListOfObjectsFLST.GetAt(0) as ObjectReference ; I use ObjectReference so that IsEnabled() becomes accessible. Use Actor if you want to perform actor functions and the formlist contains actors.
iTotal = ListOfObjectsFLST.GetSize() ; Initialize
;--- Note that you must typecast the entry from the formlist using "as."
iCurIndex = 0 ; test index 0 entry to see if all are enabled or disabled
        ;--- I use ObjectReference so that .isEnabled() becomes accessible.  
If akReference.IsEnabled()
        ;--- Use Actor if you want to perform actor functions and the formlist contains actors.
While(iCurIndex < iTotal)
 
akReference = ListOfObjectsFLST.GetAt(curIndex) as ObjectReference ; Note that you must typecast the entry from the formlist using "as."
curRef = (listOfObjectsFORMLIST.getat(0) as ObjectReference)
akReference.Disable()
 
iCurIndex += 1
;---------------------- Initialize ---------------------
EndWhile
total = listOfObjectsFORMLIST.GetSize()
Else
curIndex = 0
While(curIndex < iTotal)
;-------------------------------------------------------
akReference = ListOfObjectsFLST.GetAt(curIndex) as ObjectReference  
 
akReference.Enable()
if(curRef.isEnabled())
 
while(curIndex < total)
curRef = (listOfObjectsFORMLIST.getat(curIndex) as ObjectReference)
curRef.disable()
curIndex += 1  
curIndex += 1  
endWhile
EndWhile
 
EndIf
else
EndIf
 
EndEvent</source>
while(curIndex < total)
curRef = (listOfObjectsFORMLIST.getat(curIndex) as ObjectReference)
curRef.enable()
curIndex += 1
endWhile
 
endif
 
;--------------
 
 
endif
 
endEvent
</source>
 
 
'''To Make This Script Work'''
'''To Make This Script Work'''
 
* This script runs on a OnTriggerEnter event, so you must create a trigger volume. See the [[Complete_Example_Scripts#A_Trigger_That_Detects_When_The_Player_Enters|script example above]] for details on this.
 
* This script runs on a onTriggerEnter event, so you must create a trigger volume. See the [[Complete_Example_Scripts#A_Trigger_That_Detects_When_The_Player_Enters|script example above]] for details on this.
 
 
* Remember to add this example script to the trigger volume object that you create, so you have an actual instance of this script in your level.
* Remember to add this example script to the trigger volume object that you create, so you have an actual instance of this script in your level.
* You must create a formlist of the objects you want to cycle through in this script example.  
* You must create a formlist of the objects you want to cycle through in this script example.  
[[Image:Formlist_making_a_formlist_and_populating_it.jpg]]
[[Image:Formlist_making_a_formlist_and_populating_it.jpg]]


1. Go to the miscellaneous section of the Object Window and click on formlists,  
1. Go to the miscellaneous section of the Object Window and click on FormLists,  
 
2. then right click to make a new FormList
 
2. then right click to make a new formlist
 
 
3. In your cell view, hold shift and select all of the forms you want to add to the formlist, these could be actors or special effects, activators, or any other kind of form. Name all the forms you want to include from your cell in a similar way so they can be easily selected as a group using shift.
3. In your cell view, hold shift and select all of the forms you want to add to the formlist, these could be actors or special effects, activators, or any other kind of form. Name all the forms you want to include from your cell in a similar way so they can be easily selected as a group using shift.
4. Drag the selected forms into the window containing your new formlist information.
4. Drag the selected forms into the window containing your new formlist information.
5. Make sure to only add forms to your formlist that are all of the same type. Do not mix actors and activators for example.
5. Make sure to only add forms to your formlist that are all of the same type. Do not mix actors and activators for example.
* Now you must modify the property of this script example instance, which is present on your trigger volume.  
* Now you must modify the property of this script example instance, which is present on your trigger volume.  
Edit the property so that it points to EditorID of your formlist that you just created.
Edit the property so that it points to EditorID of your formlist that you just created.
* For this script example, I was simply enabling or disabling the objects in the list, so make sure that your formlist contains forms that will react when you enable/disable them. Actors or special effects (look up FX in the *All section of the Object Window) are good forms to start with.
* For this script example, I was simply enabling or disabling the objects in the list, so make sure that your formlist contains forms that will react when you enable/disable them. Actors or special effects (look up FX in the *All section of the Object Window) are good forms to start with.
'''Uses:'''
'''Uses:'''
* Any time you have a long list of script properties you want to perform an action on, you can make a formlist instead, and use the while loop to make your coding life Heavenly.
* Any time you have a long list of script properties you want to perform an action on, you can make a formlist instead, and use the while loop to make your coding life Heavenly.
* Systematically add a certain amount of health or other characteristic to 10 or 2000 actors / creatures to make then stronger or weaker or give them a certain skill (use setAV actor function)
* Systematically add a certain amount of health or other characteristic to 10 or 2000 actors / creatures to make then stronger or weaker or give them a certain skill (use setAV actor function)
* Use enable/disable to make a whole bunch of special effect objects (they start with FX in editor) appear or disappear
* Use enable/disable to make a whole bunch of special effect objects (they start with FX in editor) appear or disappear
Enjoy!
Enjoy!


Anonymous user

Navigation menu