FireDragon76
Pinball Wizard
- Joined
- Apr 5, 2023
- Messages
- 137
- Reaction score
- 19
- Points
- 18
- Favorite Pinball Machine
- Spirit of 76
I am working on trying to implement FizX Lite on Eight Ball Deluxe. I got it working on Popotte's Bally Star Trek (1978) just fine. I also included ball rolling sounds from the FizX All-in-One table. But for some reason, the code doesn't work on Eight Ball Deluxe. Debug window says ball rolling sound is playing (and gives consecutive numbers 1....2...3, each time the timer ticks over and the ball rolls), but it doesn't say the name of the sound, as it does in the Star Trek table, and no sound can be heard playing:
Code:
'
' ################## BALL ROLLING SOUNDS - FP ##################
' By Nailbuster, TerryRed, Popotte
' Version: 2.1
' Dec - 2022, Mar 2023
' - add this code to your table starting at "BALL ROLLING SOUNDS - FP" and ending at "END OF BALL ROLLING SOUNDS - FP".
' - add a timer named BallRolling_Update_Timer ("Timer Enabled" unchecked and "Time Interval" set to 150)
' - add a timer named Timer1 ("Timer Enabled" checked and "Time Interval" set to 75)
' - add desired BallRolling_Sound files to Music Manager
' - change Ball Rolling Sound Settings as needed
' - run Ball_Rolling_Sounds_Start on table startup
' - Add the following line of code (without apostrophe) as a separate line to "Sub ResetForNewPlayerBall()".
' FlagRamp = 0
DIM BallRolling_Sound_Enabled
DIM FP_BallRoll_Max_Volume
DIM FP_BallRoll_Active_Volume
DIM FP_BallRolling_Channel
DIM BallRolling_Sound
DIM BallRolling_Sound1
DIM BallRolling_Sound2
Dim FlagRamp
Dim TrackedBalls(6)
' ################## Ball Rolling Sound Settings ##################
Sub Ball_Rolling_Sound_Settings
BallRolling_Sound_Enabled = true ' enable Ball Rolling Sounds (true or false)
FP_BallRoll_Max_Volume = 0.6 ' Future Pinball ball rolling max volume (default = 1)
FP_BallRolling_Channel = 8 ' PlayMusic channel that is NOT used by anything else on the table!!!
BallRolling_Sound1 = "mech_ballroll_wood" ' ball rolling sound for playfield - add sound file to Music Manager
BallRolling_Sound2 = "mech_ballroll_metal" ' ball rolling sound for ramp - add sound file to Music Manager
End Sub
' max number of balls that will have ball rolling sounds (no more than 6)
' ############### Ball Rolling Sound Settings - END ###############
' *** Ball Rolling Sound Tuning (FP) ***
Dim i
Const BallVelTuning = 25
Const BallVolTuning = 2300
Function BallSpeedVol(ball) ' Calculates the Volume of the sound based on the ball speed
BallSpeedVol = (zfunBallVel(ball) ^2) / BallVolTuning
if (BallSpeedVol>1.0) then BallSpeedVol=1.0
End Function
Function BallSpeedPitch(ball) ' Calculates the pitch of the sound based on the ball speed
BallSpeedPitch = round(100+zfunBallVel(ball)/4)
if (BallSpeedPitch>120) then BallSpeedPitch=120 end if
End Function
Function zfunBallVel(ball) ' Calculates the ball speed
zfunBallVel = INT( SQR( (ball.velocity.x^2 + ball.velocity.y^2) )/BallVelTuning )
End Function
Function BallPan(ball) ' not used - Calculates the panning (left/right) for a ball based on the X position on the table.
Dim tmp
tmp = ball.PositionGlobal.x * 2 / ((xBAM.Table.width)-1)
If tmp > 0 Then
BallPan = (tmp ^10)
Else
BallPan = (-((- tmp) ^10))
End If
End Function
' *** Ball Rolling Sound Tuning (FP) - END ***
DIM bAudioW:bAudioW=xBAM.Table.width 'table width
DIM bAudioH:bAudioH=xBAM.Table.length 'table length
ReDim GlobalBallsArray(-1)
Sub GetBallsCallback(ball)
ReDim Preserve GlobalBallsArray(UBound(GlobalBallsArray) + 1)
Set GlobalBallsArray(UBound(GlobalBallsArray)) = ball
End Sub
Function GetBalls(max)
ReDim Preserve GlobalBallsArray(-1)
xBAM.EnumBalls max, 0, "GetBallsCallback"
GetBalls = GlobalBallsArray
End Function
Function FindEmptyVoice
FindEmptyVoice = -1
For i=0 to Ubound(TrackedBalls) -1
If IsEmpty(TrackedBalls(i)) Then
FindEmptyVoice = i
Exit For
End If
Next
adddebugtext "EmptyVoice= " &i
End Function
Const MinSpeed = 1
Dim Toto
Sub UpdateBallSound(ByRef tmpball, bIndex)
dim xpos,ypos
xpos= ((tmpball.PositionGlobal.x / bAudioW) * 20) - 10
ypos= ((tmpball.PositionGlobal.y / bAudioH) * -10)
if tmpball.speed>1 Then
If tmpball.ExtFloat3 <> 1 Then Exit Sub
FP_BallRoll_Active_Volume = (BallSpeedVol(tmpball))*(FP_BallRoll_Max_Volume*10) ' FP ball volume level
EffectMusic FP_BallRolling_Channel, SetVolume, FP_BallRoll_Active_Volume, 0
EffectMusic FP_BallRolling_Channel, SetFrequency, 0, BallSpeedPitch(tmpball) ' FP ball pitch
Toto = Toto +1: adddebugtext "Ball sound= "&BallRolling_Sound &" " &Toto
'AddDebugText "BallRoll Vol = " & FP_BallRoll_Active_Volume
'AddDebugText "BallRoll Freq = " & BallSpeedPitch(tmpball)
'AddDebugText "BallSpeed = " &tmpball.speed
Else
EffectMusic FP_BallRolling_Channel, SetVolume, 0, 0
end if
End Sub
Sub CheckBallSound()
For i=0 to Ubound(TrackedBalls) -1
If Not IsEmpty(TrackedBalls(i)) Then
If TrackedBalls(i).Exist Then
UpdateBallSound TrackedBalls(i),i
Else
EffectMusic FP_BallRolling_Channel, SetVolume, 0, 0 ' turn off vol on destroyed balls (fp)
AddDebugText "Stop FP Ball Rolling: Vol = 0"
TrackedBalls(i).ExtFloat3 = 0 ' If we stop sound, because ball is too slow, we mark this ball as not tracked, 0 is default value
TrackedBalls(i) = Empty ' ... and we forgot about this ball
End If
End If
Next
End Sub
Sub BallRolling_Update_Timer_Expired()
CheckBallSound()
Dim BOT, b, i
BOT = GetBalls(Ubound(TrackedBalls)) ' we don't need more balls, than we can track
For b = 0 To UBound(BOT)
If Bot(b).ExtFloat3 = 0 Then ' we want to add only balls not tracked already
adddebugtext "Not yet tracked"
If Bot(b).Speed <= MinSpeed Then Exit For 'all other balls are too slow... no need to check
i = FindEmptyVoice()
If i = -1 Then Exit For ' we don't have empty voice slots
Set TrackedBalls(i) = Bot(b)
TrackedBalls(i).ExtFloat3 = 1
' start playing FP Ball Rolling sound (looped, and volume at 0)
PlayMusic FP_BallRolling_Channel, BallRolling_Sound, true ,0 ,0
AddDebugText "Start FP Ball Rolling on PlayMusic Channel: " & FP_BallRolling_Channel
UpdateBallSound TrackedBalls(i),i
End If
If Bot(b).ExtFloat3 = 3 Then ' balls already tracked but we change ball sound
adddebugtext "Not yet tracked"
If Bot(b).Speed <= MinSpeed Then Exit For 'all other balls are too slow... no need to check
Set TrackedBalls(b) = Bot(b)
TrackedBalls(i).ExtFloat3 = 1
' start playing FP Ball Rolling sound (looped, and volume at 0)
PlayMusic FP_BallRolling_Channel, BallRolling_Sound, true ,0 ,0
AddDebugText "Change FP Ball Rolling on PlayMusic Channel: " & FP_BallRolling_Channel
UpdateBallSound TrackedBalls(i),i
End If
Next
End Sub
Sub Ball_Rolling_Sounds_Stop ' Force Ball Rolling Sounds to be off
BallRolling_Update_Timer.enabled = false
EffectMusic FP_BallRolling_Channel, SetVolume, 0, 0
AddDebugText "Ball Rolling Stopped"
End Sub
Sub Ball_Rolling_Sounds_Mute ' Force Ball Rolling Sounds to be muted
EffectMusic FP_BallRolling_Channel, SetVolume, 0, 0
AddDebugText "Mute FP Ball Rolling"
End Sub
Sub Ball_Rolling_Sounds_Start
Ball_Rolling_Sound_Settings
if BallRolling_Sound_Enabled = true then BallRolling_Update_Timer.set True, 100
AddDebugText "Ball Rolling Sound enabled: " & BallRolling_Sound_Enabled
End Sub
Sub Timer1_Expired
Dim Ball
Set Ball = XBAM.BallCloseTo(367, 280, 6)
If Ball.Position.X > 456 And Ball.Position.Y < 180 Then Exit Sub
Select Case FlagRamp
Case 0: If Ball.Position.Z < 18 Then Exit Sub ' we are always on the playfield
FlagRamp = 1
BallRolling_Sound = BallRolling_Sound2 ' then we change the ball rolling sound
adddebugtext "We access the ramp " &FlagRamp &" " &BallRolling_Sound
Case 1: If Ball.Position.Z > 18 Then Exit Sub ' we are always on the ramp
FlagRamp = 0
BallRolling_Sound = BallRolling_Sound1 ' so we have to restore the normal rolling sound
adddebugtext "We leave the ramp "&FlagRamp &" " &BallRolling_Sound
End Select
Ball.ExtFloat3 = 3: BallRolling_Update_Timer_Expired ' we change the ball to not yet tracked (ExtFloat3 = 0) and we update the sound
End Sub
Ball_Rolling_Sounds_Start 'start Ball Rolling Sounds
' ################## END OF BALL ROLLING SOUNDS - FP ##################