I’m using a cuff function in an updated Action Menu, credits to @WolfKnight179.
However, once they are uncuffed they cannot steer, any ideas why the player is staying cuffed.
Pretty sure this function was implemented by @rhys19
Client.lua
function GetPlayers()
local players = {}
for i = 0, 31 do
if NetworkIsPlayerActive(i) then
table.insert(players, i)
end
end
return players
end
function GetClosestPlayer()
local players = GetPlayers()
local closestDistance = -1
local closestPlayer = -1
local ply = GetPlayerPed(-1)
local plyCoords = GetEntityCoords(ply, 0)
for index,value in ipairs(players) do
local target = GetPlayerPed(value)
if(target ~= ply) then
local targetCoords = GetEntityCoords(GetPlayerPed(value), 0)
local distance = Vdist(targetCoords["x"], targetCoords["y"], targetCoords["z"], plyCoords["x"], plyCoords["y"], plyCoords["z"])
if(closestDistance == -1 or closestDistance > distance) then
closestPlayer = value
closestDistance = distance
end
end
end
return closestPlayer, closestDistance
end
function drawNotification(text)
SetNotificationTextEntry("STRING")
AddTextComponentString(text)
DrawNotification(false, false)
end
-------------------------------------]
local handCuffed = falseuff
local drag = false
local playerStillDragged = false
local officerDrag = -1
function cuff()
local t, distance = GetClosestPlayer()
if(distance ~= -1 and distance < 3) then
TriggerServerEvent("wk_actionmenu:cuffGranted", GetPlayerServerId(t))
else
drawNotification("Cuffed player")
end
end
RegisterNetEvent('wk_actionmenu:getArrested')
AddEventHandler('wk_actionmenu:getArrested', function()
handCuffed = not handCuffed
if(handCuffed) then
drawNotification("player cuffed")
else
drawNotification("Player uncuffed")
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(10)
if (handCuffed) then
RequestAnimDict('mp_arresting')
while not HasAnimDictLoaded('mp_arresting') do
Citizen.Wait(0)
end
local myPed = PlayerPedId(-1)
local animation = 'idle'
local flags = 49
while(IsPedBeingStunned(myPed, 0)) do
ClearPedTasksImmediately(myPed)
end
TaskPlayAnim(myPed, 'mp_arresting', animation, 8.0, -8, -1, flags, 0, 0, 0, 0)
end
if drag then
local ped = GetPlayerPed(GetPlayerFromServerId(officerDrag))
local myped = GetPlayerPed(-1)
AttachEntityToEntity(myped, ped, 4103, 11816, 0.48, 0.00, 0.0, 0.0, 0.0, 0.0, false, false, false, false, 2, true)
playerStillDragged = true
RequestAnimDict('mp_arresting')
while not HasAnimDictLoaded('mp_arresting') do
Citizen.Wait(0)
end
local myPed = PlayerPedId(-1)
local animation = 'idle'
local flags = 49
while(IsPedBeingStunned(myPed, 0)) do
ClearPedTasksImmediately(myPed)
end
TaskPlayAnim(myPed, 'mp_arresting', animation, 8.0, -8, -1, flags, 0, 0, 0, 0)
else
if(playerStillDragged) then
DetachEntity(GetPlayerPed(-1), true, false)
playerStillDragged = false
end
end
end
end)