Jump to content

DOWNLOAD MODS

Are you looking for something shiny for your load order? We have many exclusive mods and resources you won't find anywhere else. Start your search now...

LEARN MODDING

Ready to try your hand at making your own mod creations? Visit the Enclave, the original ES/FO modding school, and learn the tricks of the trade from veteran modders...

JOIN THE ALLIANCE

Membership is free and registering unlocks image galleries, project hosting, live chat, unlimited downloads, & more...

Example Script Help (Script to make an item cast a spell)


skia
 Share

Recommended Posts

I'm trying to get the example script to work off the creation kit site. 

 

I've done/read a few tutorial and thought I'd understand how to make the example script work. However, after following the pointers under the example script given and changing/assigning properties as it states, the WETempActivator object will not strike me with the sparks spell I have assigned it. 

 

Here is the script I'm trying to follow. 

 

CK Site

Edited by skia
Link to comment
Share on other sites

Thanks for the response. I have done chapters 1-3 on the CK wiki. I'll take a look at yours but to follow through with more information here is my script (which is essentially a copy and paste from the wiki) along with the properties I have modified as best as could follow from what the wiki itself says to do. 

 

This is what I have. 

Scriptname HelloWorld extends ObjectReference  

import Utility
Actor Property PlayerREF Auto
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 Auto ; Randomness applied to X Offset. Initializes at 0.
Float Property RandomOffsetY Auto ;Randomness applied to Y Offset. Initializes at 0.
Float Property RandomOffsetZ Auto ; Randomness applied to Z Offset. Initializes at 0.
Float Property PulseRate = 1.0 Auto ; How often do we shoot?
Float Property RandomRate 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. Initializes 'False'
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 CurrentTarget ;!= None
    elseIf SpawnNode
        float newXOffset = XOffSet + RandomFloat(-RandomOffsetX, RandomOffsetX)
        float newYOffset = YOffSet + RandomFloat(-RandomOffsetY, RandomOffsetY)
        float newZOffset = ZOffSet + RandomFloat(-RandomOffsetZ, RandomOffsetZ)
        CurrentTarget = PlaceAtme(TargetType)
        CurrentTarget.MoveTo(Self, newXOffSet, newYOffSet, newZOffSet)
    endif
    RegisterForSingleUpdate(PulseRate)
EndEvent
 
Event OnUpdate()
    ; find something nearby to shoot at if we're not making our own target.
    if !SpawnNode && !TargetTypeList && GetDistance(PlayerREF) < SeekRange ; No list given, Default to the player if he is in range.
	CurrentTarget = PlayerREF
    elseif TargetTypeList
        CurrentTarget = Game.FindClosestReferenceOfAnyTypeInListfromRef(TargetTypeList, Self, SeekRange)
    endif
    if CurrentTarget ; it's possible that there is no target 
        Zap.Cast(Self,CurrentTarget)
    endif
    RegisterForSingleUpdate(PulseRate + RandomFloat(0.0, RandomRate))
EndEvent

Here is a screenshot of my properties window for the script. 

PropertiesWindow.jpg

Edited by skia
Link to comment
Share on other sites

Your not filling or pointing 'TargetTypeList' to anything.

Your 'TargetType' is not pointing to anything.

Your 'ZOffset' is not set to anything.

Your random offsets are all not set to anything (zero), so your RandomFloat function would return 0. So those commands are not doing anything.

Just to mention a few things.

Link to comment
Share on other sites

Your not filling or pointing 'TargetTypeList' to anything.

Your 'TargetType' is not pointing to anything.

Your 'ZOffset' is not set to anything.

Your random offsets are all not set to anything (zero), so your RandomFloat function would return 0. So those commands are not doing anything.

Just to mention a few things.

Oh please mention all things. Because from what I understood is that the example script should pretty much function as is. But I had tried putting values for the offsets with no results but not for the randomFloat which I thought would give a random number. 

 

Also the points below the example say that if I want it to focus the player to leave TargetTypeList to default and it would default to the player if SpawnNode was set to false which it is. 

 

  • 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.

I'll try putting a value for the randomFloats

Edited by skia
Link to comment
Share on other sites

The calculations for this command are zero since nothing is set. It resolves to 0.

RegisterForSingleUpdate(0)

I am pretty sure that turns off updates.

 

if !SpawnNode && !TargetTypeList && GetDistance(PlayerREF) < SeekRange

SeekRange is 0, and GetDistance(PlayerREF) will not be less than zero, so it fails to set the CurrentTarget as the PlayerREF.

GetDistance(PlayerREF) < SeekRange

Link to comment
Share on other sites

The calculations for this command are zero since nothing is set. It resolves to 0.

RegisterForSingleUpdate(0)

I am pretty sure that turns off updates.

 

if !SpawnNode && !TargetTypeList && GetDistance(PlayerREF) < SeekRange

SeekRange is 0, and GetDistance(PlayerREF) will not be less than zero, so it fails to set the CurrentTarget as the PlayerREF.

GetDistance(PlayerREF) < SeekRange

Float Property SeekRange = 1000.0

 

Its set to 1000 though? 

 

As for the RegisterForSingleUpdate, it's Float Property PulseRate = 1.0 so RegisterForSingleUpdate(PulseRate) is RegisterForSingleUpdate(1) right? 

