Skip to content
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

fix: Carjacking #59

Merged
merged 4 commits into from
Jun 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ local function setVehicleDoorLock(vehicle, state, anim)
if state ~= nil then
lockstate = state and 2 or 1
else
lockstate = (GetVehicleDoorLockStatus(vehicle) % 2) + 1 -- (1 % 2) + 1 -> 2 (2 % 2) + 1 -> 1
lockstate = (GetVehicleDoorLockStatus(vehicle) % 2) + 1 -- (1 % 2) + 1 -> 2 (2 % 2) + 1 -> 1
end

TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(vehicle), lockstate)
Expand Down Expand Up @@ -178,17 +178,23 @@ local function carjackVehicle(target)
if not config.carjackEnable then return end
isCarjacking = true
canCarjack = false
lib.requestAnimDict('mp_am_hold_up')
local vehicle = GetVehiclePedIsUsing(target)
local occupants = getPedsInVehicle(vehicle)

CreateThread(function ()
while isCarjacking do
TaskVehicleTempAction(occupants[1], vehicle, 6, 1)
Wait(0)
end
end)

for p = 1, #occupants do
local occupant = occupants[p]
CreateThread(function()
TaskPlayAnim(occupant, 'mp_am_hold_up', 'holdup_victim_20s', 8.0, -8.0, -1, 49, 0, false, false, false)
Wait(math.random(100, 600))
lib.playAnim(occupant, 'mp_am_hold_up', 'holdup_victim_20s', 8.0, -8.0, -1, 49, 0, false, false, false)
PlayPain(occupant, 6, 0)
end)

Wait(math.random(200, 500))
end

-- Cancel progress bar if: Ped dies during robbery, car gets too far away
Expand All @@ -215,19 +221,21 @@ local function carjackVehicle(target)
local hasWeapon, weaponHash = GetCurrentPedWeapon(cache.ped, true)
if hasWeapon and isCarjacking then
local carjackChance = 0.5
if config.carjackChance[tostring(GetWeapontypeGroup(weaponHash))] then
carjackChance = config.carjackChance[tostring(GetWeapontypeGroup(weaponHash))]
local chance = config.carjackChance[GetWeapontypeGroup(weaponHash) --[[@as string]]]
if chance then
carjackChance = chance
end

if math.random() <= carjackChance then
local plate = qbx.getVehiclePlate(vehicle)
for p = 1, #occupants do
local ped = occupants[p]
CreateThread(function()
Wait(math.random(100, 500))
TaskLeaveVehicle(ped, vehicle, 0)
PlayPain(ped, 6, 0)
Wait(1250)
ClearPedTasksImmediately(ped)
ClearPedTasks(ped)
PlayPain(ped, math.random(7, 8), 0)
makePedFlee(ped)
end)
Expand All @@ -236,6 +244,7 @@ local function carjackVehicle(target)
TriggerServerEvent('qb-vehiclekeys:server:AcquireVehicleKeys', plate)
else
exports.qbx_core:Notify(locale('notify.carjack_failed'), 'error')
ClearPedTasksImmediately(target)
makePedFlee(target)
TriggerServerEvent('hud:server:GainStress', math.random(1, 4))
end
Expand All @@ -246,6 +255,7 @@ local function carjackVehicle(target)
canCarjack = true
end
else
ClearPedTasksImmediately(target)
makePedFlee(target)
isCarjacking = false
Wait(config.delayBetweenCarjackingsInMs)
Expand Down