-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Doesn't allow owners to exit a locked vehicle #51
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
local config = require 'config.client' | ||
local functions = require 'client.functions' | ||
local childLockEnabled = GetConvar('qbx:vehiclekeys:enablechildlock', 'true') == 'true' | ||
|
||
local hasKeys = functions.hasKeys | ||
local lockpickDoor = functions.lockpickDoor | ||
|
@@ -66,33 +67,38 @@ local function getVehicle() | |
return vehicle | ||
end | ||
|
||
---manages the opening of locks | ||
---Manages the opening of locks | ||
---@param vehicle number? The entity number of the vehicle. | ||
---@param state boolean? State of the vehicle lock. | ||
---@param anim any Aniation | ||
---@param anim any Animation | ||
local function setVehicleDoorLock(vehicle, state, anim) | ||
if not vehicle then return end | ||
if not isBlacklistedVehicle(vehicle) then | ||
if hasKeys(qbx.getVehiclePlate(vehicle)) or areKeysJobShared(vehicle) then | ||
|
||
if anim then | ||
lib.requestAnimDict('anim@mp_player_intmenu@key_fob@') | ||
TaskPlayAnim(cache.ped, 'anim@mp_player_intmenu@key_fob@', 'fob_click', 3.0, 3.0, -1, 49, 0, false, false, false) | ||
end | ||
|
||
TriggerServerEvent('InteractSound_SV:PlayWithinDistance', 5, 'lock', 0.3) | ||
NetworkRequestControlOfEntity(vehicle) | ||
|
||
local lockstate | ||
if state ~= nil then | ||
lockstate = state and 2 or 1 | ||
else | ||
lockstate = (GetVehicleDoorLockStatus(vehicle) % 2) + 1 -- (1 % 2) + 1 -> 2 (2 % 2) + 1 -> 1 | ||
local currentLockState = GetVehicleDoorLockStatus(vehicle) | ||
local isPedInVehicle = cache.vehicle == vehicle | ||
|
||
if childLockEnabled and isPedInVehicle and currentLockState == 4 then | ||
-- Check if the player is in the vehicle and the lock state is 4, then switch it to 1 | ||
lockstate = 1 | ||
else | ||
lockstate = isPedInVehicle and 4 or (currentLockState % 2) + 1 -- Use state 4 if the player is inside, otherwise 1 or 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will someone be able to get in the car while someone is sitting in? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if it locks on position 4 the car and closes for players who want to exit/enter the vehicle, I send you a video, I wait for a friend and I shoot the video. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if the locks are open and someone tries to sit as a passenger? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course, when the driver is already in the car. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mmmh thank you for making me think that I will adjust the code, I will adjust the code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to make some changes to qbx_smallresources |
||
end | ||
end | ||
|
||
TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(vehicle), lockstate) | ||
exports.qbx_core:Notify(locale(lockstate == 2 and 'notify.vehicle_locked' or 'notify.vehicle_unlocked')) | ||
|
||
exports.qbx_core:Notify(locale(lockstate == 1 and 'notify.vehicle_unlocked' or 'notify.vehicle_locked')) | ||
SetVehicleLights(vehicle, 2) | ||
Wait(250) | ||
SetVehicleLights(vehicle, 1) | ||
|
@@ -106,8 +112,7 @@ local function setVehicleDoorLock(vehicle, state, anim) | |
else | ||
TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(vehicle), 1) | ||
end | ||
end | ||
|
||
end | ||
exports('SetVehicleDoorLock', setVehicleDoorLock) | ||
|
||
local function getOtherPlayersInVehicle(vehicle) | ||
|
@@ -367,15 +372,28 @@ end) | |
---- Client Events ---- | ||
----------------------- | ||
|
||
RegisterKeyMapping('togglelocks', locale('info.toggle_locks'), 'keyboard', 'L') | ||
RegisterCommand('togglelocks', function() | ||
setVehicleDoorLock(getVehicle(), nil, true) | ||
end, false) | ||
|
||
RegisterKeyMapping('engine', locale('info.engine'), 'keyboard', 'G') | ||
RegisterCommand('engine', function() | ||
TriggerEvent('qb-vehiclekeys:client:ToggleEngine') | ||
end, false) | ||
local toggleLocksKeybind = lib.addKeybind({ | ||
name = 'vehicle_togglelocks', | ||
description = locale('info.toggle_locks'), | ||
defaultKey = 'L', | ||
onPressed = function(self) | ||
local vehicle = getVehicle() | ||
setVehicleDoorLock(vehicle, nil, true) | ||
end | ||
}) | ||
|
||
local engineKeybind = lib.addKeybind({ | ||
name = 'vehicle_engine', | ||
description = locale('info.engine'), | ||
defaultKey = 'G', | ||
onPressed = function(self) | ||
local vehicle = cache.vehicle | ||
if vehicle and hasKeys(qbx.getVehiclePlate(vehicle)) then | ||
local engineOn = GetIsVehicleEngineRunning(vehicle) | ||
SetVehicleEngineOn(vehicle, not engineOn, false, true) | ||
end | ||
end | ||
}) | ||
|
||
RegisterNetEvent('qb-vehiclekeys:client:ToggleEngine', function() | ||
local vehicle = cache.vehicle | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why should it be the default behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we disable it by default? (I find that for the roleplay action the default setting true is best)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#51 (review)