Action Menu Cuff Function

ok so ive been working/finding new functions for the action menu and i have the cuff one working but its cuffing me instead of the person in front of me send me Dm if you would know how to fix this and ill send you the function to look over it thanks!!

moved to: #development:scripts

Can you not just post the function in here?

i can hold on let me get it

–HandCuff start

local handcuffconfig = {
model = “prop_cs_cuffs_01”,
handcuffs = nil
}

–[[ HANDCUFF SCRIPT ]]–
RegisterNetEvent(“Handcuff”)
AddEventHandler(“Handcuff”, function()
local lPed = GetPlayerPed(-1)
if DoesEntityExist(lPed) then
if IsEntityPlayingAnim(lPed, “mp_arresting”, “idle”, 3) then
–DetachEntity(handcuffconfig.handcuffs, 0, 0)
–DeleteEntity(handcuffconfig.handcuffs)
–handcuffconfig.handcuffs = nil
ClearPedSecondaryTask(lPed)
SetEnableHandcuffs(lPed, false)
SetCurrentPedWeapon(lPed, GetHashKey(“WEAPON_UNARMED”), true)
else
RequestAnimDict(“mp_arresting”)
while not HasAnimDictLoaded(“mp_arresting”) do
Citizen.Wait(100)
end

		--RequestModel(GetHashKey(handcuffconfig.model))
		--while not HasModelLoaded(GetHashKey(handcuffconfig.model)) do
		--Citizen.Wait(100)
		--end

		--local plyCoords = GetEntityCoords(GetPlayerPed(PlayerId()), false)
		--handcuffconfig.handcuffs = CreateObject(GetHashKey(handcuffconfig.model), plyCoords.x, plyCoords.y, plyCoords.z, 1, 1, 1)

		--AttachEntityToEntity(handcuffconfig.handcuffs, GetPlayerPed(PlayerId()), GetPedBoneIndex(GetPlayerPed(PlayerId()), 60309), 0.0, 0.05, 0.0, 0.0, 0.0, 80.0, 1, 0, 0, 0, 0, 1)

		TaskPlayAnim(lPed, "mp_arresting", "idle", 8.0, -8, -1, 49, 0, 0, 0, 0)
		SetEnableHandcuffs(lPed, true)
		SetCurrentPedWeapon(lPed, GetHashKey("WEAPON_UNARMED"), true)
	end
end

end)

–Handcuff end

Pretty sure your error is here: local lPed = GetPlayerPed(-1) let me just check the natives real quick :stuck_out_tongue:

i was thinking the same but i cant or dont really know how to fix it!! but thanks

i appreciate it

20202020

Gets the closest ped in a radius.

Ped Types:
Any ped = -1
Player = 1
Male = 4
Female = 5
Cop = 6
Human = 26
SWAT = 27
Animal = 28
Army = 29

look i just found this -1 is any ped

Meaning it’ll select you as you’re the nearest? I’d try setting it to maybe 1?

i did try one already

I was looking for a facing native. But I don’t think there’s any.

ya this is weird becuz i press the button and it just cuffs me instead of the person im facing lol

Maybe use this?

https://runtime.fivem.net/doc/reference.html#_0xD71649DB0A545AA3

you know what someone that has this sent that to me awhile ago to use that so lemma see what he said to pic out of it and my only problem was i had a problem not knowing how to add it at the time lemme see what one he said to pick real quick

(nearest ped entity) thats the one he said to use

Okay, I think I got it? Maybe lol so, declare this function:

GetClosestPlayer

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

Then instead of using local lPed = GetPlayerPed(-1) use local lPed = GetClosestPlayer