2021-10-05 22:15:58 +00:00
|
|
|
Scriptname _00E_PlaceableGrammophonPlay extends ObjectReference
|
|
|
|
|
2021-10-11 18:39:58 +00:00
|
|
|
Sound Property _00E_MUS_Placeable_Koppophon Auto
|
|
|
|
MusicType Property _00E_SilenceTransitionHighPriority Auto ; OBSOLETE. Left for version update on older saves.
|
|
|
|
MusicType Property _00E_SilenceKoppophon Auto
|
2021-10-05 22:15:58 +00:00
|
|
|
GlobalVariable Property _00E_AchievementsEnabled Auto
|
|
|
|
Message Property _00E_PlayerhousingKoppophonVolume Auto
|
2021-10-11 18:39:58 +00:00
|
|
|
Actor Property PlayerREF Auto
|
2021-10-05 22:15:58 +00:00
|
|
|
|
2021-10-11 18:39:58 +00:00
|
|
|
Int playbackId = -1
|
|
|
|
Float volume = 0.5
|
|
|
|
Bool bDone ; Unlocked END_KOPPOPHON_01 achievement
|
|
|
|
Bool bMusicLocked = False
|
|
|
|
Bool bOldSilenceUpdated = False
|
2021-10-05 22:15:58 +00:00
|
|
|
|
2021-10-11 18:39:58 +00:00
|
|
|
Float Property MUSIC_LENGTH = 87.2 AutoReadOnly
|
2021-10-05 22:15:58 +00:00
|
|
|
|
|
|
|
|
2021-10-11 18:39:58 +00:00
|
|
|
;=====================================================================================
|
|
|
|
; FUNCTIONS
|
|
|
|
;=====================================================================================
|
|
|
|
|
|
|
|
Function StopMusic()
|
|
|
|
bMusicLocked = True
|
|
|
|
|
|
|
|
UnregisterForModEvent("BardsLoadGame")
|
2021-10-05 22:15:58 +00:00
|
|
|
UnregisterForUpdate()
|
2021-10-11 18:39:58 +00:00
|
|
|
|
|
|
|
If bOldSilenceUpdated == False
|
|
|
|
bOldSilenceUpdated = True
|
|
|
|
If playbackId != -1
|
|
|
|
_00E_SilenceTransitionHighPriority.Remove()
|
|
|
|
EndIf
|
|
|
|
EndIf
|
|
|
|
|
|
|
|
If playbackId != -1
|
|
|
|
Sound.StopInstance(playbackId)
|
|
|
|
playbackId = -1
|
|
|
|
EndIf
|
|
|
|
|
|
|
|
_00E_SilenceKoppophon.Remove()
|
|
|
|
|
|
|
|
bMusicLocked = False
|
|
|
|
EndFunction
|
|
|
|
|
|
|
|
Function TryStopMusic()
|
|
|
|
If bMusicLocked == False
|
|
|
|
StopMusic()
|
|
|
|
Else
|
|
|
|
RegisterForSingleUpdate(0.5)
|
|
|
|
EndIf
|
|
|
|
EndFunction
|
|
|
|
|
|
|
|
Function Cleanup()
|
|
|
|
GoToState("DoneCleanup")
|
|
|
|
TryStopMusic()
|
|
|
|
EndFunction
|
|
|
|
|
|
|
|
|
|
|
|
;=====================================================================================
|
|
|
|
; EVENTS
|
|
|
|
;=====================================================================================
|
|
|
|
|
|
|
|
Event OnInit()
|
|
|
|
GoToState("DoneCleanup")
|
|
|
|
EndEvent
|
2021-10-05 22:15:58 +00:00
|
|
|
|
|
|
|
Event OnActivate(ObjectReference triggerRef)
|
2021-10-11 18:39:58 +00:00
|
|
|
If triggerRef == PlayerREF && _00E_PlayerhousingMaster.ReferenceCanBeActivated(Self) && bMusicLocked == False
|
|
|
|
bMusicLocked = True
|
|
|
|
|
|
|
|
If playbackId == -1 ; Start playing
|
|
|
|
bOldSilenceUpdated = True
|
|
|
|
RegisterForModEvent("BardsLoadGame", "OnBardsLoadGame")
|
|
|
|
|
|
|
|
_00E_SilenceKoppophon.Add()
|
|
|
|
|
|
|
|
playbackId = _00E_MUS_Placeable_Koppophon.Play(Self)
|
|
|
|
If volume <= 0.0 || volume > 1.0
|
|
|
|
volume = 0.5
|
|
|
|
EndIf
|
|
|
|
Sound.SetInstanceVolume(playbackId, volume)
|
|
|
|
RegisterForSingleUpdate(_00E_QuestFunctions.AdjustTimePeriodByEngineTimerError(MUSIC_LENGTH))
|
|
|
|
|
|
|
|
GoToState("")
|
|
|
|
|
|
|
|
_00E_PlayerhousingKoppophonVolume.Show(volume * 100.0)
|
|
|
|
|
|
|
|
If _00E_AchievementsEnabled.GetValueInt() == 1 && (bDone == False)
|
|
|
|
bDone = True
|
|
|
|
Game.UnlockAchievement("END_KOPPOPHON_01")
|
|
|
|
EndIf
|
|
|
|
|
|
|
|
ElseIf bOldSilenceUpdated == False
|
|
|
|
; Player just loaded an older save with the Koppophon playing. The sound is dead by now.
|
|
|
|
StopMusic()
|
|
|
|
|
|
|
|
Else ; Volume control
|
|
|
|
Float fNewVolume = volume + 0.25
|
|
|
|
If fNewVolume > 1.0
|
|
|
|
fNewVolume = 0.0
|
|
|
|
EndIf
|
|
|
|
|
|
|
|
Sound.SetInstanceVolume(playbackId, fNewVolume)
|
|
|
|
If fNewVolume == 0.0 ; On mute
|
|
|
|
_00E_SilenceKoppophon.Remove()
|
|
|
|
ElseIf volume == 0.0 ; On unmute
|
|
|
|
_00E_SilenceKoppophon.Add()
|
|
|
|
EndIf
|
|
|
|
volume = fNewVolume
|
|
|
|
|
|
|
|
_00E_PlayerhousingKoppophonVolume.Show(volume * 100.0)
|
|
|
|
|
2021-10-05 22:15:58 +00:00
|
|
|
EndIf
|
2021-10-11 18:39:58 +00:00
|
|
|
|
|
|
|
bMusicLocked = False
|
|
|
|
EndIf
|
|
|
|
EndEvent
|
2021-10-05 22:15:58 +00:00
|
|
|
|
|
|
|
Event OnUpdate()
|
2021-10-11 18:39:58 +00:00
|
|
|
TryStopMusic()
|
|
|
|
EndEvent
|
|
|
|
|
|
|
|
Event OnBardsLoadGame(string eventName, string strArg, float numArg, Form sender)
|
|
|
|
; Player just loaded a save with the Koppophon playing. The sound is dead by now.
|
|
|
|
TryStopMusic()
|
|
|
|
EndEvent
|
|
|
|
|
|
|
|
Event OnCellAttach()
|
|
|
|
Cleanup()
|
|
|
|
EndEvent
|
|
|
|
|
|
|
|
Event OnLoad()
|
|
|
|
Cleanup()
|
|
|
|
EndEvent
|
|
|
|
|
|
|
|
Event OnCellDetach()
|
|
|
|
Cleanup()
|
|
|
|
EndEvent
|
|
|
|
|
|
|
|
Event OnUnload()
|
|
|
|
Cleanup()
|
|
|
|
EndEvent
|
|
|
|
|
|
|
|
State DoneCleanup
|
|
|
|
Event OnCellAttach()
|
|
|
|
; Do nothing
|
|
|
|
EndEvent
|
|
|
|
|
|
|
|
Event OnLoad()
|
|
|
|
; Do nothing
|
|
|
|
EndEvent
|
|
|
|
|
|
|
|
Event OnCellDetach()
|
|
|
|
; Do nothing
|
|
|
|
EndEvent
|
|
|
|
|
|
|
|
Event OnUnload()
|
|
|
|
; Do nothing
|
|
|
|
EndEvent
|
|
|
|
EndState
|