Difference between revisions of "Death check with weapon script"

1,789 bytes added ,  15:42, 13 August 2010
Writing the Article
imported>Spd1274
imported>Spd1274
(Writing the Article)
Line 28: Line 28:
Now that we have the editor open, here is our skeleton script:<br />
Now that we have the editor open, here is our skeleton script:<br />


<PRE>scn SDsoulreavescript
<PRE>scriptname Name


ref Target
ref Target
Line 45: Line 45:
Begin GameMode
Begin GameMode
If Dead == 1 && Once == 0  
If Dead == 1 && Once == 0  
  player.additem SDreavedsoul 1
  player.additem Item 1
  MessageBox "You have killed your victim, and claimed their soul."
  MessageBox "Message."
           set Once to 1
           set Once to 1
endif
endif
end</pre>
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>
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.
Anonymous user