From 7d97e89d258f7dc7bbe2ec0f677e25aea3af92da Mon Sep 17 00:00:00 2001 From: HC DEV <36608116+ArturMichalak@users.noreply.github.com> Date: Wed, 17 Jul 2024 17:34:55 +0200 Subject: [PATCH] feat: toggleEngine and getIsVehicleAlwaysUnlocked (#88) --- client/functions.lua | 30 +++++++++++++++++++----------- client/main.lua | 17 ++++++++++++++++- locales/da.json | 2 +- server/functions.lua | 1 + 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/client/functions.lua b/client/functions.lua index 06707e6..bc58328 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -5,6 +5,7 @@ local getIsBlacklistedWeapon = functions.getIsBlacklistedWeapon local getIsVehicleAlwaysUnlocked = functions.getIsVehicleAlwaysUnlocked local getIsVehicleLockpickImmune = functions.getIsVehicleLockpickImmune local getIsVehicleCarjackingImmune = functions.getIsVehicleCarjackingImmune +local getIsVehicleTypeAlwaysUnlocked = functions.getIsVehicleTypeAlwaysUnlocked local alertSend = false local public = {} @@ -44,12 +45,22 @@ end exports('HasKeys', public.hasKeys) -function public.toggleEngine() - local vehicle = cache.vehicle - if vehicle and public.hasKeys(qbx.getVehiclePlate(vehicle)) then - local engineOn = GetIsVehicleEngineRunning(vehicle) - SetVehicleEngineOn(vehicle, not engineOn, false, true) - end +---Checks if player has vehicle keys of or access to the vehicle is provided as part of his job. +---@param vehicle number The entity number of the vehicle. +---@param plate string? The plate number of the vehicle. +---@return boolean? `true` if player has access to the vehicle, `nil` otherwise. +function public.getIsVehicleAccessible(vehicle, plate) + plate = plate or qbx.getVehiclePlate(vehicle) + return public.hasKeys(plate) or public.areKeysJobShared(vehicle) +end + +exports('HasAccess', public.getIsVehicleAccessible) + +function public.toggleEngine(vehicle) + local veh = vehicle or cache.vehicle + if not public.getIsVehicleAccessible(veh) then return end + local engineOn = GetIsVehicleEngineRunning(veh) + SetVehicleEngineOn(veh, not engineOn, false, true) end exports('ToggleEngine', public.toggleEngine) @@ -58,18 +69,15 @@ exports('ToggleEngine', public.toggleEngine) ---@param vehicle number The entity number of the vehicle. ---@return boolean? `true` if the vehicle is blacklisted, `nil` otherwise. function public.getIsVehicleAlwaysUnlocked(vehicle) - if Entity(vehicle).state.ignoreLocks or GetVehicleClass(vehicle) == 13 then - return true - end - return getIsVehicleAlwaysUnlocked(vehicle) + or getIsVehicleTypeAlwaysUnlocked(vehicle) end function public.getNPCPedsInVehicle(vehicle) local otherPeds = {} for seat = -1, GetVehicleModelNumberOfSeats(GetEntityModel(vehicle)) - 2 do local pedInSeat = GetPedInVehicleSeat(vehicle, seat) - if not IsPedAPlayer(pedInSeat) and pedInSeat ~= 0 then + if pedInSeat ~= 0 and not IsPedAPlayer(pedInSeat) then otherPeds[#otherPeds + 1] = pedInSeat end end diff --git a/client/main.lua b/client/main.lua index e3e7d6e..b476c6e 100644 --- a/client/main.lua +++ b/client/main.lua @@ -277,8 +277,9 @@ local function watchCarjackingAttempts() end ----------------------- ----- Client Events ---- +------ Key Binds ------ ----------------------- + local togglelocksBind togglelocksBind = lib.addKeybind({ name = 'togglelocks', @@ -297,6 +298,7 @@ engineBind = lib.addKeybind({ name = 'toggleengine', description = locale('info.engine'), defaultKey = 'G', + disabled = not cache.vehicle, onPressed = function() engineBind:disable(true) toggleEngine() @@ -305,6 +307,10 @@ engineBind = lib.addKeybind({ end }) +----------------------- +---- Client Events ---- +----------------------- + local isTakingKeys = false RegisterNetEvent('QBCore:Client:VehicleInfo', function(data) if not LocalPlayer.state.isLoggedIn or data.event ~= 'Entering' then return end @@ -339,6 +345,15 @@ RegisterNetEvent('lockpicks:UseLockpick', function(isAdvanced) end end) +RegisterNetEvent('qbx_vehiclekeys:client:OnLostKeys', function() + Wait(0) + showHotwiringLabel() +end) + +AddEventHandler('ox_lib:cache:seat', function() + showHotwiringLabel() +end) + AddEventHandler('ox_lib:cache:vehicle', function() showHotwiringLabel() end) diff --git a/locales/da.json b/locales/da.json index e9b9724..5741bba 100644 --- a/locales/da.json +++ b/locales/da.json @@ -21,7 +21,7 @@ }, "info": { "engine": "Tænd/sluk motor", - "search_keys": "~g~[H]~w~ - Søg efter nøgler", + "search_keys_dispatch": "[H] - Søg efter nøgler", "toggle_locks": "Lås/oplås køretøj", "vehicle_theft": "Køretøjstyveri i gang. Type: " }, diff --git a/server/functions.lua b/server/functions.lua index 75befac..b0ec3ba 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -101,6 +101,7 @@ function public.removeKeys(source, plate) Player(source).state:set('keysList', keys, true) + TriggerClientEvent('qbx_vehiclekeys:client:OnLostKeys', source) exports.qbx_core:Notify(source, locale('notify.keys_removed')) return true