Hey ya’ll! I have this code (see below) to cuff nearest player. However, as you can guess it’s not working! The code is going through, as I have received the notification, but the cuff aspect isn’t working. I am not receiving any errors either. Any help is godly. Thanks
RegisterNetEvent('cuffp')
AddEventHandler('cuffp', function()
closest, distance = GetClosestPlayer()
if closest ~= nil and DoesEntityExist(GetPlayerPed(closest)) then
if distance -1 and distance < 3 then
drawNotification('~g~ SUCCESS: ~w~You cuffed the nearest player. (' .. GetPlayerName(closest) .. ')')
local closestID = GetPlayerServerId(closest)
TriggerServerEvent('cuffServer', closestID)
else
drawNotification("~r~ ERROR: ~w~Nearest Player is too far away!")
end
end
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