Jump to content

Help with oncast script.


wapeddell

Recommended Posts

Posted

Basically I'm trying to make a soundplay when casting any spell. However, I don't know how to make it where it works when casting nor do I know how to make it work on any spell.

 

Scriptname SpellName extends ObjectReference  
 
Spell Property SpellBloodSpike auto
Sound Property MySound Auto
 
Event OnSpellCast(Form akSpell)
 
Spell spellCast = akSpell as Spell
if spellCast && spellCast == SpellBloodSpike
int instanceID = Mysound.play(self)
Sound.SetInstanceVolume(instanceID, 1.0) ; 
EndIf
EndEvent
 
Posted

If you haven't, you might want to take a look at the documentation OnSpellCast

 

The simple answer is you can't do what you want the way you want to. The OnSpellCast trigger would have to be attached to every actor. Assuming you only want it to trigger on actor cast spells. Other types of casts would be like the standing stones. Another issue is that the OnSpellCast also triggers for enchantments, potions, and ingredients. Not just magical spells. Your example looks like just a copy+paste from the wiki. Which means that in your if statement the check would only allow triggering if the spell cast was SpellBloodSpike.

 

Based on your sample you would have to attach that script to every object that would actually do the casting. Only then when that object casts would it fire. For example if you put that script on the player, only when the player cast would it do its stuff. If any other actor casts it would do nothing, because it would never fire. Something to be aware of if you decide to go that route, any actors that are already spawned will not be updated with the attached script. You could use a quest with a ReferenceAlias and force an existing actor into the alias, with the script attached to the ReferenceAlias. However it still would only affect that reference. As soon as you put someone/something else in the ReferenceAlias only that object would be a trigger.

 

An alternative is to modify the script to be placed on spells and then when you activate that spell it triggers. Though that still requires you attach to every spell you want to trigger on. This alleviates the issues with already spawned references though. The script attached to a spell is triggered every time that spell is cast.

 

The biggest problem with either method is you have to modify a lot of records to attach the script. This also creates direct compatibility issues with any other mod that would modify those records.

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...