Jump to content

How can I script a sound to loop endlessly when an item is equipped, then stop when unequipped?


Recommended Posts

I'm trying to add a sound to some armor i'm making, but I kinda hit a brick wall when it comes to adding sound.

 

All I want, is, when my character equips the item, then a sound will loop until I unequip the item

 

The problem: I've never used papyrus before.

 

It seems similar to LUA, a language i'm familiar with but needlessly complex.

 

I can't work out how I address a specific sound to play. The CK forums suggest using an identifier (ex. mysound), but how do I link that to a WAV file?

 

All I have right now is this:

Scriptname Bodysoundloop extends ObjectReference Hidden

int intArmorSFX = ArmorBodySFX.play(self)
Sound.SetInstanceVolume(intArmorSFX, 1) 

Sound.StopInstance(intArmorSFX)

Does ArmorBodySFX refer to the ObjectReference of a Sound Descriptor or something? I have no idea... Help please!

Edited by OmalleyPike
Link to comment
Share on other sites

I don't know anything about Papyrus (yet), but 'ArmorBodySFX' almost certainly a reference to an object inside CK. CK is all about long chains of references inside references, as you may have seen. I don't think the script would have the ability to directly reference a WAV file, so it's probably a pointer to something with an Object ID.

Link to comment
Share on other sites

Okay so I did some more work on this today and I managed to get the script to compile and link my Sound Property to my Sound Descriptor, but unfortunately it doesn't play the sound in-game. Any ideas?

Scriptname Bodysoundloop extends ObjectReference

Sound Property ArmorSFX_LP auto
Int Property ArmorSFX auto
Int Property Armorplay auto

Event OnEquipped(Actor akActor)
  ArmorSFX = ArmorSFX_LP.play(self)
  Sound.SetInstanceVolume(ArmorSFX, 1)
EndEvent

Event OnUnequipped(Actor akActor)
  Sound.StopInstance(ArmorSFX)
EndEvent

Again, thanks!

 

EDIT: I managed to fix the problem: The problem was, that using ArmorSFX - ArmorSFX_LP.play(self) attempts to play the sound from the script itself (to my understanding) instead of an object in-world. So instead of using that, we add an additional ObjectReference which is linked to the PlayerRef. This then defines the source of the sound to be the player, not the script itself. The finished script looks like this:

Scriptname Bodysoundloop extends ObjectReference

Sound Property ArmorSFX_LP auto
Int Property ArmorSFX auto
Int Property Armorplay auto
ObjectReference Property soundsourceplayer auto

Event OnEquipped(Actor akActor)
  ArmorSFX = ArmorSFX_LP.play(soundsourceplayer)
  Sound.SetInstanceVolume(ArmorSFX, 1)
EndEvent

Event OnUnequipped(Actor akActor)
  Sound.StopInstance(ArmorSFX)
EndEvent
Edited by OmalleyPike
Link to comment
Share on other sites

  • Recently Browsing   0 members

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