Difference between revisions of "Death check with weapon script"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>Spd1274
imported>Spd1274
Line 104: Line 104:
[[Image:thegiftpic.png]]
[[Image:thegiftpic.png]]


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 matche our skeleton script). 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.  
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.
Save the item, and close out of the dialogue box.

Revision as of 20:34, 13 August 2010


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

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:
File:Toolbarwscriptcircle.png

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, let's save our script, by clicking on the Floppy Disk icon, and close the window.

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. Click on Magic -> than Potion.

File:Thegiftpic.png

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

The Ench is altogether to challenging, simply navigate to the Enchantment division by clicking Step -> than step -> and than Step.

Right-Click inside the list of enchantments and select New.

Fill in with an appropriate ID, in this case: TheEnch

Work in Progress