diff --git a/[gameplay]/internetradio/config/SRadioConfig.lua b/[gameplay]/internetradio/config/SRadioConfig.lua index 4bfae1e9c..02648c32f 100644 --- a/[gameplay]/internetradio/config/SRadioConfig.lua +++ b/[gameplay]/internetradio/config/SRadioConfig.lua @@ -4,4 +4,6 @@ -- ## Version: 1.0 ## -- ####################################### -RADIO_BOX_MODEL = 2229 \ No newline at end of file +RADIO_BOX_MODEL = 2229 +RADIO_DESTROY_ON_VEHICLE_EXPLODE = false +RADIO_DESTROY_ON_VEHICLE_DESTROY = false \ No newline at end of file diff --git a/[gameplay]/internetradio/handle_radio/SHandleRadio.lua b/[gameplay]/internetradio/handle_radio/SHandleRadio.lua index 5bb618fe4..1c819a741 100644 --- a/[gameplay]/internetradio/handle_radio/SHandleRadio.lua +++ b/[gameplay]/internetradio/handle_radio/SHandleRadio.lua @@ -37,6 +37,12 @@ function clearPlayerSpeaker(playerOrSpeaker) local matchingElement = (playerElement == playerOrSpeaker) or (speakerBox == playerOrSpeaker) if (matchingElement) then + local boxElement = isElement(speakerBox) + + if (boxElement) then + destroyElement(speakerBox) + end + playerSpeakers[playerElement] = nil return true @@ -87,6 +93,12 @@ function onServerCreateSpeaker(streamURL) setElementDimension(boxElement, playerDimension) setElementCollisionsEnabled(boxElement, false) + local playerVehicle = isPedInVehicle(client) and getPedOccupiedVehicle(client) + + if (playerVehicle) then + attachElements(boxElement, playerVehicle, -0.7, -1.5, -0.1, 0, 90, 0) + end + local speakerData = { speakerBox = boxElement, speakerStreamURL = streamURL, @@ -167,4 +179,39 @@ function clearSpeakersOnDestroyQuit() clearPlayerSpeaker(source) end addEventHandler("onPlayerQuit", root, clearSpeakersOnDestroyQuit) -addEventHandler("onElementDestroy", resourceRoot, clearSpeakersOnDestroyQuit) \ No newline at end of file +addEventHandler("onElementDestroy", resourceRoot, clearSpeakersOnDestroyQuit) + +function destroyAttachedRadioOnVehicleExplodeOrDestroy() + local validElement = isElement(source) + + if (not validElement) then + return false + end + + local elementType = getElementType(source) + local vehicleType = (elementType == "vehicle") + + if (not vehicleType) then + return false + end + + local attachedElements = getAttachedElements(source) + + for attachedID = 1, #attachedElements do + local attachedElement = attachedElements[attachedID] + local attachedElementType = getElementType(attachedElement) + local attachedElementObject = (attachedElementType == "object") + + if (attachedElementObject) then + clearPlayerSpeaker(attachedElement) + end + end +end + +if (RADIO_DESTROY_ON_VEHICLE_EXPLODE) then + addEventHandler("onVehicleExplode", root, destroyAttachedRadioOnVehicleExplodeOrDestroy) +end + +if (RADIO_DESTROY_ON_VEHICLE_DESTROY) then + addEventHandler("onElementDestroy", root, destroyAttachedRadioOnVehicleExplodeOrDestroy) +end \ No newline at end of file