Edited by skia
Link to comment
Share on other sites

Oh, yeah, I forgot to look in the properties equals this time. :lol: I wondered why I 'missed' it in my last response.

1000 should be fine, its a large area.

 

Make sure your using a clean save game, that has never had your mod activated. When your testing a mod, you should always use a clean save game.

Link to comment
Share on other sites

Ok I got it working. I remembered I had another mod that altered its script and I deleted that, then I assigned values to all the random variables and x y and z offsets and its working. Not what I had in mind cause I thought I would see the spell go from it to me but instead it just zaps me, still neat! Thanks for the help! 

Link to comment
Share on other sites

 
EDIT: Ok So I got it to strike me once, when I hit one time but the sound of it hitting me is stuck on. Then when I hit it again, nothing happens. It only hits me once when I hit it once for the first time. So I added a messagebox on the OnHit and OnUpdate to see what was going on.
 
I get "Hit!" when I hit it and take damage and then I get "Update!" for Even OnUpdate but then it just gets suck on "Hit!" over and over even without me hitting it. I just don't understand why OnHit would get stuck? 
 
Here is my code. I figured a large portion of the code was useless for what I was trying to do and so I commented it out. 
 

Scriptname ZapScript extends ObjectReference  

import Utility
Actor Property PlayerREF Auto
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 Auto ; Randomness applied to X Offset. Initializes at 0.
Float Property RandomOffsetY Auto ;Randomness applied to Y Offset. Initializes at 0.
Float Property RandomOffsetZ Auto ; Randomness applied to Z Offset. Initializes at 0.
Float Property PulseRate = 1.0 Auto ; How often do we shoot?
Float Property RandomRate 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. Initializes 'False'
Spell Property Zap Auto ; What spell shall we use for the effect?
FormList Property TargetTypeList Auto ; List of potential targets
Float Property SeekRange = 10.0 Auto ; The range it will "Lock into" a target if not making a node.
Form Property source  Auto  


Event OnHit(ObjectReference akAggressor, Form  akSource,Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, \
  bool abBashAttack, bool abHitBlocked)

if akSource == Zap


  ;  if CurrentTarget ;!= None
  ;  elseIf SpawnNode
       ; float newXOffset = XOffSet + RandomFloat(-RandomOffsetX, RandomOffsetX)
      ;  float newYOffset = YOffSet + RandomFloat(-RandomOffsetY, RandomOffsetY)
      ;  float newZOffset = ZOffSet + RandomFloat(-RandomOffsetZ, RandomOffsetZ)
      ;  CurrentTarget = PlaceAtme(TargetType)
       ; CurrentTarget.MoveTo(Self, newXOffSet, newYOffSet, newZOffSet)
   ; endif
Debug.MessageBox("Hit!")

    RegisterForSingleUpdate(PulseRate)
endif
;source = akSource 
EndEvent

Event OnUpdate()
    ; find something nearby to shoot at if we're not making our own target.
   ; if !SpawnNode && !TargetTypeList ;&& GetDistance(PlayerREF) < SeekRange ; No list given, Default to the player if he is in range.
CurrentTarget = PlayerREF
    ;elseif TargetTypeList
        ;CurrentTarget = Game.FindClosestReferenceOfAnyTypeInListfromRef(TargetTypeList, Self, SeekRange)
   ; endif
    if CurrentTarget ; it's possible that there is no target 
        Zap.Cast(Self,CurrentTarget)

    endif
Debug.MessageBox("Update!")
   ;UnregisterForUpdate()
   RegisterForSingleUpdate(PulseRate + RandomFloat(0.0, RandomRate))


EndEvent

 
EDIT AGAIN.
 
It seems to be because the spell I am filtering via the if loop and the spell I"m having it cast is the same is causing it to constantly go through the if loop as true over and over again. Once I changed the spell for the object to cast to lets say thunderbolt, it began working as I had expected it too. I'd cast sparks on it and it would launch a thunderbolt. I'm still confused as to why this is so. Or maybe its because Sparks is a spell that can always be casted? I'll have to try with fire to see. 
 
So with flames as the spell for the object to cast I can see that it constantly spouts flames out but I can hit around the object and have it change the direction it spits the falmes, its actually pretty neat! But still not what I'm looking for. I need it to do the same with sparks and I need it to do it for like a short while, might have to make a new spell... 

 

Final EDIT:

So I resorted to making a new spell, it works but doesn't look like I want it. Trying to apply the same script to a body of water and it won't work ? Not sure why yet. any thoughts on this?

Edited by skia
Link to comment
Share on other sites

I have never seen water boil when hit with a fireball. If its a mod, then look at that mod to see what they did.

Most of modding is seeing how somebody did something similar to what your trying to do. :lol:

Yeah I've been trying to see skyrim scripts and learn from them but I can't exactly find how Bethesda gets their water to boil from a fire spell. It is not a mod, its actually there by default and in fact if you open up the creation kit and got to Special Effects, AddOnNod and search for boil you can find the effect. But you can also try it in game. Certain waters will in fact boil from a fire spell, I just don't know how that works. 

 

I also found out about this two days ago. Pretty neat. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...