TimFL Posted December 15, 2018 Posted December 15, 2018 I've been looking for a way to disable the radio as smoothly as possible (so no sound cut-off or infinite loops anywhere), this is what Daniel Hartung (from Discord) and I came up with: Client-side (trigger this in your server-side playerEnterVehicle event, has to be triggered server-side cause the client-side variant triggers too early before the player is in the vehicle) const localPlayer = mp.players.local; let radioKillTimer = null; mp.game.audio.setUserRadioControlEnabled(false); mp.events.add("disableVehicleRadio", () => { if(radioKillTimer == null){ radioKillTimer = setInterval(() => { if(localPlayer.isSittingInAnyVehicle()){ mp.game.audio.setRadioToStationName("OFF"); clearInterval(radioKillTimer); radioKillTimer = null; return; } }, 100); } }); The custom client event checks whether a timer to kill the radio already exists, if not it creates one (interval 100ms) that runs until the local player entity reports the fact that they're sitting in a vehicle. That's when the radio is set to off and the timer is killed and it's ensured that the radio station is only set once (preventing jittery sound). 3
DevGrab Posted December 15, 2018 Posted December 15, 2018 why using server-resources when client-side only works. mp.game.audio.setRadioToStationName("OFF"); mp.game.audio.setUserRadioControlEnabled(false); mp.events.add("render", () => { if (mp.players.local.vehicle) { mp.game.audio.setRadioToStationName("OFF"); mp.game.audio.setUserRadioControlEnabled(false); } }); 1
TimFL Posted December 15, 2018 Author Posted December 15, 2018 8 hours ago, DevGrab said: why using server-resources when client-side only works. mp.game.audio.setRadioToStationName("OFF"); mp.game.audio.setUserRadioControlEnabled(false); mp.events.add("render", () => { if (mp.players.local.vehicle) { mp.game.audio.setRadioToStationName("OFF"); mp.game.audio.setUserRadioControlEnabled(false); } }); Because you're setting the stations once every render tick, and setting the radio has that sideeffect of jittery sound/radio frequency searching sound playing 247. Tried several ways of doing it, even with a render version (that works similar to the one in the first post) but this is the best/least resource intensive way we could come up with. 1
DevGrab Posted December 17, 2018 Posted December 17, 2018 Am 15.12.2018 um 21:29 schrieb TimFL: Because you're setting the stations once every render tick, and setting the radio has that sideeffect of jittery sound/radio frequency searching sound playing 247. Tried several ways of doing it, even with a render version (that works similar to the one in the first post) but this is the best/least resource intensive way we could come up with. nope, works fine.
Flow Posted December 22, 2018 Posted December 22, 2018 just tested it. it seems like when you are unsing JS to detect playerEnterVehicle the solution of DevGrab is the right one. On C# (i did not test it but tim) it's tim's solution which is better. just want to let you know
Tiny22 Posted September 5, 2020 Posted September 5, 2020 I once did the two on the server and it works so I uploaded them to you. Have fun https://mega.nz/file/v8cCTAAK#T1GSlfuGpR5T1FKNJLRdpHMXowvO3xypu7pXSUQZi_o
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now