Skip to content

Commit

Permalink
feat: handcuffing and dependency checks
Browse files Browse the repository at this point in the history
* fix(server/commands): usable

* feat(server/main): dependency and version checks

* fix(server/commands): job checks

* fix(server/main): missing table initiation

* feat: handcuffing

* fix(server): event name

* fix(client/interactions): adjust invBusy positioning

* fix(server/interactions): unhandcuffed event

* fix(client/interactions): remove wait for skillcheck

* feat: config option to consume handcuffs
  • Loading branch information
mafewtm authored Dec 13, 2024
1 parent 60b0b2e commit d4a5585
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 0 deletions.
100 changes: 100 additions & 0 deletions client/interactions.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
local disabledControls = {
21, -- Sprint
24, -- Attack
257, -- Attack 2
25, -- Aim
263, -- Melee Attack 1
45, -- Reload
22, -- Jump
44, -- Cover
37, -- Select Weapon
23, -- Enter vehicle
288, -- Disable phone
289, -- Inventory
170, -- Animations
167, -- Job
26, -- Disable looking behind
73, -- Disable clearing animation
199, -- Disable pause screen
59, -- Disable steering in vehicle
71, -- Disable driving forward in vehicle
72, -- Disable reversing in vehicle
36, -- Disable going stealth
264, -- Disable melee
257, -- Disable melee
140, -- Disable melee
141, -- Disable melee
142, -- Disable melee
143, -- Disable melee
75 -- Disable exit vehicle
}

lib.callback.register('qbx_police:client:getHandcuffed', function()
ClearPedTasksImmediately(cache.ped)
SetCurrentPedWeapon(cache.ped, `WEAPON_UNARMED`, true)
FreezeEntityPosition(cache.ped, true)

LocalPlayer.state.invBusy = true

local success = lib.skillCheck('medium')

lib.playAnim('mp_arrest_paired', 'crook_p2_back_right', 8.0, 8.0, 3750, 48, 0.0, false, 0, false)
Wait(3750)

if success then
lib.disableControls:Add(disabledControls)
lib.disableRadial(true)
else
LocalPlayer.state.invBusy = false
end

FreezeEntityPosition(cache.ped, false)

return not success
end)

RegisterNetEvent('qbx_police:client:handcuffPlayer', function()
SetCurrentPedWeapon(cache.ped, `WEAPON_UNARMED`, true)
FreezeEntityPosition(cache.ped, true)

lib.playAnim('mp_arrest_paired', 'cop_p2_back_right', 8.0, 8.0, 3750, 48, 0.0, false, 0, false)
Wait(3750)

FreezeEntityPosition(cache.ped, false)
end)

RegisterNetEvent('qbx_police:client:getUnhandcuffed', function()
FreezeEntityPosition(cache.ped, true)

lib.playAnim('mp_arresting', 'b_uncuff', 8.0, 8.0, 5500, 48, 0.0, false, 0, false)
Wait(5500)

lib.disableControls:Remove(disabledControls)
lib.disableRadial(false)

LocalPlayer.state.invBusy = false

FreezeEntityPosition(cache.ped, false)
end)

RegisterNetEvent('qbx_police:client:unhandcuffPlayer', function()
SetCurrentPedWeapon(cache.ped, `WEAPON_UNARMED`, true)
FreezeEntityPosition(cache.ped, true)

lib.playAnim('mp_arresting', 'a_uncuff', 8.0, 8.0, 3750, 48, 0.0, false, 0, false)
Wait(3750)

FreezeEntityPosition(cache.ped, false)
end)

CreateThread(function()
while LocalPlayer.state.handcuffed do
if not IsEntityPlayingAnim(cache.ped, 'mp_arresting', 'idle', 3) then
lib.playAnim('mp_arresting', 'idle', 8.0, 8.0, -1, 48, 0.0, false, 0, false)
end

lib.disableControls()

Wait(0)
end
end)
1 change: 1 addition & 0 deletions config/server.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
return {
consumeHandcuffs = true, -- If true, handcuffs will be consumed when putting someone in handcuffs and will be returned upon uncuffing them with a handcuff key
giveVehicleKeys = function(src, vehicle)
return exports.qbx_vehiclekeys:GiveKeys(src, vehicle)
end,
Expand Down
44 changes: 44 additions & 0 deletions server/interactions.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
local config = require 'config.server'

local function handcuff(source)
local playerPed = GetPlayerPed(source)
local playerCoords = GetEntityCoords(playerPed)
local targetId, _, _ = lib.getClosestPlayer(playerCoords, 1.0)

if not targetId or Player(targetId).state.handcuffed then return end

TriggerClientEvent('qbx_police:client:handcuffPlayer', source)

local targetCuffed = lib.callback.await('qbx_police:client:getHandcuffed', targetId)

if not targetCuffed then return end

if config.consumeHandcuffs then
exports.ox_inventory:RemoveItem(source, 'handcuffs', 1)
end

Player(targetId).state:set('handcuffed', true, true)
exports.qbx_core:SetMetadata(targetId, 'handcuffed', true)
end

exports.qbx_core:CreateUseableItem('handcuffs', handcuff)

local function unhandcuff(source)
local playerPed = GetPlayerPed(source)
local playerCoords = GetEntityCoords(playerPed)
local targetId, _, _ = lib.getClosestPlayer(playerCoords, 1.0)

if not targetId or not Player(targetId).state.handcuffed then return end

TriggerClientEvent('qbx_police:client:unhandcuffPlayer', source)
TriggerClientEvent('qbx_police:client:getUnhandcuffed', targetId)

if config.consumeHandcuffs then
exports.ox_inventory:AddItem(source, 'handcuffs', 1)
end

Player(targetId).state:set('handcuffed', true, true)
exports.qbx_core:SetMetadata(targetId, 'handcuffed', false)
end

exports.qbx_core:CreateUseableItem('handcuff_key', unhandcuff)
9 changes: 9 additions & 0 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ lib.callback.register('qbx_police:server:confiscateVehicle', function(source, ne
return true
end)

RegisterNetEvent('QBCore:Server:OnPlayerLoaded', function()
local src = source
local isHandcuffed = exports.qbx_core:GetMetadata(source, 'ishandcuffed')

if isHandcuffed then
Player(src).state:set('handcuffed', true, true)
end
end)

AddEventHandler('onServerResourceStart', function(resource)
if resource ~= cache.resource then return end

Expand Down

0 comments on commit d4a5585

Please sign in to comment.