Death check with weapon script
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.
Tools used in this tutorial
Required |
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:
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.
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.
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: Beginning Scripts).
4. Finally create, and place into Tamriel, the weapon that will execute the script. To be called, The Weapon.
Notes:
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:
Deadcount on a weapon.
So without further ado, "Get on with it!"
The Script[edit | edit source]
To begin, we load the CS and than open the script editor by clicking on the File:ScriptEditorIcon.png symbol.
Which is at the very end of the toolbar:
Now that we have the editor open, here is our skeleton script:
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
Now I understand that this seems quite alot to take in at first glance. However, lets break it down:
Scriptname Name ref Target short Dead short Once
Here we name our script, and give it the Script ID it will be saved and called by.
Than we create a reference, which in this case will point to the Target of the player, hence the name 'Target.'
Than we list two shorts, which are variables this script can reference inside of itself, Dead and Once. Which we will see later.
Begin ScriptEffectStart set Target to GetSelf if Target.GetDead == 1 && Target.GetIsPlayableRace == 1 set Dead to 1 endif set Once to 0 End
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.
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.
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.
Begin GameMode if Dead == 1 && Once == 0 player.additem Item 1 messageBox "Message." set Once to 1 endif End
Finally our script finishes up by running a test that Dead and Once have been set to the correct values for a killed NPC.
Than the script adds an Item of our choice to the Player's inventory and displays a message.
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[edit | edit source]
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.
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[edit | edit source]
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.
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.
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!