enderalse/source/scripts/_00e_gaboff_grammophonesc.psc

133 lines
2.9 KiB
Plaintext

Scriptname _00E_Gaboff_GrammophoneSC extends ObjectReference
Message Property _00E_Gaboff_GrammophoneMSG Auto
Message Property _00E_PlayerhousingKoppophonVolume Auto
Sound Property _00E_MUS_Special_OceansWidowM Auto
MiscObject Property Gold001 Auto
Actor Property PlayerREF Auto
Int iSoundID = -1
Float fVolume = 0.5
Bool bMusicLocked = False
Float Property MUSIC_LENGTH = 212.3 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
If _00E_Gaboff_GrammophoneMSG.Show() == 0
PlayerREF.RemoveItem(Gold001, 5)
PlayMusic(_00E_MUS_Special_OceansWidowM, MUSIC_LENGTH)
EndIf
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