Jump to content

[LE] Music Box Script Help


Hypn0sef

Recommended Posts

I know there are plenty of music boxes in existing mods, but I'm attempting to make one that can be kept in your inventory and used wherever. My scripting ability is very minimal, but I got the Stroti gramophone converted in NifSkope so you can pick it up. I tried using this script* I found in another forum, but it only worked when dropped and picked up and with the priority of the music track set as 1, the highest, and even then it doesn't stop. I assume it needs to be OnEquip or something rather than OnActivate. (I'm also not insulting this script, it works great on an activator but doesn't perfectly suit my need)

 

Any help would be greatly appreciated and will get you a credit on the mod page

 

*Scriptname AAMusicScript extends ObjectReference
;* Play Music * By: NexusComa * ; nexusmods.com
ObjectReference Property Marker Auto
MusicType Property _MusicTrack Auto
MusicType Property _NONE Auto
;
Event OnInit()
Marker.Disable()
GoToState("Switch")
EndEvent
;-----------------------
State Switch
Event OnActivate(ObjectReference akActionRef)
If(Marker.IsDisabled())
_Enable()
Else
_Disable()
EndIf
EndEvent
EndState
;-----------------------
Function _Enable()
Marker.Enable()
_MusicTrack.Add()
Utility.Wait(1.0)
_NONE.Remove()
EndFunction
;-----------------------
Function _Disable()
Marker.Disable()
_NONE.Add()
Utility.Wait(1.0)
_MusicTrack.Remove()
EndFunction
Link to comment
Share on other sites

Since you're using an object that can be picked up, you can simplify the script. You're right, you do need to use the OnEquipped event. What I would do is use a Message form with 2 buttons to enable or disable the music.

 

MusicType Property _MusicTrack Auto
Message Property MusicBoxMsg auto 


Event OnEquipped(Actor akActor) 
    If akActor == Game.GetPlayer()
        If MusicBoxMsg.Show() == 0 
            _MusicTrack.Remove() 
        Else 
            _MusicTrack.Add()
        Endif 
    Endif
EndEvent

If you want to add more track selections, you can use an array and do something like this:

 

MusicType[] Property _MusicTracks Auto
Message Property MusicBoxMsg auto 
MusicType CurrentTrack

Event OnEquipped(Actor akActor) 
    If akActor == Game.GetPlayer()
        CurrentTrack.Remove() ;stop playing current track
        
        Int Button = MusicBoxMsg.Show()
        If Button <= 8 ;make Message button 9 as a Stop button.
            CurrentTrack = _MusicTracks[Button] 
            CurrentTrack.Add() ;start playing new selected track
        Endif
    Endif
EndEvent
Link to comment
Share on other sites

I just tried * and it didn't even play the music so there goes that theory lol

 

*

MusicType Property _MusicTrack Auto
ObjectReference Property Marker Auto
Event OnEquipped(Actor akActor)
If akActor == Game.GetPlayer()
If(Marker.IsDisabled())
_MusicTrack.Remove()
Else
_MusicTrack.Add()
Endif
Endif
EndEvent
Link to comment
Share on other sites

It keeps playing because you're not disabling or enabling the marker in the script. Instead of using an marker in this case, I would use a bool instead:

MusicType Property _MusicTrack Auto
Bool Property Playing = False Auto Hidden 

Event OnEquipped(Actor akActor) 
    If akActor == Game.GetPlayer()
        If Playing == True
            Playing = False
            _MusicTrack.Remove() 
        Else 
            Playing = True
            _MusicTrack.Add()
        Endif 
    Endif
EndEvent

Edit: The hidden tag just means the property won't show in the Creation kit.

Link to comment
Share on other sites

I realized that after I posted and tried a variant with my attempt at having it enable and disable the marker but that also didn't work, likely due to my scripting ability and not any issue with the concept. Awesome I'll try that way, thanks again!

Link to comment
Share on other sites

No problem :) the enable / disable might not have worked if your property wasn't filled, but again for this I think using a bool would be better. I haven't ever used the MusicTrack.Add and remove functions before so I can't really say how well they work.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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