-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: open bugs with carjacking (#106)
* chore: remove duplicated classes * perf: load module when we need to * fix: hot wiring/searching for keys causes ped to leave car occasionally * fix: carjacking ped will just return to their car once car jack is done, ped should run away in fear * chore: ped leaves vehicle without closing the door which is realistic, and why wait? * fix: this makes ped doesn't leave the car, so we stop carjacking when progress finish * perf: code improvements * fix: findKeysChance is always a number * perf: we don't need this * docs: available vehicle types and categories with examples * fix: prevent from executing the file twice, we use require * fix: this throw error vehicle being 0, so we need to check * Revert "fix: hot wiring/searching for keys causes ped to leave car occasionally" This reverts commit 3f24871.
- Loading branch information
Showing
7 changed files
with
56 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,14 +11,15 @@ local toggleEngine = functions.toggleEngine | |
local lockpickDoor = functions.lockpickDoor | ||
local areKeysJobShared = functions.areKeysJobShared | ||
local getVehicleInFront = functions.getVehicleInFront | ||
local getIsCloseToCoords = functions.getIsCloseToCoords | ||
local getIsVehicleShared = functions.getIsVehicleShared | ||
local getNPCPedsInVehicle = functions.getNPCPedsInVehicle | ||
local sendPoliceAlertAttempt = functions.sendPoliceAlertAttempt | ||
local getIsVehicleAccessible = functions.getIsVehicleAccessible | ||
local getIsBlacklistedWeapon = functions.getIsBlacklistedWeapon | ||
|
||
local getIsVehicleShared = sharedFunctions.getIsVehicleShared | ||
local getIsCloseToCoords = sharedFunctions.getIsCloseToCoords | ||
local getIsBlacklistedWeapon = sharedFunctions.getIsBlacklistedWeapon | ||
local getIsVehicleAlwaysUnlocked = sharedFunctions.getIsVehicleAlwaysUnlocked | ||
local getIsVehicleCarjackingImmune = functions.getIsVehicleCarjackingImmune | ||
local getIsVehicleCarjackingImmune = sharedFunctions.getIsVehicleCarjackingImmune | ||
|
||
----------------------- | ||
---- Functions ---- | ||
|
@@ -36,12 +37,9 @@ local function setVehicleDoorLock(vehicle, state, anim) | |
lib.playAnim(cache.ped, 'anim@mp_player_intmenu@key_fob@', 'fob_click', 3.0, 3.0, -1, 49) | ||
end | ||
|
||
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 | ||
end | ||
local lockstate = state ~= nil | ||
and (state and 2 or 1) | ||
or (GetVehicleDoorLockStatus(vehicle) % 2) + 1 -- use ternary | ||
|
||
TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(vehicle), lockstate) | ||
exports.qbx_core:Notify(locale(lockstate == 2 and 'notify.vehicle_locked' or 'notify.vehicle_unlocked')) | ||
|
@@ -81,7 +79,7 @@ local function findKeys(vehicleModel, vehicleClass, plate, vehicle) | |
combat = true, | ||
} | ||
}) then | ||
if math.random() <= vehicleConfig.findKeysChance[vehicle] then | ||
if math.random() <= vehicleConfig.findKeysChance then | ||
TriggerServerEvent('qb-vehiclekeys:server:AcquireVehicleKeys', plate) | ||
return true | ||
else | ||
|
@@ -145,6 +143,8 @@ local function makePedFlee(ped) | |
ClearPedTasks(ped) | ||
SetPedFleeAttributes(ped, 0, false) | ||
TaskReactAndFleePed(ped, cache.ped) | ||
TaskSmartFleePed(ped, cache.ped, 100.0, -1, false, false) | ||
ResetPedLastVehicle(ped) -- make ped forget about his last car, so he cant return to it | ||
end | ||
|
||
local function makePedsPutHandsUpAndScream(occupants, vehicle) | ||
|
@@ -166,8 +166,7 @@ local function onCarjackSuccess(occupants, vehicle) | |
for p = 1, #occupants do | ||
local ped = occupants[p] | ||
CreateThread(function() | ||
Wait(math.random(100, 500)) | ||
TaskLeaveVehicle(ped, vehicle, 0) | ||
TaskLeaveVehicle(ped, vehicle, 256) -- flag 256 to leave door open | ||
PlayPain(ped, 6, 0) | ||
Wait(1250) | ||
PlayPain(ped, math.random(7, 8), 0) | ||
|
@@ -221,6 +220,7 @@ local function carjackVehicle(driver, vehicle) | |
}) then | ||
if cache.weapon and isCarjacking then | ||
local carjackChance = config.carjackChance[GetWeapontypeGroup(cache.weapon) --[[@as string]]] or 0.5 | ||
isCarjacking = false -- make this false to stop TaskVehicleTempAction from preventing ped to leave the car | ||
|
||
if math.random() <= carjackChance then | ||
onCarjackSuccess(occupants, vehicle) | ||
|
@@ -378,8 +378,8 @@ AddEventHandler('ox_lib:cache:vehicle', function() | |
showHotwiringLabel(cache.vehicle) | ||
end) | ||
|
||
lib.onCache('vehicle', function (vehicle) ---for some reason the autolock works with this | ||
end) | ||
-- lib.onCache('vehicle', function (vehicle) ---for some reason the autolock works with this | ||
-- end) | ||
|
||
for _, info in pairs(config.sharedKeys) do | ||
if info.enableAutolock then | ||
|
@@ -414,6 +414,10 @@ AddEventHandler('onResourceStart', function(resourceName) | |
end | ||
end) | ||
|
||
RegisterNetEvent('qb-vehiclekeys:client:GiveKeys', function(id, plate) | ||
require 'client.commands'(id, plate) -- we load command module when we actually need it | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
BerkieBb
Contributor
|
||
end) | ||
|
||
--#region Backwards Compatibility ONLY -- Remove at some point -- | ||
RegisterNetEvent('qb-vehiclekeys:client:AddKeys', function(plate) | ||
TriggerServerEvent('qb-vehiclekeys:server:AcquireVehicleKeys', plate) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Reloading the file each time for a command seems very weird to me. Why would you do that?