128 lines
2.7 KiB
Plaintext
128 lines
2.7 KiB
Plaintext
Scriptname _00E_MQ13a_GrammophoneSC extends ObjectReference
|
|
|
|
Actor Property PlayerREF Auto
|
|
Sound Property _00E_MUS_Special_DrachenflugM Auto
|
|
Message Property _00E_PlayerhousingKoppophonVolume Auto
|
|
|
|
Int iSoundID = -1
|
|
Float fVolume = 0.5
|
|
Bool bMusicLocked = False
|
|
|
|
Float Property MUSIC_LENGTH = 243.0 AutoReadOnly
|
|
|
|
|
|
;=====================================================================================
|
|
; FUNCTIONS
|
|
;=====================================================================================
|
|
|
|
Function PlayMusic(Sound musicSound, Float fMusicLength)
|
|
If fVolume <= 0.0 || fVolume > 1.0
|
|
fVolume = 0.5
|
|
EndIf
|
|
RegisterForModEvent("BardsLoadGame", "OnBardsLoadGame")
|
|
iSoundID = musicSound.Play(Self)
|
|
Sound.SetInstanceVolume(iSoundID, fVolume)
|
|
RegisterForSingleUpdate(_00E_TimeControl.AdjustTimePeriodByEngineTimerError(fMusicLength))
|
|
GoToState("")
|
|
_00E_PlayerhousingKoppophonVolume.Show(fVolume * 100.0)
|
|
EndFunction
|
|
|
|
Function ChangeMusicVolume()
|
|
If fVolume >= 0.0 && fVolume < 1.0
|
|
fVolume += 0.25
|
|
Else ; fVolume >= 1.0 or something is wrong with fVolume
|
|
fVolume = 0.0
|
|
EndIf
|
|
Sound.SetInstanceVolume(iSoundID, fVolume)
|
|
_00E_PlayerhousingKoppophonVolume.Show(fVolume * 100.0)
|
|
EndFunction
|
|
|
|
Function StopMusic()
|
|
bMusicLocked = True
|
|
|
|
GoToState("DoneCleanup")
|
|
UnregisterForModEvent("BardsLoadGame")
|
|
UnregisterForUpdate()
|
|
|
|
If iSoundID != -1
|
|
Sound.StopInstance(iSoundID)
|
|
iSoundID = -1
|
|
EndIf
|
|
|
|
bMusicLocked = False
|
|
EndFunction
|
|
|
|
Function TryStopMusic()
|
|
If bMusicLocked == False
|
|
StopMusic()
|
|
Else
|
|
RegisterForSingleUpdate(0.5)
|
|
EndIf
|
|
EndFunction
|
|
|
|
|
|
;=====================================================================================
|
|
; EVENTS
|
|
;=====================================================================================
|
|
|
|
Event OnInit()
|
|
GoToState("DoneCleanup")
|
|
EndEvent
|
|
|
|
Event OnActivate(ObjectReference akActionRef)
|
|
If akActionRef == PlayerREF && bMusicLocked == False
|
|
bMusicLocked = True
|
|
|
|
If iSoundID == -1
|
|
PlayMusic(_00E_MUS_Special_DrachenflugM, MUSIC_LENGTH)
|
|
Else
|
|
ChangeMusicVolume()
|
|
EndIf
|
|
|
|
bMusicLocked = False
|
|
EndIf
|
|
EndEvent
|
|
|
|
Event OnUpdate()
|
|
TryStopMusic()
|
|
EndEvent
|
|
|
|
Event OnBardsLoadGame(string eventName, string strArg, float numArg, Form sender)
|
|
; Player just loaded a save with the gramophone playing. The sound is dead by now.
|
|
TryStopMusic()
|
|
EndEvent
|
|
|
|
Event OnCellAttach()
|
|
TryStopMusic()
|
|
EndEvent
|
|
|
|
Event OnLoad()
|
|
TryStopMusic()
|
|
EndEvent
|
|
|
|
Event OnCellDetach()
|
|
TryStopMusic()
|
|
EndEvent
|
|
|
|
Event OnUnload()
|
|
TryStopMusic()
|
|
EndEvent
|
|
|
|
State DoneCleanup
|
|
Event OnCellAttach()
|
|
; Do nothing
|
|
EndEvent
|
|
|
|
Event OnLoad()
|
|
; Do nothing
|
|
EndEvent
|
|
|
|
Event OnCellDetach()
|
|
; Do nothing
|
|
EndEvent
|
|
|
|
Event OnUnload()
|
|
; Do nothing
|
|
EndEvent
|
|
EndState
|