From b60b52a2c0a8c39bd4866981f8bacfc61e2033f6 Mon Sep 17 00:00:00 2001 From: Vortrex <3858226+VortrexFTW@users.noreply.github.com> Date: Fri, 27 Aug 2021 18:45:56 -0500 Subject: [PATCH] Add biz/house toggleable interior lights --- scripts/client/event.js | 2 +- scripts/client/main.js | 4 +++ scripts/client/server.js | 19 +++++++++++--- scripts/client/utilities.js | 14 +++++++++- scripts/server/business.js | 51 ++++++++++++++++++++++++++++++++----- scripts/server/command.js | 14 +++++++--- scripts/server/misc.js | 17 +++++++++++++ 7 files changed, 105 insertions(+), 16 deletions(-) diff --git a/scripts/client/event.js b/scripts/client/event.js index 7a8bd575..a99a7eed 100644 --- a/scripts/client/event.js +++ b/scripts/client/event.js @@ -92,7 +92,6 @@ function onProcess(event, deltaTime) { processJobRouteSphere(); forceLocalPlayerEquippedWeaponItem(); processWantedLevelReset(); - processGameSpecifics(); } @@ -120,6 +119,7 @@ function onDrawnHUD(event) { processItemActionRendering(); processSkinSelectRendering(); processNameTagRendering(); + processInteriorLightsRendering(); } // =========================================================================== diff --git a/scripts/client/main.js b/scripts/client/main.js index 3cc12254..99d664d1 100644 --- a/scripts/client/main.js +++ b/scripts/client/main.js @@ -25,6 +25,7 @@ let renderSmallGameMessage = true; let renderScoreBoard = true; let renderHotBar = true; let renderItemActionDelay = true; +let renderInteriorLights = true; let logLevel = LOG_ALL; @@ -50,4 +51,7 @@ let forcedAnimation = null; let calledDeathEvent = false; +let interiorLightsEnabled = true; +let interiorLightsColour = toColour(0, 0, 0, 150); + // =========================================================================== \ No newline at end of file diff --git a/scripts/client/server.js b/scripts/client/server.js index 911f39cf..41e183ee 100644 --- a/scripts/client/server.js +++ b/scripts/client/server.js @@ -76,19 +76,18 @@ function addAllNetworkHandlers() { addNetworkHandler("vrr.veh.lights", toggleVehicleLights); addNetworkHandler("vrr.veh.engine", toggleVehicleEngine); + addNetworkHandler("vrr.veh.repair", repairVehicle); addNetworkHandler("vrr.veh.sync", syncVehicleProperties); addNetworkHandler("vrr.civ.sync", syncCivilianProperties); addNetworkHandler("vrr.plr.sync", syncPlayerProperties); addNetworkHandler("vrr.obj.sync", syncObjectProperties); - addNetworkHandler("vrr.veh.repair", repairVehicle); - addNetworkHandler("vrr.pedAnim", makePedPlayAnimation); - addNetworkHandler("vrr.hideAllGUI", hideAllGUI); - addNetworkHandler("vrr.gameScript", setGameScriptState); + addNetworkHandler("vrr.clientInfo", serverRequestedClientInfo); + addNetworkHandler("vrr.interiorLights", updateInteriorLightsState); } // =========================================================================== @@ -267,4 +266,16 @@ function setGameScriptState(scriptName, state) { } } +// =========================================================================== + +function serverRequestedClientInfo() { + sendServerClientInfo(); +} + +// =========================================================================== + +function updateInteriorLightsState(state) { + interiorLightsEnabled = state; +} + // =========================================================================== \ No newline at end of file diff --git a/scripts/client/utilities.js b/scripts/client/utilities.js index 8e73b3a6..83c6f7d6 100644 --- a/scripts/client/utilities.js +++ b/scripts/client/utilities.js @@ -684,4 +684,16 @@ function getLocalPlayerLookAtPosition() { let centerCameraPos = getWorldFromScreenPosition(toVector3(game.width/2, game.height/2, 0)); return getWorldFromScreenPosition(toVector3(game.width/2, game.height/2, getDistance(centerCameraPos, localPlayer.position)+20)); } -} \ No newline at end of file +} + +// =========================================================================== + +function processInteriorLightsRendering() { + if(renderInteriorLights) { + if(!interiorLightsEnabled) { + graphics.drawRectangle(null, toVector2(0.0, 0.0), toVector2(game.width, game.height), interiorLightsColour, interiorLightsColour, interiorLightsColour, interiorLightsColour); + } + } +} + +// =========================================================================== \ No newline at end of file diff --git a/scripts/server/business.js b/scripts/server/business.js index 9ace3e0a..5845e8b4 100644 --- a/scripts/server/business.js +++ b/scripts/server/business.js @@ -343,7 +343,7 @@ function setBusinessPublicCommand(command, params, client) { // =========================================================================== -function lockBusinessCommand(command, params, client) { +function lockUnlockBusinessCommand(command, params, client) { let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)); if(!areParamsEmpty(params)) { @@ -362,6 +362,33 @@ function lockBusinessCommand(command, params, client) { // =========================================================================== +/** + * This is a command handler function. + * + * @param {string} command - The command name used by the player + * @param {string} params - The parameters/args string used with the command by the player + * @param {Client} client - The client/player that used the command + * @return {bool} Whether or not the command was successful + * + */ + function toggleBusinessInteriorLightsCommand(command, params, client) { + let businessId = (isPlayerInAnyBusiness(client)) ? getPlayerBusiness(client) : getClosestBusinessEntrance(getPlayerPosition(client)); + + if(!getBusinessData(businessId)) { + messagePlayerError(client, "Business not found!"); + return false; + } + + getBusinessData(businessId).interiorLights = !getBusinessData(houseId).interiorLights; + + getBusinessData(businessId).needsSaved = true; + + updateBusinessInteriorLightsForOccupants(businessId); + messagePlayerMeAction(client, `turns ${getOnOffFromBool(getBusinessData(businessId).interiorLights)} the business lights`); +} + +// =========================================================================== + function setBusinessEntranceFeeCommand(command, params, client) { let splitParams = params.split(" "); let entranceFee = toInteger(splitParams[0]) || 0; @@ -466,7 +493,7 @@ function setBusinessInteriorTypeCommand(command, params, client) { getBusinessData(businessId).exitPosition = toVector3(0.0, 0.0, 0.0); getBusinessData(businessId).exitInterior = 0; getBusinessData(businessId).hasInterior = false; - messageAdmins(`${getInlineChatColourByName("lightGrey")}${getPlayerName(client)} ${getInlineChatColourByName("white")}remove business ${getInlineChatColourByType("businessBlue")}${getBusinessData(businessId).name} ${getInlineChatColourByName("white")}interior`); + messageAdmins(`${getInlineChatColourByName("lightGrey")}${getPlayerName(client)} ${getInlineChatColourByName("white")}removed business ${getInlineChatColourByType("businessBlue")}${getBusinessData(businessId).name} ${getInlineChatColourByName("white")}interior`); resetBusinessPickups(); resetBusinessBlips(); @@ -476,7 +503,7 @@ function setBusinessInteriorTypeCommand(command, params, client) { getBusinessData(businessId).exitInterior = getPlayerInterior(client); getBusinessData(businessId).exitDimension = getBusinessData(businessId).databaseId+getGlobalConfig().businessDimensionStart; getBusinessData(businessId).hasInterior = true; - messageAdmins(`${getInlineChatColourByName("lightGrey")}${getPlayerName(client)} ${getInlineChatColourByName("white")}remove business ${getInlineChatColourByType("businessBlue")}${getBusinessData(businessId).name} ${getInlineChatColourByName("white")}interior`); + messageAdmins(`${getInlineChatColourByName("lightGrey")}${getPlayerName(client)} ${getInlineChatColourByName("white")}removed business ${getInlineChatColourByType("businessBlue")}${getBusinessData(businessId).name} ${getInlineChatColourByName("white")}interior`); resetBusinessPickups(); resetBusinessBlips(); @@ -950,10 +977,11 @@ function saveBusinessToDatabase(businessId) { ["biz_exit_pos_z", tempBusinessData.exitPosition.z], ["biz_exit_rot_z", tempBusinessData.exitRotation], ["biz_exit_int", tempBusinessData.exitInterior], - ["biz_exit_vw", tempBusinessData.databaseId+getGlobalConfig().businessDimensionStart], + ["biz_exit_vw", tempBusinessData.exitDimension], ["biz_exit_pickup", tempBusinessData.exitPickupModel], ["biz_exit_blip", tempBusinessData.exitBlipModel], ["biz_has_interior", boolToInt(tempBusinessData.hasInterior)], + ["biz_interior_lights", boolToInt(tempBusinessData.interiorLights)], ]; let dbQuery = null; @@ -1031,7 +1059,7 @@ function createBusinessEntranceBlip(businessId) { blipModelId = getBusinessData(businessId).entranceBlipModel; } - getBusinessData(businessId).entranceBlip = createGameBlip(blipModelId, getBusinessData(businessId).entrancePosition, 1, getColourByName("businessBlue")); + getBusinessData(businessId).entranceBlip = createGameBlip(getBusinessData(businessId).entrancePosition, blipModelId, 1, getColourByName("businessBlue")); setElementOnAllDimensions(getBusinessData(businessId).entranceBlip, false); setElementDimension(getBusinessData(businessId).entranceBlip, getBusinessData(businessId).entranceDimension); //getBusinessData(businessId).entranceBlip.streamInDistance = 300; @@ -1082,7 +1110,7 @@ function createBusinessExitBlip(businessId) { blipModelId = getBusinessData(businessId).exitBlipModel; } - getBusinessData(businessId).exitBlip = createGameBlip(blipModelId, getBusinessData(businessId).exitPosition, 1, getColourByName("businessBlue")); + getBusinessData(businessId).exitBlip = createGameBlip(getBusinessData(businessId).exitPosition, blipModelId, 1, getColourByName("businessBlue")); setElementDimension(getBusinessData(businessId).exitBlip, getBusinessData(businessId).entranceDimension); setElementOnAllDimensions(getBusinessData(businessId).exitBlip, false); //getBusinessData(businessId).exitBlip.interior = getBusinessData(businessId).exitInterior; @@ -1637,4 +1665,15 @@ function clearPlayerBusinessGameScripts(client, businessId) { } } +// =========================================================================== + +function updateBusinessInteriorLightsForOccupants(businessId) { + let clients = getClients() + for(let i in clients) { + if(getPlayerBusiness(clients[i]) == businessId) { + updateInteriorLightsForPlayer(clients[i], getBusinessData(businessId).interiorLights); + } + } +} + // =========================================================================== \ No newline at end of file diff --git a/scripts/server/command.js b/scripts/server/command.js index d5ed18d2..f91d8afd 100644 --- a/scripts/server/command.js +++ b/scripts/server/command.js @@ -82,7 +82,8 @@ function loadCommands() { //commandData("delbizloc", deleteBusinessLocationCommand, "[id]", getStaffFlagValue("manageBusinesses"), true, false), commandData("bizreloadall", reloadAllBusinessesCommand, "", getStaffFlagValue("manageBusinesses"), true, false, "Reloads all businesses from the database"), - commandData("bizlock", lockBusinessCommand, "", getStaffFlagValue("none"), true, true, "Locks a business"), + commandData("bizlock", lockUnlockBusinessCommand, "", getStaffFlagValue("none"), true, true, "Locks a business"), + commandData("bizlights", toggleBusinessInteriorLightsCommand, "", getStaffFlagValue("none"), true, true, "Turns on/off a business's interior lights"), commandData("bizbuy", buyBusinessCommand, "", getStaffFlagValue("none"), true, true, "Purchases a business"), commandData("bizfee", setBusinessEntranceFeeCommand, "", getStaffFlagValue("none"), true, true, "Sets a fee to charge players when they enter the business."), commandData("biztill", viewBusinessTillAmountCommand, "", getStaffFlagValue("none"), true, true, "Shows the business's till (cash register) amount"), @@ -199,6 +200,7 @@ function loadCommands() { commandData("housebuy", buyHouseCommand, "", getStaffFlagValue("none"), true, false), commandData("housedesc", setHouseDescriptionCommand, "", getStaffFlagValue("manageHouses"), true, false), commandData("houselock", lockUnlockHouseCommand, "", getStaffFlagValue("none"), true, false), + commandData("houselights", toggleHouseInteriorLightsCommand, "", getStaffFlagValue("none"), true, false), commandData("houseowner", setHouseOwnerCommand, "", getStaffFlagValue("manageHouses"), true, false), commandData("housebuyprice", setHouseBuyPriceCommand, "", getStaffFlagValue("none"), true, false), commandData("houserentprice", setHouseRentPriceCommand, "", getStaffFlagValue("none"), true, false), @@ -295,9 +297,7 @@ function loadCommands() { 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)."), + commandData("admins", listOnlineAdminsCommand, "", getStaffFlagValue("none"), true, false, "Shows a list of online admins"), ], moderation: [ commandData("kick", kickClientCommand, " [reason]", getStaffFlagValue("basicModeration"), true, true, "Kicks a player from the server"), @@ -335,10 +335,16 @@ function loadCommands() { commandData("forceskin", forcePlayerSkinCommand, " ", getStaffFlagValue("basicModeration"), true, true, "Changes a character's skin directly."), + commandData("plrinfo", getPlayerInfoCommand, "", getStaffFlagValue("basicModeration"), true, true, "Shows basic info about the specified player"), commandData("getplrhouse", getAllHousesOwnedByPlayerCommand, "", getStaffFlagValue("basicModeration"), true, true, "Shows a list of all houses owned by the player"), commandData("getplrbiz", getAllBusinessesOwnedByPlayerCommand, "", getStaffFlagValue("basicModeration"), true, true, "Shows a list of all businesses owned by the player"), commandData("getplrveh", getAllVehiclesOwnedByPlayerCommand, "", getStaffFlagValue("basicModeration"), true, true, "Shows a list of all vehicles owned by the player"), ], + radio: [ + 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)."), + ], security: [], startup: [], subAccount: [ diff --git a/scripts/server/misc.js b/scripts/server/misc.js index 1226a931..23659c4e 100644 --- a/scripts/server/misc.js +++ b/scripts/server/misc.js @@ -153,6 +153,7 @@ function enterExitPropertyCommand(command, params, client) { clearPlayerHouseGameScripts(client, inHouse.index); getPlayerData(client).pedState = VRR_PEDSTATE_READY; }, 2000); + updateInteriorLightsForPlayer(client, true); }, 1000); }, 1100); removeEntityData(client, "vrr.inHouse"); @@ -194,6 +195,7 @@ function enterExitPropertyCommand(command, params, client) { clearPlayerBusinessGameScripts(client, inBusiness.index); getPlayerData(client).pedState = VRR_PEDSTATE_READY; }, 2000); + updateInteriorLightsForPlayer(client, true); }, 1000); }, 1100); removeEntityData(client, "vrr.inBusiness"); @@ -240,6 +242,7 @@ function enterExitPropertyCommand(command, params, client) { if(doesBusinessHaveAnyItemsToBuy(closestBusinessId)) { messagePlayerInfo(client, "Use /buy to purchase items from this business"); } + updateInteriorLightsForPlayer(client, closestBusiness.lights); setTimeout(function() { if(closestBusiness.streamingRadioStation != -1) { if(getPlayerData(client).streamingRadioStation != closestBusiness.streamingRadioStation) { @@ -288,6 +291,7 @@ function enterExitPropertyCommand(command, params, client) { fadeCamera(client, true, 1.0); } getPlayerData(client).pedState = VRR_PEDSTATE_READY; + updateInteriorLightsForPlayer(client, closestHouse.lights); setTimeout(function() { if(closestHouse.streamingRadioStation != -1) { if(getPlayerData(client).streamingRadioStation != closestHouse.streamingRadioStation) { @@ -394,4 +398,17 @@ function updateServerGameTime() { } } +// =========================================================================== + +function listOnlineAdminsCommand(command, params, client) { + let clients = getClients(); + for(let i in clients) { + if(getPlayerData(clients[i])) { + if(getPlayerData(clients[i]).accountData.flags.admin > 0) { + messagePlayerNormal(client, `• [${getPlayerData(clients[i]).accountData.staffTitle}] ${getCharacterFullName(clients[i])}`); + } + } + } +} + // =========================================================================== \ No newline at end of file