Complete Example Scripts: Difference between revisions

Jump to navigation Jump to search
imported>Evernewjoy
imported>Evernewjoy
Line 183: Line 183:
</source>
</source>


====To Make This Script Work====
===Good Usage of Properties to Make Scripts Compact===
This script should be attached to an item that the player has to pick up as part of a quest. When the player picks up the item for the first time, the quest's stage it set to a value specified by a parameter.


* Create an item for the player to pick up, and attach this script to that item
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.
* In the dialogue window for that item, right click on this script and select "Edit Properties". You need to specify:
 
** The associated quest (QuestToSet)
 
** The stage at which the quest should be set (StageToSet)
In the example below I was having to do two different things to about 30 different draugrs,
* Then just place your item in the world. When the player picks it up, the quest you specified will be set to the stage you specified.
 
* turn their AI on and make them visible
* 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.
 
 
In this example I only show 3 of the Draugrs I was modifying. ''Imagine it was 30 Draugrs and you can see why only setting the properties once and writing only one script would be a time-saver :)''
 
<source lang="papyrus">
Scriptname RamaJRDisableAndMakeInvis extends ObjectReference
 
ObjectReference property RamaJRFadeRockArcher001 auto
ObjectReference property RamaJRFadeRockArcher002 auto
ObjectReference property RamaJRFadeRockArcher003 auto
 
float alpha
 
 
;--- The Most Important Line ---
bool property enableBeasts auto
;-------------------------------
 
ObjectReference curBeast
 
Event onTriggerEnter(ObjectReference ObjRef)
 
if(ObjRef == game.getplayer())
 
  if (enableBeasts) ;if enableBeasts is true
                        ;make them visible
                        alpha = 1
                  else
                        ;make them invisible
                        alpha = 0
 
  curBeast = RamaJRFadeRockArcher001
  (curBeast as Actor).setAlpha(alpha)
  (curBeast as Actor).enableAI(enableBeasts)
 
  curBeast = RamaJRFadeRockArcher002
  (curBeast as Actor).setAlpha(alpha)
  (curBeast as Actor).enableAI(enableBeasts)
 
  curBeast = RamaJRFadeRockArcher003
  (curBeast as Actor).setAlpha(alpha)
  (curBeast as Actor).enableAI(enableBeast)
endif
endif
endEvent
 
 
</source>
 
So notice in the script above, I set the bool as a property value so I can decide with each instance where I run the script which way it should work.
 
 
* Incidentally this script is also a example of casting a variable to a certain type when needed, I cast the ObjectReference to a Actor so I can access the Actor-type functions
 
<source lang="papyrus">
ObjectReference curBeast
(curBeast as Actor).enableAI(true)
</source>
 
 
* I use curBeast for easy copy-pasting. You could use FormLists to do this process as well
 
 
====How to Make This Script Work====
 
* You will need to replace all names for the Draugr Archers (RamaJRFadeRockArcher001 for example) with the exact ID values of each of your chosen creatures.
 
* 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
 
 
Enjoy!
 
 
♥ and thanks to our friends at Bethesda for such an awesome Creation Kit!
Anonymous user

Navigation menu