From e17b43bf2f151d63eeadc1ee76439320b712c814 Mon Sep 17 00:00:00 2001 From: Vortrex <3858226+VortrexFTW@users.noreply.github.com> Date: Tue, 24 Aug 2021 20:36:02 -0500 Subject: [PATCH] Add radiostation and keybinds list --- scripts/server/class.js | 1 + scripts/server/command.js | 27 +++++++++++---------- scripts/server/keybind.js | 14 +++++++++++ scripts/server/radio.js | 50 +++++++++++++++++++++++++++++---------- 4 files changed, 67 insertions(+), 25 deletions(-) diff --git a/scripts/server/class.js b/scripts/server/class.js index 79f147a1..8594eb71 100644 --- a/scripts/server/class.js +++ b/scripts/server/class.js @@ -1240,6 +1240,7 @@ function initClassTable() { this.url = ""; this.genre = ""; this.codec = ""; + this.index = -1; if(dbAssoc) { this.databaseId = dbAssoc["radio_id"]; diff --git a/scripts/server/command.js b/scripts/server/command.js index f09c2269..d5ed18d2 100644 --- a/scripts/server/command.js +++ b/scripts/server/command.js @@ -280,23 +280,24 @@ function loadCommands() { commandData("jobreloadall", reloadAllJobsCommand, "", getStaffFlagValue("manageJobs"), true, false), ], keybind: [ - commandData("bindkey", addKeyBindCommand, " [params]", getStaffFlagValue("none"), true, false), - commandData("unbindkey", removeKeyBindCommand, "", getStaffFlagValue("none"), true, false), - //commandData("keybinds", showKeyBindCommands, "", getStaffFlagValue("none"), true, false), + commandData("bindkey", addKeyBindCommand, " [params]", getStaffFlagValue("none"), true, false, "Binds a key to a command and optional parameters"), + commandData("unbindkey", removeKeyBindCommand, "", getStaffFlagValue("none"), true, false, "Removes an existing keybind from your account"), + commandData("keybinds", showKeyBindListCommand, "", getStaffFlagValue("none"), true, false, "Shows a list of all your current keybinds"), ], locale: [], messaging: [], misc: [ - commandData("pos", getPositionCommand, "", getStaffFlagValue("basicModeration"), true, false), - commandData("idea", submitIdeaCommand, "", getStaffFlagValue("none"), true, true), - commandData("bug", submitBugReportCommand, "", getStaffFlagValue("none"), true, true), - commandData("enter", enterExitPropertyCommand, "", getStaffFlagValue("none"), true, true), - commandData("cursor", toggleMouseCursorCommand, "", getStaffFlagValue("none"), true, false), - commandData("mousecam", toggleMouseCameraCommand, "", getStaffFlagValue("none"), true, false), - commandData("yes", playerPromptAnswerYesCommand, "", getStaffFlagValue("none"), true, false), - commandData("no", playerPromptAnswerNoCommand, "", getStaffFlagValue("none"), true, false), - commandData("radiostation", playStreamingRadioCommand, "", getStaffFlagValue("none"), true, false), - commandData("radiovolume", setStreamingRadioVolumeCommand, "", getStaffFlagValue("none"), true, false), + commandData("pos", getPositionCommand, "", getStaffFlagValue("basicModeration"), true, false, "Shows your current coordinates"), + commandData("idea", submitIdeaCommand, "", getStaffFlagValue("none"), true, true, "Sends an suggestion/idea to the developers"), + commandData("bug", submitBugReportCommand, "", getStaffFlagValue("none"), true, true, "Submits a bug report"), + commandData("enter", enterExitPropertyCommand, "", getStaffFlagValue("none"), true, true, "Enters or exists a house/business"), + commandData("cursor", toggleMouseCursorCommand, "", getStaffFlagValue("none"), true, false, "Toggles cursor visibility"), + commandData("mousecam", toggleMouseCameraCommand, "", getStaffFlagValue("none"), true, false, "Toggles vehicle mouse camera for games that don't have it"), + commandData("yes", playerPromptAnswerYesCommand, "", getStaffFlagValue("none"), true, false, "Answers a prompt with YES"), + commandData("no", playerPromptAnswerNoCommand, "", getStaffFlagValue("none"), true, false, "Answers a prompt with NO"), + commandData("radiostation", playStreamingRadioCommand, "", getStaffFlagValue("none"), true, false, "Plays a radio station in your vehicle, house, or business (depending on which one you're in)"), + commandData("radiostations", showRadioStationListCommand, "", getStaffFlagValue("none"), true, false, "Shows a list of all available radio stations"), + commandData("radiovolume", setStreamingRadioVolumeCommand, "", getStaffFlagValue("none"), true, false, "Sets the radio streaming volume (for your game only)."), ], moderation: [ commandData("kick", kickClientCommand, " [reason]", getStaffFlagValue("basicModeration"), true, true, "Kicks a player from the server"), diff --git a/scripts/server/keybind.js b/scripts/server/keybind.js index c7f584de..281644f8 100644 --- a/scripts/server/keybind.js +++ b/scripts/server/keybind.js @@ -196,4 +196,18 @@ function loadKeyBindConfiguration() { return JSON.parse(keyBindConfigFile); } +// =========================================================================== + +function showKeyBindListCommand(command, params, client) { + let keybindList = getPlayerData(client).accountData.keyBinds.map(function(x) { return `${getInlineChatColourByName("lightGrey")}${toUpperCase(getKeyNameFromId(x.key))}: ${getInlineChatColourByName("white")}${x.commandString}`; }); + + let chunkedList = splitArrayIntoChunks(keybindList, 6); + + messagePlayerInfo(client, `${getInlineChatColourByType("clanOrange")}== ${getInlineChatColourByType("jobYellow")}Your Key Binds ${getInlineChatColourByType("clanOrange")}===========================`); + + for(let i in chunkedList) { + messagePlayerInfo(client, chunkedList[i].join(", ")); + } +} + // =========================================================================== \ No newline at end of file diff --git a/scripts/server/radio.js b/scripts/server/radio.js index a82047a7..4af0a57c 100644 --- a/scripts/server/radio.js +++ b/scripts/server/radio.js @@ -7,13 +7,10 @@ // TYPE: Server (JavaScript) // =========================================================================== -let radioStations = []; - -// =========================================================================== - function initRadioScript() { logToConsole(LOG_INFO, "[VRR.Radio]: Initializing radio script ..."); - radioStations = loadRadioStationsFromDatabase(); + getServerData().radioStations = loadRadioStationsFromDatabase(); + setRadioStationIndexes(); logToConsole(LOG_INFO, "[VRR.Radio]: Radio script initialized successfully!"); return true; } @@ -47,12 +44,13 @@ function loadRadioStationsFromDatabase() { function playStreamingRadioCommand(command, params, client) { if(areParamsEmpty(params)) { messagePlayerSyntax(client, getCommandSyntaxText(command)); + messagePlayerInfo(client, "Use /radiostations for a list of available radio stations."); return false; } let radioStationId = params; - if(radioStationId != 0 && typeof radioStations[radioStationId-1] == "undefined") { + if(radioStationId != 0 && typeof getServerData().radioStations[radioStationId-1] == "undefined") { messagePlayerError(client, "That radio station ID does not exist!"); return false; } @@ -79,12 +77,12 @@ function playStreamingRadioCommand(command, params, client) { getVehicleData(getPlayerVehicle(client)).streamingRadioStation = radioStationId-1; getPlayerData(client).streamingRadioStation = radioStationId-1; - meActionToNearbyPlayers(client, `changes their vehicle's radio station to ${radioStations[radioStationId-1].name} (${radioStations[radioStationId-1].genre})`); + meActionToNearbyPlayers(client, `changes their vehicle's radio station to ${getRadioStationData(radioStationId-1).name} (${getRadioStationData(radioStationId-1).genre})`); let clients = getClients(); for(let i in clients) { if(getPlayerVehicle(client) == getPlayerVehicle(clients[i])) { - playRadioStreamForPlayer(clients[i], radioStations[radioStationId-1].url, true, getPlayerStreamingRadioVolume(client)); + playRadioStreamForPlayer(clients[i], getRadioStationData(radioStationId-1).url, true, getPlayerStreamingRadioVolume(client)); } } } else { @@ -104,12 +102,12 @@ function playStreamingRadioCommand(command, params, client) { } else { getHouseData(houseId).streamingRadioStation = radioStationId-1; getPlayerData(client).streamingRadioStation = radioStationId-1; - meActionToNearbyPlayers(client, `changes their house radio station to ${radioStations[radioStationId-1].name} (${radioStations[radioStationId-1].genre})`); + meActionToNearbyPlayers(client, `changes their house radio station to ${getRadioStationData(radioStationId-1).name} (${getRadioStationData(radioStationId-1).genre})`); let clients = getClients(); for(let i in clients) { if(getEntityData(clients[i], "vrr.inHouse") == houseId) { - playRadioStreamForPlayer(clients[i], radioStations[radioStationId-1].url, true, getPlayerStreamingRadioVolume(clients[i])); + playRadioStreamForPlayer(clients[i], getRadioStationData(radioStationId-1).url, true, getPlayerStreamingRadioVolume(clients[i])); } } } @@ -129,12 +127,12 @@ function playStreamingRadioCommand(command, params, client) { } else { getBusinessData(businessId).streamingRadioStation = radioStationId-1; getPlayerData(client).streamingRadioStation = radioStationId-1; - meActionToNearbyPlayers(client, `changes the business radio station to ${radioStations[radioStationId-1].name} (${radioStations[radioStationId-1].genre})`); + meActionToNearbyPlayers(client, `changes the business radio station to ${getRadioStationData(radioStationId-1).name} (${getRadioStationData(radioStationId-1).genre})`); let clients = getClients(); for(let i in clients) { if(getEntityData(clients[i], "vrr.inBusiness") == businessId) { - playRadioStreamForPlayer(clients[i], radioStations[radioStationId-1].url, true, getPlayerStreamingRadioVolume(clients[i])); + playRadioStreamForPlayer(clients[i], getRadioStationData(radioStationId-1).url, true, getPlayerStreamingRadioVolume(clients[i])); } } } @@ -185,4 +183,32 @@ function getPlayerStreamingRadioVolume(client) { return getPlayerData(client).accountData.streamingRadioVolume; } +// =========================================================================== + +function showRadioStationListCommand(command, params, client) { + let stationList = getServerData().radioStations.map(function(x) { return `${getInlineChatColourByName("lightGrey")}${x.index}: ${getInlineChatColourByName("white")}${x.name}`; }); + + let chunkedList = splitArrayIntoChunks(stationList, 4); + + messagePlayerInfo(client, `${getInlineChatColourByType("clanOrange")}== ${getInlineChatColourByType("jobYellow")}Radio Stations ${getInlineChatColourByType("clanOrange")}===========================`); + + for(let i in chunkedList) { + messagePlayerInfo(client, chunkedList[i].join(", ")); + } +} + +// =========================================================================== + +function setRadioStationIndexes() { + for(let i in getServerData().radioStations) { + getServerData().radioStations[i].index = i; + } +} + +// =========================================================================== + +function getRadioStationData(radioStationId) { + return getServerData().radioStations[radioStationId]; +} + // =========================================================================== \ No newline at end of file