Complete Example Scripts: Difference between revisions

Jump to navigation Jump to search
no edit summary
imported>Fg109
m (fixed while loop in new example script)
imported>RedwoodElf
No edit summary
Line 612: Line 612:
*Put it to your "Data/Scripts/Source" Folder and compile.
*Put it to your "Data/Scripts/Source" Folder and compile.
*Call it's functions in other scripts either by import and call by function name or by using ExtendedUtility.<FunctionName>()
*Call it's functions in other scripts either by import and call by function name or by using ExtendedUtility.<FunctionName>()
=== Script to make an item cast a spell ===
<Source lang="Papyrus">
Scriptname SpellZapScript extends ObjectReference 
import Utility
Float Property xOffset  Auto 
{Relative X position for the target}
Float Property yOffset  Auto 
{Y Offset for Target}
Float Property zOffset  Auto 
{Z offset for Target}
Float Property RandomOffsetX = 0.0 Auto
{Randomness applied to X Offset}
Float Property RandomOffsetY = 0.0 Auto
{Randomness applied to Y Offset}
Float Property RandomOffsetZ = 0.0 Auto
{Randomness applied to Z Offset}
Float Property PulseRate = 1.0 Auto 
{How often do we shoot?}
Float Property RandomRate = 0.0 Auto
{Add random delay to pulse rate, capped at this value}
Activator Property TargetType  Auto 
{What type of object are we zapping if we're spawning a node?}
ObjectReference Property CurrentTarget  Auto 
{The actual target we're shooting at}
Bool Property SpawnNode  Auto 
{Do we spawn a target? If not, zap the nearest valid target.}
Spell Property Zap Auto
{What spell shall we use for the effect?}
FormList Property TargetTypeList Auto
{List of potential targets}
Float Property SeekRange = 1000.0 Auto
{The range it will "Lock into" a target if not making a node.}
Event OnInit()
    if SpawnNode && !CurrentTarget
        CurrentTarget = PlaceAtme(TargetType,1)
        CurrentTarget.MoveTo(Self,XOffSet,YOffSet,ZOffSet)
    endif
    RegisterForSingleUpdate(PulseRate)
EndEvent
Event OnUpdate()
    if !SpawnNode
        CurrentTarget = Game.FindClosestReferenceOfAnyTypeInListfromRef(TargetTypeList,Self,SeekRange)
; find something nearby to shoot at if we're not making our own target.
if !TargetTypeList && GetDistance(Player) < SeekRange ; No list given, Default to the player.
CurrentTarget = Game.GetPlayer()
endif
    else
        CurrentTarget.MoveTo(Self, XOffSet+(RandomFloat(0.0,RandomOffsetX)-RandomOffsetX/2 ), \
            YOffSet+(RandomFloat(0.0,RandomOffsetY)-RandomOffsetY/2), \
            ZOffSet+(RandomFloat(0.0,RandomOffsetZ)-RandomOffsetZ/2))
    endif
    Zap.Cast(Self,CurrentTarget)
    RegisterForSingleUpdate(PulseRate+RandomFloat(0.0,RandomRate))
EndEvent
</Source>
How to make this script work:
*Put it on the object you want the spells to originate from, and set the properties to define it's exact desired behavior.
*Pick any spell you want for the property Zap (needs to be of the Aimed spell type)
*If you want it to just shoot at a specific spot, define the Spawn Node Type as an xmarker, set SpawnNode to "True", and enter the relative coordinates you want the spell to be aimed at.
*If you want it to look for targets nearby, set SpawnNode to false and put a formlist of the valid targets in the TargetTypeList. If no Formlist is given, it will default to trying to shoot the player.
Anonymous user

Navigation menu