Difference between revisions of "Scripting Tutorial: Spell Tome"

3,096 bytes added ,  15:24, 6 February 2011
imported>Grosie
m (→‎Putting it all together: spelling correction)
imported>IronSpine
 
(8 intermediate revisions by 5 users not shown)
Line 2: Line 2:


With that in mind, let's get started!
With that in mind, let's get started!
{{Tools|req0=[[The Elder Scrolls Construction Set|Construction Set]]}}


==Starting off==
==Starting off==
Line 29: Line 30:
       set buttonpressed to 1
       set buttonpressed to 1
   else
   else
       Message "You have already learn what you can from this Tome"
       Message "You have already learned what you can from this Tome"
   endif
   endif
end
end
Line 70: Line 71:
   else
   else
       ;Tell the player that they have got the spell already.
       ;Tell the player that they have got the spell already.
       Message "You have already learn what you can from this Tome"
       Message "You have already learned what you can from this Tome"
   endif
   endif
end
end
Line 112: Line 113:
==Extra==
==Extra==
===Problems===
===Problems===
The [[GameMode]] block will not execute when the menus are opened. The best way around it would be to automatically give the player the spell (as the [[OnActivate]] block does run in menus), however, I wanted to show how to use a [[MessageBox]] in this context.
The [[GameMode]] block will not execute when the menus are opened. The best way around it would be to automatically give the player the spell (as the [[OnActivate]] block does run in menus), however, I wanted to show how to use a [[MessageBox]] in this context. You could instead use the [[MenuMode]] Blocktype, which does run in menus (hence the name) - simple replace:
begin GameMode
with:
begin MenuMode


The script doesn't take into account whether the player has the spell already or not, this could be changed by instead of using the 'doonce' variable, checking if the player has the spell.
The script doesn't take into account whether the player has the spell already or not, this could be changed by instead of using the 'doonce' variable, checking if the player has the spell.
==Book==
If you want the book to open so you can read it, it's simple enough just type Activate after the OnActivate
<pre>
begin onActivate
  Activate
  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 learned what you can from this Tome"
  endif
end
</pre>
Now you will be able to read the book.


===Homework===
===Homework===
A similar method can be used on a scroll, using a scripted enchantment instead. This also has the benefit of ensuring that the addition can only be made once.
A similar method can be used on a scroll, using a scripted enchantment instead. This also has the benefit of ensuring that the addition can only be made once.
----
==IronSpine Supplemental - If the script doesn't work?==
I precisely followed the instructions of this tutorial, however (for me) the script never triggered. This was not resolved regardless of mode or other minor changes I made trying to figure out why it didn't.
I examined the script of a DLC Tome for comparison. Using that as a template along with the information here I immediately had a successful custom Tome of Alliance with custom spell, in my case a powerful multi-effect spell to cast on friendly NPC for 5min of prolonged assistance in battle.
Use the content of the tutorial and if your script doesn't seem to execute (as mine did not), use the following as a template and see if it starts working.
<pre>
scn AMLLSpellTomeOfAlliance
short buttonPressed
short isDone
Begin OnEquip Player
If isDone == 0
  MessageBox "(OnEquip Block) - Would you learn the ways of the Alliance?", "I would.", "No, I would not."
EndIf
End
Begin OnActivate
Activate
If isActionRef Player == 1 && isDone == 0
  MessageBox "(OnActivate Block) - Would you learn the ways of the Alliance?", "I would.", "No, I would not."
EndIf
End
Begin MenuMode
Set buttonPressed to GetButtonPressed
If buttonPressed > -1
  If buttonPressed == 0
  ;Add to SpellBook.
  Player.AddSpell AMLLAlliedDefenderMinorSpell
  PlaySound SPLAlterationCast
  Set isDone to 1
  EndIf
EndIf
End</pre>
In my case (and perhaps yours) it's '''OnEquip''' that triggers, not '''OnActivate'''. This is confirmed by the block prefix I added so I could see which is actually being triggered.
Based on my testing, this executes as wanted. Once Yes is selected, subsequent reading of the Tome is just that. Reading. Also, dropping the Tome and picking it back up just yeilds a standard auto read, with take option, and back in inventory just normal reading.
Note the scripts don't appear case-sensitive generally so it's up to you, but for easier reading out of habbit I use Pascal Casing due to my background.
Thanks to the original author of this article for the general knowledge. Tomes open up a hugely interesting way to add true custom spells to the game in a way that feels right and perfectly fits in with the mechanics. Instead of simply using a code to get the object you can of course go stuff it into a bookshelf, chest or anything else and "go get it properly" in-game ''':)'''
- IronSpine
----


[[Category:Tutorials]]
[[Category:Tutorials]]
[[Category:Scripting Tutorials]]
[[Category:Scripting Tutorials]]
Anonymous user