Global Scripts

If you're used to scripting in The Elder Scrolls III: Morrowind, you may be familiar with a concept known as "global scripts". In Morrowind, the way to run a global script — at least if you have the Tribunal or Bloodmoon expansions, or if you have the Morrowind Game of the Year Edition — is to create your script as normal, then specify it is a Start Script in the Construction Set.

In Oblivion, however, all scripts must be attached to objects of some kind. This, of course, presents a problem: how can an object, which must be always be persistent in memory and running its script, be created? The answer, of course, is by creating a quest, then defining your script as a quest script.


What is a Global or a Quest script?Edit

A Global script ( which will be called as Quest script from this point onwards )is a script that needs to be running all the time in order to perform advanced scripting techniques. The actual uses for this vary a great deal, but reasons include: alterations of the locations of objects above and beyond the Havok physics engine; dynamic placement of creatures and objects; and modifications of NPCs on a grand scale (for instance, making every single NPC in the game burst into flames...).

Quest scripts can be designed to run immediately, from the very start of the game. This is distinct from some of the scripts on, for example, side quests. Those scripts are triggered and executed only while the quest is in play.

Quest scripts can be created by selecting Quest script type in the script editing window. They must be designated as quest scripts in order to be attached to quests.

A few basic facts about quest scripts and their interaction with quests :

  • Quest scripts run only when the quest is running (which can be determined in-game by using sqv QUEST_NAME in the Console). Quests can be started and stopped using the StartQuest and StopQuest script commands. Note that this is independent of a quest being complete or not. Completing a quest means that it is moved to the Completed Quest tab in the player's journal -- It will still be running unless a StopQuest command is used to turn it off.
  • The rate at which a Quest script is processed can be changed by defining the fQuestDelayTime variable of the script. Each Quest can have its own fQuestDelayTime variable.
    • The fQuestDelayTime variable of a particular Quest script may be set from another script by addressing the quest, e.g. set MyQuest.fQuestDelayTime to 0.01.
    • Since quest scripts run based on time intervals, they will not necessarily frame sync, even when fQuestDelayTime is set to a very low value. For some effects (e.g. those using SetPos), this can have undesired effects. In such cases, Object or/and Magic scripts may be more appropriate to achieve an effect smoothly.
  • Quest scripts are non-reference scripts and are therefore somewhat restricted in the function syntax they can use.
  • Quest scripts are the only scripts which actually process a MenuMode block while the player is resting or using fast travel.
  • In general, quests should be stopped when they are completed, in order to keep their scripts from processing. If there is need to keep a completed quest running (for some post-quest dialogue or script processing), the task of creating a second quest can be considered.
  • Quest variables can still be accessed and modified when a quest is not running. When a quest is stopped, it's script will stop being processed, but it will still exist and the state of it's variables will remain intact.
  • Quests automatically turn on when an entry is written to the player's journal. So if the line SetStage QUESTNAME 10 is executed and the entry 10 has journal text, the corresponding Quest will start automatically.

Should I use a Quest script?Edit

If you have to ask, then the answer is a very emphatic no!

Quest scripts are inefficient and are not the recommended solution to most problems. However, if the creation of a quest script is necessary, the scope of the script should be reduced to prevent the wastage of CPU cycles.

For example : If your script only affects Actors inside a certain inn, you could easily get the job done by using an Activator, with a script attached to it, and placing it inside each cell of that inn or include provisions in your quest script to stop it's processing once the job is done.

Creating a Quest script:Edit

Create a QuestEdit

Before you can write your script, you need to create a quest to attach a script to. This is done by selecting "Character"->"Quests" from the menu at the top of the Construction Set. Once you are presented with the Quests dialog, move over to the white list on the left-hand side of the box. Under the "Editor ID" column button, right-click and choose "New" to create a new Quest. You are prompted for a name for your quest. Type in a good name and click OK.

After you have a quest ready, move over to the "Script" selection box, and click the button marked "..." in order to open the Script Editor.

Create your ScriptEdit

This is a simple matter of programming. Refer to the Scripting category for all of the necessary information. You will also want to define float fQuestDelayTime inside your script. Set it to a low value (e.g., set fQuestDelayTime to 0.001) in order to have your script process every frame.

Once you have finished the meat of your script, go to the toolbar of the Script Editor dialog and select "Quest" from the Script Type drop-down list. You are ready to assign the script to the quest! Close the Script Editor now, and save your script if it prompts you. Be sure to correct any errors if they come up.

Sample Global Script FormatEdit

scriptname YourScriptNameGoesHere

;If this variable is defined, we can custom-tune how fast Oblivion
; will process this Quest script.  If you have a global script that
; needs precision, it is important to define this.
float fQuestDelayTime

;Any other script variables you'll need go here.
;***SCRIPT VARIABLES***


begin GameMode
    ;Conditions which should prevent this script from running go here.
    ; Use the "if ( condition )" command and then the "return" command.
    ;***CANCEL CONDITIONS***
    
    ;This specifies that we want this script to process every millisecond.
    ; Since no computer can run Oblivion at 1000 frames per second, this
    ; means that you want it to execute once every frame (usually quite a
    ; bit longer than 1 millisecond).
    ;Change this value as necessary to change the precision of your
    ; script.  Bear in mind that the fastest it can run is once per frame.
    set fQuestDelayTime to 0.001
    
    ;The actual meat of your script goes here.
    ;***SCRIPT CONTENTS***

end GameMode

Assign your Script to the QuestEdit

Now that you are finished your script, the script can be attached to the quest. Simply select your new script from the "Script" dropdown list in the Quest dialog, and choose "OK" in the far bottom right corner of the Quest dialog.

Congratulations! You now have a global script.

See AlsoEdit