Difference between revisions of "Death check with weapon script"

5,316 bytes added ,  04:52, 12 September 2010
m
(marked as unfinished)
imported>Spd1274
imported>Darkness X
m ((marked as unfinished))
 
(21 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Request Tutorial}}
{{unfinished}}
{{Tools|req0=[[The Elder Scrolls Construction Set|Construction Set]]}}== Introduction ==
 
In the process of working on a project that requires the Player to kill an NPC, and than adds an item upon the death of the NPC, and only an NPC, it became necessary to layout the steps for the project, and this seemed the best, and most helpful way to others, to do that.
 
This Tutorial will follow the steps below:<br />
1. Create a Magic Effect Script that will check for the death of an NPC at the Player's hand, than add an Item to the inventory with a nice little message. <br />
2. Create the item to be added, in this case, the soul of the NPC in the form of a bottled potion. From here on, called The Gift. <br />
3. Create a scripted enchantment that runs our script. To be called, The Ench (Because there is no way to activate a script when the Player hits an NPC i.e. Onstrike or anything of that kind. See: [[Begin|Beginning Scripts]]).<br />
4. Finally create, and place into Tamriel, the weapon that will execute the script. To be called, The Weapon.
 
Notes:<br />
It is assumed the reader has a prior basic knowledge of scripting, however, as it is most frustrating to see things work but not understand why, most work done here will be well explained.
 
Other Tutorials of possible relevance:
<br /> [[Deadcount on a weapon]].
 
So without further ado, "Get on with it!"
 
== The Script ==
 
[[Image:toolbarwscriptcircle.png|thumb|right|Script Editor Icon]]
To begin, we load the CS and than open the script editor by clicking on the [[Image:ScriptEditorIcon.png]] symbol.
Which is at the very end of the toolbar:<br />
 
 
Now that we have the editor open, here is our skeleton script:<br />
 
<PRE>
Scriptname Name
 
ref Target
 
short Dead
short Once
 
Begin ScriptEffectStart
set Target to GetSelf
if Target.GetDead == 1 && Target.GetIsPlayableRace == 1
  set Dead to 1
endif
set Once to 0
End
 
Begin GameMode
If Dead == 1 && Once == 0
  player.additem Item 1
  MessageBox "Message."
          set Once to 1
endif
End
</pre>
 
Now I understand that this seems quite alot to take in at first glance. However, lets break it down:
 
<PRE>
Scriptname Name
 
ref Target
 
short Dead
short Once
</pre>
 
Here we name our script, and give it the Script ID it will be saved and called by. <br />Than we create a reference, which in this case will point to the Target of the player, hence the name 'Target.' <br />
Than we list two shorts, which are variables this script can reference inside of itself, Dead and Once. Which we will see later.
 
<pre>
Begin ScriptEffectStart
set Target to GetSelf
if Target.GetDead == 1 && Target.GetIsPlayableRace == 1
  set Dead to 1
endif
set Once to 0
End
</pre>
 
This portion of the script does all the hard work. It begins as soon on ScriptEffectStart, which in the case of an enchantment, means it will begin with the Player strikes a creature.<br />
It tells our reference Target to find out what exactly it is, thus retrieving the data on the NPC or creature the Player is attacking.<br />
Than Target is tested if it is dead, and if it is a playable race, and therefore and NPC. (This excludes creatures such as Golden Saints, because there does not seem to be a NPC test in Vanilla CS.) If these tests both evaluate as true, the script sets the short Dead to 1 and than Once to 0, confirming a run of the script.
 
<pre>
Begin GameMode
if Dead == 1 && Once == 0
  player.additem Item 1
  messageBox "Message."
          set Once to 1
endif
End
</pre>
 
[[Image:scripttypepic.png|thumb|right|Script Type]]
Finally our script finishes up by running a test that Dead and Once have been set to the correct values for a killed NPC. <br /> Than the script adds an Item of our choice to the Player's inventory and displays a message.<br /> In order to avoid the script giving the Player the item over and over and over, the last action of the script is to set Once to 1, avoiding a loop.
 
 
Now, be sure to change to Script Type to: Magic Effect. Now click the Floppy Disk icon to save the script. Close the Script Editor.
 
 
This completes our creation of the script, it is all that simple. It needs to be said that the tests run under "ScriptEffectStart" must be run there, because that portion of the script is run while attacking the victim, and if those tests were run under "GameMode" the Player would no longer have a target to test.
 
So now, onto the The Gift.
 
== The Gift ==
 
In this case we are creating a potion so, we need to navigate to the Potion section of the CS Object Window. Click on Magic -> than Potion.
 
[[Image:thegiftpic.png|thumb|right|The Gift]]
 
We than need to select a potion inside the menu. I am choosing "TestPoison" because I like it's bottle image, double click on your choice. Now, you want to change the ID to something easily found, in this case: Item (in order to match our skeleton script). Next change the name of the potion Now, you can edit the properties of the potion if you'd like, but that is for another tutorial, and falls out of my hands.
 
Save the item, and close out of the dialogue box.
 
 
== The Ench ==
 
[[Image:ench.png|thumb|right|The Ench]]
The Ench is altogether to challenging, simply navigate to the Enchantment division by clicking Magic -> than Enchantment.
 
Right-Click inside the list of enchantments and select New.
 
Fill in with an appropriate ID, in this case: TheEnch. Choose "Weapon" as the Type.
 
 
 
[[Image:encheffect.png|thumb|right|The Ench Effect]]
 
 
 
 
Right click inside the data area, select New. You're now at the Enchantment Effect window.
 
 
The Effect field needs to be set to Script Effect so that we can apply our script. It will than default the Range to touch, this just means it will only affect those we hit with the weapon. The Duration and Magnitude remain zero because we are using a script and they are unnecessary.<br />
In the bottom half, we need to choose the Script Effect, "Name" in this case. Than we need to name the effect, I left it at the default. The School and Visual are purely aesthetics. You can choose a school if you please and a visual effect you find nice, I chose the Soul Trap effect. The tick box for hostility, doesn't need to be checked, but it is here out of habit, swinging a weapon at your opponent isn't exactly kind.
 
 
On to the Weapon!


== Introduction ==


I am currently working on a project that requires the Player to kill an NPC, and than adds an item upon the death of the NPC. Through much trial and error, I finally ran down how to achieve this. I intend to lay it out here, for those who might want to do something similar.
== The Weapon ==


So, in this tutorial, I will be guiding you in how to do several things:<br />
1. Create a Magic Effect Script that will check for the death of an NPC at the Player's hand, than add an Item to the inventory with a nice little message. <br />
2. Create the item to be added, in this case, the soul of the NPC in the form of a bottled potion.<br />
3. Create a scripted enchantment that runs our script. (Because there is no way to activate a script when the Player hits an NPC).<br />
4. Finally create, and place into Tamriel, the weapon that will execute the script.


There is a rather good Tutorial on the Wiki that got me started on my path in this project, thought I should give it a nod, [http://cs.elderscrolls.com/constwiki/index.php/Deadcount_on_a_weapon Deadcount on a weapon].
[[Category:Tutorials]]
[[Category:Scripting Tutorials]]
{{Request Tutorial}}
Anonymous user