Difference between revisions of "Adding Working Scripts to Items"
imported>Mr6 (Created page with "Category:Tutorials Category:Community Tutorials ===What it does:=== This tutorial will go step-by-step to adding a simple script to an item-- gloves that grant you th...") |
imported>Mr6 |
||
Line 12: | Line 12: | ||
===Writing the script=== | ===Writing the script=== | ||
Now that the easy part is done, we will move on to the difficult part. From Gameplay at the top select Papyrus Script Manager, right click on a script and select New. You will be greeted with a dialogue box. | Now that the easy part is done, we will move on to the difficult part. From Gameplay at the top select [[Papyrus Script Manager]], right click on a script and select New. You will be greeted with a dialogue box. | ||
[[File:AddingScriptsToItems-NewScript.jpg|200px|thumb|none|alt=Container window settings|Create a Script]] | [[File:AddingScriptsToItems-NewScript.jpg|200px|thumb|none|alt=Container window settings|Create a Script]] | ||
Because it's an item, it must extend ObjectReference because OnEquipped is an ObjectReference Script. | Because it's an item, it must extend [[ObjectReference_Script|ObjectReference]] because [[OnEquipped_-_ObjectReference|OnEquipped]] is an ObjectReference Script. | ||
Now we can simply just write out our script and save it. | Now we can simply just write out our script and save it. | ||
Line 25: | Line 25: | ||
</source> | </source> | ||
In order to use things like AddSpell and AddItem, you have to make a property for them in your script. If not you will get an "Undefined variable" error. | In order to use things like [[AddSpell]] and [[AddItem]], you have to make a [[Variables_and_Properties|property]] for them in your script. If not you will get an "Undefined variable" error. | ||
<source lang="papyrus"> | <source lang="papyrus"> |
Revision as of 10:45, 21 February 2012
What it does:
This tutorial will go step-by-step to adding a simple script to an item-- gloves that grant you the Blizzard spell while wearing them.
Create the item
First, you want to create the gloves. Let's say our gloves are Elven Gauntlets of Thalmor origin. The fields I edited are highlighted in red.
Writing the script
Now that the easy part is done, we will move on to the difficult part. From Gameplay at the top select Papyrus Script Manager, right click on a script and select New. You will be greeted with a dialogue box.
Because it's an item, it must extend ObjectReference because OnEquipped is an ObjectReference Script. Now we can simply just write out our script and save it.
This is the scriptname:
Scriptname tutGlovesofBlizzardScript extends ObjectReference
{OnEquip adds a spell}
In order to use things like AddSpell and AddItem, you have to make a property for them in your script. If not you will get an "Undefined variable" error.
Spell Property Blizzard auto
This is our ObjectReference.OnEquipped event. It is important you extend it by ObjectReference in the Scriptname, or else this will not compile properly saying it is "not a valid or non existent function".
Event OnEquipped(Actor akActor)
if akActor == Game.GetPlayer()
Game.GetPlayer().AddSpell(Blizzard, true)
endIf
endEvent
This is simply just another event using the same property to remove the spell when the player unequipped it. We only want them to have the spell if they wear it.
Event OnUnequipped(Actor akActor)
if akActor == Game.GetPlayer()
Game.GetPlayer().RemoveSpell(Blizzard)
endIf
endEvent
So now that our script is finished, we can save it. Hopefully yours compiles as flawlessly as this example.
Attaching the Script
Now, we go back to our gloves, and add the script, edit the property and select the spell that will stand in for the Blizzard property.
Testing In Game
Now we can test them. I added the gloves in to the game by allowing the players to combine normal elven gauntlets with Frost Salts at the Forge. You can use any method you want to put them in the game. Everything looks good on the gauntlets so far, and when we equip them our script runs successfully.
This concludes the tutorial, and I hope it helped people avoid a lot of frustration.