Difference between revisions of "A beginner's guide, lesson 7 - Using Scripts in Quests"

Jump to navigation Jump to search
→‎Imperial City Phase Two: Fixing example script
imported>Pyrocow2
(→‎Imperial City Phase Two: Editing some English)
imported>Pyrocow2
(→‎Imperial City Phase Two: Fixing example script)
Line 995: Line 995:
  ''I have met with Vilanus Villa again. He has taken the deed to Top View and will complete the registration. I should come back in 24 hours to complete the transfer.''
  ''I have met with Vilanus Villa again. He has taken the deed to Top View and will complete the registration. I should come back in 24 hours to complete the transfer.''


We want to set up a delay of one day before we can collect the finished documents. This gives us an excellent opportunity to look at and practice timers
We want to set up a delay of one day before we can collect the finished documents. This gives us an excellent opportunity to look at and practice timers.


===Timers===
===Timers===
Line 1,001: Line 1,001:
Timers are another bit of scripting that gets used again and again. The game uses a number of global variables to report the progress of time.  
Timers are another bit of scripting that gets used again and again. The game uses a number of global variables to report the progress of time.  


The two most used are
The two most used are:


GetSecondsPassed  
*[[GetSecondsPassed]]
GameDaysPassed  
*[[GameDaysPassed]]


We can use the seconds passed to establish timed events. We must use a float variable to interact with the GetSecondsPassed function.  
We can use the seconds passed to establish timed events. GetSecondsPassed returns a float value, so we must set up a float type variable to save it in.


Ok this example script is really pointless it takes 10 septims from the player, then gives them back 25 seconds later.
Here is an example script that takes 10 Septims from the player and then gives them back 25 seconds later.  
However, the structure is what counts.  


If you change the bits in bold to suit your needs, you will have a perfectly functional timer script.
<pre>
 
Scriptname ExampleTimerScript
The Remove function can be replaced with any script you want to run prior to the countdown.
 
The 25 controls how long the script will run for.
 
The Add function can be replaced by whatever you want to happen after the event.
 
<pre>Scriptname ExampleTimerScript


float Timer
float Timer
short DoOnce
short State


Begin GameMode
Begin GameMode
   If SetZero == 0  
   If State == 0  
     Set Timer to 25
     Set Timer to 25.0
     Set DoOnce to 1
     Set State to 1
     Player.RemoveItem ‘gold001’ 10
     Player.RemoveItem "gold001" 10
   Else
   ElseIf State == 1
     If Timer > 0
     If Timer > 0
       Set Timer to Timer - GetSecondsPassed
       Set Timer to Timer - GetSecondsPassed
     Else
     Else
       Player.AddItem ‘gold001’ 10
       Player.AddItem "gold001" 10
      Set State to 2
     EndIf
     EndIf
   EndIf
   EndIf


End</pre>
End
</pre>


When you plan to script longer events where precision is not essential you can use the courser GameDaysPassed function.  
If you're writing a script where you're only interested in the number of in-game days that have passed, you can use GameDaysPassed instead.


In the quest script we add some variables called StartDay, Timer, and DeedDone.
In the quest script we add some variables called StartDay, Timer, and DeedDone.
Anonymous user

Navigation menu