WoxBox Posted January 5, 2018 Share Posted January 5, 2018 Hey guys, After following the Creation Kit Tutorials and doing a bit of research online I thought I'd have a bit of a better grasp on creating custom scripts and attaching them to objects but I'm still a little green and can't seem to get my idea to work. So essentially I want to attach a script to a weapon of the effect that once the weapon is equipped, it'll play a sound file at certain intervals (let's say every 10mins). I wanted to add an even more complex implantation where it plays a random sound from an array of possible sounds, but thought I'd stick with something basic first. Once it's unequipped, it'll stop attempting to play sound. Other things I tried (and failed) to do were:Once the play has equipped the sword they get a buff that shows up in the Active Effects tab on the Magic page in game.Add a few custom enchants/magic effects to the weapon (Increase crit chance and life drain). So the sudo code (in my mind) was: On EquipApply BuffStart 10min timer (Loop)Load Sound filePlay Sound I got as far as the example found here: https://www.creationkit.com/index.php?title=OnEquipped_-_ObjectReference But creating enchants and buffs just completely lost me. Not to mention the playing of sound files. If anyone could point me in the right direction, that'd be hugely appreciated :smile:) EDIT: I forgot to mention that the weapon I'm intending on adding a script to is itself a mod. I know that may complicate things but for testing, I'm more than happy to add it to a standard Skyrim weapon. Link to comment Share on other sites More sharing options...
TheWormpie Posted January 5, 2018 Share Posted January 5, 2018 actor property player auto spell property myBuffAbility auto sound[] property mySounds auto float property mySoundVolume auto ; remember to fill these properties Event OnEquipped(Actor akActor) if akActor == Game.GetPlayer() player.AddSpell(myBuffAbility) PlayRandomSound() ; remove this if you don't want the sound to play instantly when equipping RegisterForSingleUpdate(600.0) ;run update event in 10 minutes endIf endEvent Event OnUnequipped(Actor akActor) if akActor == Game.GetPlayer() player.RemoveSpell(myBuffAbility) UnregisterForUpdate() ;stop playing sounds every 10 minutes endIf endEvent Event OnUpdate() PlayRandomSound() RegisterForSingleUpdate(600.0) EndEvent Function PlayRandomSound() int iRandom = utility.RandomInt(1, mySounds.Length) ; will create a random number between 1 and the length of your sound array int instanceID = mySounds[iRandom].play(player) ; play a random sound from the array, it is heard playing from the player actor Sound.SetInstanceVolume(instanceID, mySoundVolume) ; play at whatever volume you want, but never more than 1.0 EndFunction This should do everything you want, except the custom enchants (which shouldn't be in the script but rather in your weapon's enchantment settings). Read it through and see if you understand everything. Otherwise ask :) Link to comment Share on other sites More sharing options...
WoxBox Posted January 5, 2018 Author Share Posted January 5, 2018 actor property player auto spell property myBuffAbility auto sound[] property mySounds auto float property mySoundVolume auto ; remember to fill these properties Event OnEquipped(Actor akActor) if akActor == Game.GetPlayer() player.AddSpell(myBuffAbility) PlayRandomSound() ; remove this if you don't want the sound to play instantly when equipping RegisterForSingleUpdate(600.0) ;run update event in 10 minutes endIf endEvent Event OnUnequipped(Actor akActor) if akActor == Game.GetPlayer() player.RemoveSpell(myBuffAbility) UnregisterForUpdate() ;stop playing sounds every 10 minutes endIf endEvent Event OnUpdate() PlayRandomSound() RegisterForSingleUpdate(600.0) EndEvent Function PlayRandomSound() int iRandom = utility.RandomInt(1, mySounds.Length) ; will create a random number between 1 and the length of your sound array int instanceID = mySounds[iRandom].play(player) ; play a random sound from the array, it is heard playing from the player actor Sound.SetInstanceVolume(instanceID, mySoundVolume) ; play at whatever volume you want, but never more than 1.0 EndFunction This should do everything you want, except the custom enchants (which shouldn't be in the script but rather in your weapon's enchantment settings). Read it through and see if you understand everything. Otherwise ask :smile: Oh wow that's utterly fantastic! I can't thank you enough, Wormple! Half of these functions I hadn't even heard of before which is probably half my problem haha. But no, you've laid it all out quite nicely and the comments are really appreciated!!! :) I was actually tinkering around with the script now and was trying to add a timer using StartTimerGameTIme() but that was failing me. Now this makes a whole lot more sense :D! So I assume I'll have to create the spell/buff first then link it through the properties. The array I'm not too sure about but I'm sure I can research how to do it :) I'll have a play around trying to make the array of sounds property etc and see how far I get. Thank you so much again! Link to comment Share on other sites More sharing options...
WoxBox Posted January 5, 2018 Author Share Posted January 5, 2018 actor property player auto spell property myBuffAbility auto sound[] property mySounds auto float property mySoundVolume auto ; remember to fill these properties Event OnEquipped(Actor akActor) if akActor == Game.GetPlayer() player.AddSpell(myBuffAbility) PlayRandomSound() ; remove this if you don't want the sound to play instantly when equipping RegisterForSingleUpdate(600.0) ;run update event in 10 minutes endIf endEvent Event OnUnequipped(Actor akActor) if akActor == Game.GetPlayer() player.RemoveSpell(myBuffAbility) UnregisterForUpdate() ;stop playing sounds every 10 minutes endIf endEvent Event OnUpdate() PlayRandomSound() RegisterForSingleUpdate(600.0) EndEvent Function PlayRandomSound() int iRandom = utility.RandomInt(1, mySounds.Length) ; will create a random number between 1 and the length of your sound array int instanceID = mySounds[iRandom].play(player) ; play a random sound from the array, it is heard playing from the player actor Sound.SetInstanceVolume(instanceID, mySoundVolume) ; play at whatever volume you want, but never more than 1.0 EndFunction This should do everything you want, except the custom enchants (which shouldn't be in the script but rather in your weapon's enchantment settings). Read it through and see if you understand everything. Otherwise ask :smile: Hey Wormple, sorry to keep bugging you but I'm running into issue with the script. The equip and unequip events are firing but the update event isn't being triggered. I've reduced the update to 30 seconds and added a message box for good measure but it doesn't seem to be running. Any ideas? :) Link to comment Share on other sites More sharing options...
TheWormpie Posted January 6, 2018 Share Posted January 6, 2018 I don't know. Try removing the UnregisterForUpdate part. Otherwise you might have to move part of your script to another instance, a quest for example. If you don't have a quest associated with this already, create one, then move the OnUpdate event and the PlayRandomSound function to the quest script. Then, in your weapon script, you can use "myQuest.RegisterForSingleUpdate(600.0)" instead and see if it makes a difference (and again, remember to make a quest property and fill it with the appropiate quest). Link to comment Share on other sites More sharing options...
Recommended Posts