@@ -37,6 +37,12 @@ function clearPlayerSpeaker(playerOrSpeaker)
3737 local matchingElement = (playerElement == playerOrSpeaker ) or (speakerBox == playerOrSpeaker )
3838
3939 if (matchingElement ) then
40+ local boxElement = isElement (speakerBox )
41+
42+ if (boxElement ) then
43+ destroyElement (speakerBox )
44+ end
45+
4046 playerSpeakers [playerElement ] = nil
4147
4248 return true
@@ -87,6 +93,12 @@ function onServerCreateSpeaker(streamURL)
8793 setElementDimension (boxElement , playerDimension )
8894 setElementCollisionsEnabled (boxElement , false )
8995
96+ local playerVehicle = isPedInVehicle (client ) and getPedOccupiedVehicle (client )
97+
98+ if (playerVehicle ) then
99+ attachElements (boxElement , playerVehicle , - 0.7 , - 1.5 , - 0.1 , 0 , 90 , 0 )
100+ end
101+
90102 local speakerData = {
91103 speakerBox = boxElement ,
92104 speakerStreamURL = streamURL ,
@@ -167,4 +179,39 @@ function clearSpeakersOnDestroyQuit()
167179 clearPlayerSpeaker (source )
168180end
169181addEventHandler (" onPlayerQuit" , root , clearSpeakersOnDestroyQuit )
170- addEventHandler (" onElementDestroy" , resourceRoot , clearSpeakersOnDestroyQuit )
182+ addEventHandler (" onElementDestroy" , resourceRoot , clearSpeakersOnDestroyQuit )
183+
184+ function destroyAttachedRadioOnVehicleExplodeOrDestroy ()
185+ local validElement = isElement (source )
186+
187+ if (not validElement ) then
188+ return false
189+ end
190+
191+ local elementType = getElementType (source )
192+ local vehicleType = (elementType == " vehicle" )
193+
194+ if (not vehicleType ) then
195+ return false
196+ end
197+
198+ local attachedElements = getAttachedElements (source )
199+
200+ for attachedID = 1 , # attachedElements do
201+ local attachedElement = attachedElements [attachedID ]
202+ local attachedElementType = getElementType (attachedElement )
203+ local attachedElementObject = (attachedElementType == " object" )
204+
205+ if (attachedElementObject ) then
206+ clearPlayerSpeaker (attachedElement )
207+ end
208+ end
209+ end
210+
211+ if (RADIO_DESTROY_ON_VEHICLE_EXPLODE ) then
212+ addEventHandler (" onVehicleExplode" , root , destroyAttachedRadioOnVehicleExplodeOrDestroy )
213+ end
214+
215+ if (RADIO_DESTROY_ON_VEHICLE_DESTROY ) then
216+ addEventHandler (" onElementDestroy" , root , destroyAttachedRadioOnVehicleExplodeOrDestroy )
217+ end
0 commit comments