Difference between revisions of "Running Scripts On Arrows"

938 bytes added ,  19:02, 24 October 2006
some minor additions/clarifications
imported>Scruggs
(forgot gamemode block)
imported>Scruggs
(some minor additions/clarifications)
Line 118: Line 118:
end</pre>
end</pre>


Here, [[GetScale]] returns the player's height as a proportion of the default racial height of 128. For the default height, we want the trigger zone placed 115 units above the player's feet when standing, and 95 units above when sneaking. Then we modify the offset to account for the player's vertical facing.
Here, [[GetScale]] returns the player's height as a proportion of the default racial height of 128. For the default height, we want the trigger zone placed 115 units above the player's feet when standing, and 95 units above when sneaking. Then we modify the offset to account for the player's vertical facing. Note that it would be more efficient to do some of the scale calculations only once, when the game is first loaded, since that information is not likely to change.


Great, now we have a trigger zone glued to the player's location, capable of intercepting any arrows he fires. We can attach a demo script to the trigger zone itself to show how this works:
Great, now we have a trigger zone glued to the player's location, capable of intercepting any arrows he fires. We can attach a demo script to the trigger zone itself to show how this works:
Line 199: Line 199:
*If its coordinates all return 0, it has hit an actor and no longer exists in the gameworld.
*If its coordinates all return 0, it has hit an actor and no longer exists in the gameworld.


Using these guidelines, we can write a slightly more complicated script. This script Simply reports on the state of the arrow over the course of its flight. We use a doOnce variable '''triggered''' to make sure we only track one arrow at a time:
Using these guidelines, we can write a slightly more complicated script. This script simply reports on the state of the arrow over the course of its flight. We use a doOnce variable '''triggered''' to make sure we only track one arrow at a time:
<pre>
<pre>
scriptName acTrigZoneSummonSCR
scriptName acTrigZoneSummonSCR
Line 256: Line 256:


Admittedly, that script isn't terribly useful in itself, but it should give you a starting point in setting up your own scripts on arrows.
Admittedly, that script isn't terribly useful in itself, but it should give you a starting point in setting up your own scripts on arrows.
Bear in mind that if two scripts attempt to use this approach at the same time, they will conflict with each other. Therefore, it's a good idea to conditionalize things as specifically as possible. For instance, if you only need to detect a certain type of arrow, then you would enable the trigZone only while the player has that type of arrow equipped.
Also, you'll probably realize that the usefulness of trigger zones isn't limited to detecting arrows. For instance, by keeping a trigZone glued in front of the player at all times, you could detect what item or actor is in the crosshairs at any given moment, and perform actions on the target. I hope to find time to post some more tutorials on the uses of trigger zones, but in the meantime, have fun experimenting.
[[Category:Useful_Code]]
[[Category:Useful_Code]]
Anonymous user