Skip to content

Commit

Permalink
fix(client): alarm consistency feat(client): re-did vehicle locking/u…
Browse files Browse the repository at this point in the history
…nlocking exports

Should be a fix for the alarm constantly going off at times as well as at the wrong time + Exports for locking and unlocking the door with effects.
  • Loading branch information
l-404-l authored Apr 16, 2024
1 parent dc65129 commit ecd3e77
Showing 1 changed file with 40 additions and 12 deletions.
52 changes: 40 additions & 12 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ end

RegisterKeyMapping('togglelocks', locale("info.toggle_locks"), 'keyboard', 'L')
RegisterCommand('togglelocks', function()
ToggleVehicleLocks(GetVehicle())
SetVehicleDoorLock(GetVehicle(), nil, true)
end)

RegisterKeyMapping('engine', locale("info.engine"), 'keyboard', 'G')
Expand Down Expand Up @@ -300,25 +300,33 @@ function AreKeysJobShared(veh)
return false
end

function ToggleVehicleLocks(veh)
function SetVehicleDoorLock(veh, state, anim)
if veh then
if not isBlacklistedVehicle(veh) then
if HasKeys(qbx.getVehiclePlate(veh)) or AreKeysJobShared(veh) then
local vehLockStatus = GetVehicleDoorLockStatus(veh)

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)
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(veh)
if vehLockStatus == 1 then
TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(veh), 2)
exports.qbx_core:Notify(locale("notify.vehicle_locked"), 'inform')
if state then
state = state == true and 2 or 1
TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(veh), state)
exports.qbx_core:Notify(state == 2 and locale("notify.vehicle_locked") or locale("notify.vehicle_unlocked"), 'inform')
else
TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(veh), 1)
exports.qbx_core:Notify(locale("notify.vehicle_unlocked"), 'inform')
if vehLockStatus == 1 then
TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(veh), 2)
exports.qbx_core:Notify(locale("notify.vehicle_locked"), 'inform')
else
TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(veh), 1)
exports.qbx_core:Notify(locale("notify.vehicle_unlocked"), 'inform')
end
end

SetVehicleLights(veh, 2)
Wait(250)
SetVehicleLights(veh, 1)
Expand All @@ -334,6 +342,7 @@ function ToggleVehicleLocks(veh)
end
end
end
exports("SetVehicleDoorLock", SetVehicleDoorLock)

function GetOtherPlayersInVehicle(vehicle)
local otherPeds = {}
Expand Down Expand Up @@ -378,10 +387,21 @@ function LockpickDoor(isAdvanced)
if #(pos - GetEntityCoords(vehicle)) > 2.5 then return end
if GetVehicleDoorLockStatus(vehicle) <= 0 then return end

SetVehicleAlarm(vehicle, true)
SetVehicleAlarmTimeLeft(vehicle, 2)

usingAdvanced = isAdvanced
lib.requestAnimDict('veh@break_in@0h@p_m_one@')
TaskPlayAnim(cache.ped, 'veh@break_in@0h@p_m_one@', "low_force_entry_ds", 3.0, 3.0, -1, 16, 0, false, false, false)
local success = lib.skillCheck({'easy', 'easy', {areaSize = 60, speedMultiplier = 1}, 'medium'}, {'1', '2', '3', '4'})
SetTimeout(10000, function()
if not DoesEntityExist(vehicle) then return end
if not IsEntityAVehicle(vehicle) then return end
if isCarjacking then return end
if IsVehicleAlarmActivated(vehicle) then
SetVehicleAlarm(vehicle, false)
end
end)
if success then
LockpickFinishCallback(success)
else
Expand Down Expand Up @@ -426,9 +446,17 @@ end
function Hotwire(vehicle, plate)
local hotwireTime = math.random(config.minHotwireTime, config.maxHotwireTime)
isHotwiring = true

SetVehicleAlarm(vehicle, true)
SetVehicleAlarmTimeLeft(vehicle, hotwireTime)
SetVehicleAlarmTimeLeft(vehicle, 2)

SetTimeout(hotwireTime * 2, function()
if not DoesEntityExist(vehicle) then return end
if not IsEntityAVehicle(vehicle) then return end
if isHotwiring then return end
if IsVehicleAlarmActivated(vehicle) then
SetVehicleAlarm(vehicle, false)
end
end)
if lib.progressCircle({
duration = hotwireTime,
label = locale("progress.searching_keys"),
Expand Down

0 comments on commit ecd3e77

Please sign in to comment.