Difference between revisions of "Scripting Tutorial: Spell Tome"
imported>Grosie |
imported>Grosie |
||
Line 38: | Line 38: | ||
if buttonpressed == 1 | if buttonpressed == 1 | ||
set button to GetButtonPressed | set button to GetButtonPressed | ||
if button == | if button == 1 | ||
set doonce to 0 | |||
set buttonpressed to 0 | |||
Message "Ok - Maybe you can learn later" | |||
elseif button == | elseif button == 0 | ||
set buttonpressed to 0 | set buttonpressed to 0 | ||
player.AddSpell StandardFrostDamageTarget1Novice | player.AddSpell StandardFrostDamageTarget1Novice | ||
Line 51: | Line 51: | ||
NB: The MessageBox Part should all be on one line - wiki formatting however prevents this. | NB: The MessageBox Part should all be on one line - wiki formatting however prevents this. | ||
===How the script works=== | |||
The first part names the script and declares the variables. | |||
<pre> | |||
scn aaaSpellTomeScript ;Script name, put near the top of alphabetical list | |||
short doonce ;Variable for executing the check only once | |||
short buttonpressed ;Has a button been pressed (should we check which one?) | |||
int button ;Which button has been pressed? | |||
</pre> | |||
The OnActivate block executes each time you open the book and asks you if you want the spell if you haven't already learnt it. | |||
<pre> | |||
begin onActivate | |||
if doonce == 0 ;has the player already learnt the spell? | |||
;ask the player if they would like the spell | |||
MessageBox "Would you like to learn the Spell of Frost Damage?", "Yes please", "No way, maybe later" | |||
set doonce to 1 ;Don't ask them again | |||
set buttonpressed to 1 ;tell the script to check what the player answered | |||
else | |||
;Tell the player that they have got the spell already. | |||
Message "You have already learn what you can from this Tome" | |||
endif | |||
end | |||
</pre> | |||
The GameMode Block excutes every frame, checking if a button has been pressed and responding if it has. | |||
<pre> | |||
begin GameMode | |||
if buttonpressed == 1 | |||
set button to GetButtonPressed ;find which button has been pressed | |||
if button == 1 ;has the player decided not to learn this spell? | |||
set doonce to 0 ;tell the script that we should ask the player again | |||
set buttonpressed to 0 ;tell it that we have finished checking buttons | |||
Message "Ok - Maybe you can learn later" ;confirm the player's choice to him/her | |||
elseif button == 0 ;has the player decided to learn the spell? | |||
set buttonpressed to 0 ;tell the script we have finished checking buttons | |||
player.AddSpell StandardFrostDamageTarget1Novice ;add the spell | |||
Message "Use this knowledge wisely" ; confirm the player's choice | |||
endif | |||
endif | |||
end | |||
</pre> | |||
''This article is currently being written, please do not change it yet!'' | ''This article is currently being written, please do not change it yet!'' |
Revision as of 11:59, 18 May 2009
This article has been marked by editors or authors as incomplete. Please see the Talk page for details. Discussion and collaboration can improve an article and lead to a better Wiki.
This tutorial will tell you how to create a Spell Tome (or a book that will add a spell to the player's inventory when the book is read). You will create a book, put some text into it, and add a script to it to give the player a spell. If you don't already know how to script anything, or are entirely new to the TES:CS then I suggest that you go and read another tutorial first, then come back here when you know the basic interface. An excellent tutorial for learning the scripting interface is Scripting Tutorial: My First Script.
With that in mind, let's get started!
Starting off
Open the TES:CS and load Oblivion.esm (and optionally whatever previous .esp file you want to add spell tomes to). If you are planning on creating a new plugin data file, go ahead and save it now, call it something like "SpellTomeTutorial". doing this now will avoid any possible crashes when trying to create a new data file later on after you have put in all the hard work putting this together.
Creating the Tome (Book)
Open the Object window and expand the 'Items' > 'Book' > 'Clutter' categories and click on 'Book'. Now select one of the books in the list (eg 'Book1CheapGuideAnvil'), 'right-click on it, and choose edit. Change the EditorID to something like 'aaaSpellTome' (So that it is easy to find a the top of the books list) and change the name to whatever you want. Also, while you are here, clear any text that is in the box on the right, and make sure that the book has no enchantment, teachings or script (at the moment) Click OK, and when asked if you want to create a new form, choose yes.
The Spell
You cannot create a spell tome without a spell. At this point you can either choose to use an existing spell that came with Oblivion or create a new one. I'm not going to tell you how to create a new spell here, but there are many resources to tell you how. Whichever mthod you choose, you need the editor ID for the spell. In this tutorial, I am going to use 'StandardFrostDamageTarget1Novice'
The Script
We now need to create the script that we will attach to our book to add the spell. So go ahead and open the scripting window and create a new script. Type this into the window and hit save (NOT THE COMPILE ALL BUTTON!) I will explain how it works in a moment.
scn aaaSpellTomeScript short doonce short buttonpressed int button begin onActivate if doonce == 0 MessageBox "Would you like to learn the Spell of Frost Damage?", "Yes please", "No way, maybe later" set doonce to 1 set buttonpressed to 1 else Message "You have already learn what you can from this Tome" endif end begin GameMode if buttonpressed == 1 set button to GetButtonPressed if button == 1 set doonce to 0 set buttonpressed to 0 Message "Ok - Maybe you can learn later" elseif button == 0 set buttonpressed to 0 player.AddSpell StandardFrostDamageTarget1Novice Message "Use this knowledge wisely" endif endif end
NB: The MessageBox Part should all be on one line - wiki formatting however prevents this.
How the script works
The first part names the script and declares the variables.
scn aaaSpellTomeScript ;Script name, put near the top of alphabetical list short doonce ;Variable for executing the check only once short buttonpressed ;Has a button been pressed (should we check which one?) int button ;Which button has been pressed?
The OnActivate block executes each time you open the book and asks you if you want the spell if you haven't already learnt it.
begin onActivate if doonce == 0 ;has the player already learnt the spell? ;ask the player if they would like the spell MessageBox "Would you like to learn the Spell of Frost Damage?", "Yes please", "No way, maybe later" set doonce to 1 ;Don't ask them again set buttonpressed to 1 ;tell the script to check what the player answered else ;Tell the player that they have got the spell already. Message "You have already learn what you can from this Tome" endif end
The GameMode Block excutes every frame, checking if a button has been pressed and responding if it has.
begin GameMode if buttonpressed == 1 set button to GetButtonPressed ;find which button has been pressed if button == 1 ;has the player decided not to learn this spell? set doonce to 0 ;tell the script that we should ask the player again set buttonpressed to 0 ;tell it that we have finished checking buttons Message "Ok - Maybe you can learn later" ;confirm the player's choice to him/her elseif button == 0 ;has the player decided to learn the spell? set buttonpressed to 0 ;tell the script we have finished checking buttons player.AddSpell StandardFrostDamageTarget1Novice ;add the spell Message "Use this knowledge wisely" ; confirm the player's choice endif endif end
This article is currently being written, please do not change it yet!