Help : Need a Script

Post » Tue Aug 27, 2013 2:47 am

Hi all,

As my scripting skills are very very low, I'm asking help here to reach my goals.

I'm trying to enhance http://skyrim.nexusmods.com/mods/1117//? by modifying the sound's level of the draw/sheath action.
The idea is too reduce half the level (and maybe more) of the sound made by your weapon when you draw, or sheath, your weapon while sneaking.

I first wanted to make two different sounds for these (if sneaking or not) but I think it appears more easier and efficient to simply adjust the sound's volume.
And to do so, as it was advised to me, I created a new sound category to be manipulated. (Of course, I also redirected the sound descriptor to that category)

As I was expecting, my following code doesn't work ! And give no notifications. But at least compile correctly.
I didn't even know where it's supposed to be called, so I tried to add it on a weapon for tests...

Spoiler
Scriptname AudioDynamicSneak extends ObjectReference
{Draw and sheath sounds reduced while sneaking}

Actor Property PlayerREF Auto
SoundCategory Property AudioCategorySneaked Auto

Event OnEquipped(Actor akActor)

If ((akActor == PlayerREF) && ((PlayerREF.GetEquippedItemType(0) == 0||1||2||3||4||5||6||7||8||10||12) || (PlayerREF.GetEquippedItemType(1) == 0||1||2||3||4||5||6||7||8||10||12) ) )
If (akActor.IsSneaking())
AudioCategorySneaked.SetVolume(0.2)
Debug.notification("Equip while sneaking")
Else
AudioCategorySneaked.SetVolume(1.0)
Endif

Endif
EndEvent

Event OnUnequipped(Actor akActor)

If ((akActor == PlayerREF) && ((PlayerREF.GetEquippedItemType(0) == 0||1||2||3||4||5||6||7||8||10||12) || (PlayerREF.GetEquippedItemType(1) == 0||1||2||3||4||5||6||7||8||10||12) ) )
If (akActor.IsSneaking())
AudioCategorySneaked.SetVolume(0.2)
Debug.notification("Equip while sneaking")
Else
AudioCategorySneaked.SetVolume(1.0)
Endif

Endif
EndEvent


So if anyone has a clue, a lead or a better idea to help me make this working, I will really appreciate :smile:
Thank you in advance for your time.

Best,

User avatar
Sam Parker
 
Posts: 3358
Joined: Sat May 12, 2007 3:10 am

Post » Tue Aug 27, 2013 2:22 am

Two problems with using those two events:

1. The volume will only change when you are equipping the weapon, not when drawing or sheathing the weapon. So if you equip the weapon while you aren't sneaking, then the sound will play at the original volume even if you sneak when you draw the weapon.

2. Those events require the script to be attached to the weapon (or other item that is to be equipped). So you would need to attach that script to every weapon present in the player's load order.

I'd suggest using SKSE (Skyrim Script Extender) and doing something like this:

Scriptname AudioDynamicSneak extends Quest{Draw and sheath sounds reduced while sneaking};This script should be attached to a questInt iSneakKeyActor Property PlayerRef AutoSoundCategory Property AudioCategorySneaked AutoFunction Initialize() UnregisterForKey(iSneakKey) iSneakKey = Input.GetMappedKey("Sneak") RegisterForKey(iSneakKey)EndFunctionEvent OnInit() Initialize()EndEventEvent OnKeyDown(Int KeyCode) If(PlayerRef.IsSneaking())  AudioCategorySneaked.SetVolume(0.2) Else  AudioCategorySneaked.SetVolume(1.0) EndIfEndEvent

The idea is to adjust the volume everytime the player presses the button assigned to start/stop sneaking.

You still need to figure out how to update the key assigned to sneaking in case the player decides to change it for whatever reason. Here's a suggestion:

Scriptname AudioDynamicSneakAlias extends ReferenceAlias{Updates the key assigned to sneaking upon loading the game};Attach this script to a reference alias that is filled with PlayerRefAudioDynamicSneak Property QuestName Auto ;change QuestName to be the EditorID of the quest that AudioDynamicSneak is attached toEvent OnPlayerLoadGame() QuestName.Initialize()EndEvent
User avatar
Kristina Campbell
 
Posts: 3512
Joined: Sun Oct 15, 2006 7:08 am

Post » Mon Aug 26, 2013 6:16 pm

Thank you MrJack for enlightening me !

I really wanted to avoid to put a script on every weapon, so your solution is ravishing :)

I'm gonna try your suggestions right away.

I'll keep you informed,

Many many thanks

User avatar
Monique Cameron
 
Posts: 3430
Joined: Fri Jun 23, 2006 6:30 am


Return to V - Skyrim