-
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
Conversation
addition of the check if the players are in the vehicle if yes lock on position 4 to lock the vehicle from the inside
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.
This seems counterintuitive to what most players expect with fivem vehicle keys. I gather that lock state 4 requires the vehicle to be unlocked before someone can get out aka like child safety locks on the back seat of most modern vehicles. Additionally we should be using cache.vehicle
to check the vehicle of the player.
If we want to add something like this it should be configurable with the default off for those that want the "vanilla" experience.
suggest how you see the code? local function isChildLockEnabled()
return GetConvar('qbx:vehicleKeys:enableChildLock', 'false') == 'true'
end
--- 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 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
local currentLockState = GetVehicleDoorLockStatus(vehicle)
local isPedInVehicle = cache.vehicle == vehicle
if isChildLockEnabled() 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
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'))
SetVehicleLights(vehicle, 2)
Wait(250)
SetVehicleLights(vehicle, 1)
Wait(200)
SetVehicleLights(vehicle, 0)
Wait(300)
ClearPedTasks(cache.ped)
else
exports.qbx_core:Notify(locale('notify.no_keys'), 'error')
end
else
TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(vehicle), 1)
end
end |
It's easier to review code if you commit the changes to the branch rather than ask us to review a comment. I think you are going in the right direction though. We generally use all lowercase for convars as well as store them in a local variable at the top of the file rather than retrieve via function. |
client/main.lua
Outdated
description = locale('info.engine'), | ||
defaultKey = 'G', | ||
onPressed = function(self) | ||
TriggerEvent('qb-vehiclekeys:client:ToggleEngine') |
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.
Consider using a function instead of an event.
code quality adjustment
code tested ✅ |
@@ -4,6 +4,7 @@ | |||
|
|||
local config = require 'config.client' | |||
local functions = require 'client.functions' | |||
local childLockEnabled = GetConvar('qbx:vehiclekeys:enablechildlock', 'true') == 'true' |
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.
-- 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 comment
The 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 comment
The 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 comment
The 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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to make some changes to qbx_smallresources
Closing as author has not been responsive. Feel free to re-open. |
addition of the check if the players are in the vehicle if yes lock on position 4 to lock the vehicle from the inside