Complete Example Scripts: Difference between revisions

Jump to navigation Jump to search
imported>Jog
(Mess-o-headers)
imported>Evernewjoy
Line 54: Line 54:
* Non-player triggers can be used by changing the == to a != in the script above, to do things to other actors like restoring their health or moving them around (but not affecting player if player walks through the trigger)
* Non-player triggers can be used by changing the == to a != in the script above, to do things to other actors like restoring their health or moving them around (but not affecting player if player walks through the trigger)


===Cycle Through an Array of Objects and Perform an Action on each Object===
This example script cycles through an array 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.
<source lang="papyrus">
Scriptname RamaFormListExampleScript extends ObjectReference 
;-------- 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())
;--- test index 0 entry to see if all are enabled or disabled
;--- Note that you must typecast the entry from the formlist using "as."
        ;--- I use ObjectReference so that .isEnabled() becomes accessible.
        ;--- Use Actor if you want to perform actor functions and the formlist contains actors.
curRef = (listOfObjectsFORMLIST.getat(0) as ObjectReference)
;---------------------- Initialize ---------------------
total = listOfObjectsFORMLIST.GetSize()
curIndex = 0
;-------------------------------------------------------
if(curRef.isEnabled())
while(curIndex < total)
curRef = (listOfObjectsFORMLIST.getat(curIndex) as ObjectReference)
curRef.disable()
curIndex += 1
endWhile
else
while(curIndex < total)
curRef = (listOfObjectsFORMLIST.getat(curIndex) as ObjectReference)
curRef.enable()
curIndex += 1
endWhile
endif
;--------------
endif
endEvent
</source>
'''To Make This Script Work'''
* This script runs on a onTriggerEnter event, so you must create a trigger volume. See the script example above for details on this.
* You must create a formlist of the objects you want to cycle through in this script example.
1. Go to the miscellaneous section of the Object Window and click on formlists,
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.
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.
* Now you must modify the property of this script example to point to your formlist that you just created, so that the script is actually aware of your formlist property.
* 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:'''
* 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)
* Use enable/disable to make a whole bunch of special effect objects (they start with FX in editor) appear or disappear
Enjoy!


===Move an Object to a Specific Location Without Fade===
===Move an Object to a Specific Location Without Fade===
Anonymous user

Navigation menu