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

feat: handcuffing and dependency checks #148

Merged
merged 10 commits into from
Dec 13, 2024
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
mafewtm marked this conversation as resolved.
Show resolved Hide resolved

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
2 changes: 1 addition & 1 deletion server/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ lib.addCommand('callsign', {
}, function(source, args)
local player = exports.qbx_core:GetPlayer(source)

if not player or player.PlayerData.job.type ~= 'leo' or player.PlayerData.job.type ~= 'ems' then return end
if not player or player.PlayerData.job.type ~= 'leo' and player.PlayerData.job.type ~= 'ems' then return end

player.Functions.SetMetaData('callsign', args.callsign)
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
mafewtm marked this conversation as resolved.
Show resolved Hide resolved

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)
14 changes: 14 additions & 0 deletions server/main.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
assert(lib.checkDependency('qbx_vehicles', '1.4.1', true))
assert(lib.checkDependency('qbx_garages', '1.1.3', true))
lib.versionCheck('Qbox-project/qbx_police')

local config = require 'config.server'
local sharedConfig = require 'config.shared'

Expand Down Expand Up @@ -38,6 +42,7 @@ end
lib.callback.register('qbx_police:server:spawnVehicle', function(source, vehicle, spawn)
local ped = GetPlayerPed(source)

vehicle.mods = vehicle.mods or {}
vehicle.mods.plate = vehicle.mods.plate or ('LSPD%s'):format(math.random(1000, 9999))

local netId, veh = qbx.spawnVehicle({
Expand Down Expand Up @@ -101,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
Loading