From 901f150efd61acc2a8aaf6c5c017bff719b85637 Mon Sep 17 00:00:00 2001 From: Vortrex <3858226+VortrexFTW@users.noreply.github.com> Date: Tue, 20 Apr 2021 21:34:04 -0500 Subject: [PATCH] Radio stream and volume funcs --- scripts/server/radio.js | 71 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/scripts/server/radio.js b/scripts/server/radio.js index 31701ba4..17f8d8ca 100644 --- a/scripts/server/radio.js +++ b/scripts/server/radio.js @@ -43,4 +43,75 @@ function loadRadioStationsFromDatabase() { return tempRadioStations; } +// =========================================================================== + +function playStreamingRadioCommand(command, params, client) { + if(areParamsEmpty(params)) { + messagePlayerSyntax(client, getCommandSyntaxText(command)); + return false; + } + + let radioStationId = params; + + if(radioStationId != 0 && typeof radioStations[radioStationId-1] == "undefined") { + messagePlayerError(client, "That radio station ID does not exist!"); + return false; + } + + if(!isPlayerInAnyVehicle(client)) { + + } + + if(!getVehicleData(getPlayerVehicle(client))) { + messagePlayerError(client, "This is a random traffic vehicle and commands can't be used for it."); + return false; + } + + if(radioStationId == 0) { + getVehicleData(getPlayerVehicle(client)).streamingRadioStation = -1; + getPlayerData(client).streamingRadioStation = -1; + meActionToNearbyPlayers(client, `turns off their vehicle's radio`); + + let clients = getClients(); + for(let i in clients) { + if(getPlayerVehicle(client) == getPlayerVehicle(clients[i])) { + playRadioStreamForPlayer(clients[i], ""); + } + } + return false; + } + + getVehicleData(getPlayerVehicle(client)).streamingRadioStation = radioStationId-1; + getPlayerData(client).streamingRadioStation = radioStationId-1; + meActionToNearbyPlayers(client, `changes their vehicle's radio station to ${radioStations[radioStationId-1].name}`); + + let clients = getClients(); + for(let i in clients) { + if(getPlayerVehicle(client) == getPlayerVehicle(clients[i])) { + playRadioStreamForPlayer(clients[i], radioStations[radioStationId-1].url); + setPlayerStreamingRadioVolume(client, getPlayerData(client).streamingRadioVolume); + } + } +} + +// =========================================================================== + +function setStreamingRadioVolumeCommand(command, params, client) { + if(areParamsEmpty(params)) { + messagePlayerSyntax(client, getCommandSyntaxText(command)); + return false; + } + + let volumeLevel = params; + + if(isNaN(volumeLevel)) { + messagePlayerError(client, "Volume level must a number"); + return false; + } + + setPlayerStreamingRadioVolume(client, toInteger(volumeLevel)/100); + getPlayerData(client).streamingRadioVolume = toInteger(volumeLevel)/100; + messagePlayerSuccess(client, `You set your streaming radio volume to ${volumeLevel}`); +} + // =========================================================================== \ No newline at end of file