Drag/Undrag command


#1

Hi guys, I’m trying to create a drag command to let a user to drag another user around the map, I tryied to use AttachEntityToEntity but the client ista-crash. Maybe I missed something about network control or something, can you help me to understand what I’m doing wrong?


[Release]Drag command
#2

You should post your code so we can see.


#3

I will do but don’t flame me :slight_smile:

Server Side:

RegisterNetEvent("es_roleplay:drag")
AddEventHandler('es_roleplay:drag', function(pl)
	Citizen.Trace('drag ' .. tostring(pl))
	local ped = GetPlayerPed(GetPlayerFromServerId(pl))
	local myped = GetPlayerPed(-1)
	AttachEntityToEntity(myped, ped, 24818, 0.54, 0.54, 0.0, 0.0, 0.0, 0.0, false, false, false, true, 2, true)
end)


Client Side

TriggerEvent('es:addCommand', 'drag', function(source, args, user)
	if(player_jobs[user.identifier] or (tonumber(user.permission_level) > 2))then
		local job = player_jobs[user.identifier]
		if(job)then
			job = player_jobs[user.identifier].job
		end
		if(groups.police[job] or tonumber(user.permission_level) > 2)then
		end
		if(#args < 2)then
			TriggerClientEvent('chatMessage', source, "JOB", {255, 0, 0}, "Usage: ^2/drag (ID)")
		else
			if(GetPlayerName(tonumber(args[2])))then
				TriggerEvent('es:getPlayerFromId', tonumber(args[2]), function(target)
					if(get3DDistance(target.coords.x, target.coords.y, target.coords.z, user.coords.x, user.coords.y, user.coords.z) > 10.0)then
						TriggerClientEvent('chatMessage', source, "JOB", {255, 0, 0}, "Please get closer to suspect.")
						return
					end
					if (cuffed[target.identifier])then
						TriggerClientEvent('es_roleplay:drag', -1, tonumber(args[2]))
					else
						TriggerClientEvent('chatMessage', source, "JOB", {255, 0, 0}, "Suspect is not cuffed.")
					end
				end)
			else
				TriggerClientEvent('chatMessage', source, "JOB", {255, 0, 0}, "Incorrect player ID")
			end
		end
	else
		TriggerClientEvent('chatMessage', source, "JOB", {255, 0, 0}, "You need to be police.")
	end
end)

[Release]Drag command
#5

nice it almost works almost there just something thats missing, cuz i get stuck to the person insteed of the otherway around. adn get Disconnected “FiveM stoped working”. but hope there will be a fix


#6

Have a look here

AttachEntityToEntity(entity1, entity2, boneIndex, xPos, yPos, zPos, xRot, yRot, zRot, p9, useSoftPinning, collision, isPed, vertexIndex, fixedRot)

Then find the pelvis bone ID here: https://pastebin.com/D7JMnX1g

Let me know how it goes, I dont have knowledge to make this myself, but have helped someone make a working version, but he decided to keep it under wraps and not share… hence no longer a friend.


#7

Do you put the bone ID where is says boneindex?


#8

Is this said script?
or do i still need that xpos, ypos

AttachEntityToEntity(entity1, entity2, SKEL_Pelvis, 4103, 11816, useSoftPinning, collision, isPed, vertexIndex, fixedRot)

#9

that I am not sure of, best to find some help from someone with more knowledge then me. If I was able to make this script myself it would of been released awhile ago.
Unfortunately my help is about what I posted here already.


#10

Have you got the drag command working?


#11

still tryin to fix it


#12

can someone please see if this is working this is one of the most important scripts the community needs now :confused:


#13

I’m looking into it myself atm xD


#14

Just hold tight, Cops script is working on a drag function.


#15

This has undrag and it makes it so you can’t drag yourself, but it still has the issue of attaching you to the player…so rip
I tried just switching ped and myped but of course its never that easy :smile:

Client

otherid = 0
drag = false
RegisterNetEvent("drag")
AddEventHandler('drag', function(pl)
	otherid = tonumber(pl)
	Citizen.Trace(tonumber(otherid))
	drag = not drag

end)

Citizen.CreateThread(function()
	while true do
		if drag then
			local ped = GetPlayerPed(GetPlayerFromServerId(otherid))
			local myped = GetPlayerPed(-1)
			AttachEntityToEntity(myped, ped, 11816, 0.54, 0.54, 0.0, 0.0, 0.0, 0.0, false, false, false, true, 2, true)
			--AttachEntityToEntityPhysically(myped, ped, 11816, 11816, 0.25, 0.25,  0.0, 0.25, 0.25, 0.0, 0.0, 0.0, 0.0, 0.0, true,  false, false, false, false)
		else
			DetachEntity(GetPlayerPed(-1), true, false)
		end
		Citizen.Wait(0)
	end
end)

Server

TriggerEvent('es:addCommand', 'drag', function(source, args, user)

	local playerIdentifier = getPlayerIdentifierEasyMode(source)
	local playerJob = getPlayerJob(playerIdentifier)
	local argument = args[2] 
	local savedsource = source
	print(savedsource)
	if argument == nil or type(tonumber(argument)) == nil then
	
		TriggerClientEvent("chatMessage", source, "SYSTEM", { 0, 141, 155 }, "example: /drag <id>")
		
	elseif playerJob ~= "cop" and playerJob ~= "sheriff" then
	
		TriggerClientEvent("chatMessage", source, "SYSTEM", { 0, 141, 155 }, "^3Civilians are not allowed to use /drag")
		
	else 
			
		if(GetPlayerName(tonumber(argument)))then
			TriggerEvent('es:getPlayerFromId', tonumber(argument), function(target)
				if argument == savedsource then
					TriggerClientEvent('chatMessage', source, "SYSTEM", { 0, 141, 155 }, "You cannot drag yourself.")
				else
					TriggerClientEvent("drag", source, tonumber(argument))
				end
			end)
		else
			TriggerClientEvent('chatMessage', source, "SYSTEM", { 0, 141, 155 }, "Incorrect player ID")
		end		
	end
end)

#16

My though is that AttachEntityToEntity is not good to attach two player because the API didn’t manage two network entity


#17

“BONENAME”,“BONETYPE”,“BONETAG”
“SKEL_ROOT”,“4215”,"0"
“SKEL_Pelvis”,“4103”,"11816"
“SKEL_L_Thigh”,“4103”,"58271"
“SKEL_L_Calf”,“4103”,"63931"
“SKEL_L_Foot”,“4103”,"14201"
“SKEL_L_Toe0”,“7”,"2108"
“IK_L_Foot”,“119”,"65245"
“PH_L_Foot”,“119”,"57717"
“MH_L_Knee”,“119”,"46078"
“SKEL_R_Thigh”,“4103”,"51826"
“SKEL_R_Calf”,“4103”,"36864"
“SKEL_R_Foot”,“4103”,"52301"
“SKEL_R_Toe0”,“7”,"20781"
“IK_R_Foot”,“119”,"35502"
“PH_R_Foot”,“119”,"24806"
“MH_R_Knee”,“119”,"16335"
“RB_L_ThighRoll”,“7”,"23639"
“RB_R_ThighRoll”,“7”,"6442"
“SKEL_Spine_Root”,“4103”,"57597"
“SKEL_Spine0”,“4103”,"23553"
“SKEL_Spine1”,“4103”,"24816"
“SKEL_Spine2”,“4103”,"24817"
“SKEL_Spine3”,“4103”,"24818"
“SKEL_L_Clavicle”,“4103”,"64729"
“SKEL_L_UpperArm”,“4103”,"45509"
“SKEL_L_Forearm”,“4215”,"61163"
“SKEL_L_Hand”,“4215”,"18905"
“SKEL_L_Finger00”,“4103”,"26610"
“SKEL_L_Finger01”,“4103”,"4089"
“SKEL_L_Finger02”,“7”,"4090"
“SKEL_L_Finger10”,“4103”,"26611"
“SKEL_L_Finger11”,“4103”,"4169"
“SKEL_L_Finger12”,“7”,"4170"
“SKEL_L_Finger20”,“4103”,"26612"
“SKEL_L_Finger21”,“4103”,"4185"
“SKEL_L_Finger22”,“7”,"4186"
“SKEL_L_Finger30”,“4103”,"26613"
“SKEL_L_Finger31”,“4103”,"4137"
“SKEL_L_Finger32”,“7”,"4138"
“SKEL_L_Finger40”,“4103”,"26614"
“SKEL_L_Finger41”,“4103”,"4153"
“SKEL_L_Finger42”,“7”,"4154"
“PH_L_Hand”,“119”,"60309"
“IK_L_Hand”,“119”,"36029"
“RB_L_ForeArmRoll”,“7”,"61007"
“RB_L_ArmRoll”,“7”,"5232"
“MH_L_Elbow”,“119”,"22711"
“SKEL_R_Clavicle”,“4103”,"10706"
“SKEL_R_UpperArm”,“4103”,"40269"
“SKEL_R_Forearm”,“4215”,"28252"
“SKEL_R_Hand”,“4215”,"57005"
“SKEL_R_Finger00”,“4103”,"58866"
“SKEL_R_Finger01”,“4103”,"64016"
“SKEL_R_Finger02”,“7”,"64017"
“SKEL_R_Finger10”,“4103”,"58867"
“SKEL_R_Finger11”,“4103”,"64096"
“SKEL_R_Finger12”,“7”,"64097"
“SKEL_R_Finger20”,“4103”,"58868"
“SKEL_R_Finger21”,“4103”,"64112"
“SKEL_R_Finger22”,“7”,"64113"
“SKEL_R_Finger30”,“4103”,"58869"
“SKEL_R_Finger31”,“4103”,"64064"
“SKEL_R_Finger32”,“7”,"64065"
“SKEL_R_Finger40”,“4103”,"58870"
“SKEL_R_Finger41”,“4103”,"64080"
“SKEL_R_Finger42”,“7”,"64081"
“PH_R_Hand”,“119”,"28422"
“IK_R_Hand”,“119”,"6286"
“RB_R_ForeArmRoll”,“7”,"43810"
“RB_R_ArmRoll”,“7”,"37119"
“MH_R_Elbow”,“119”,"2992"
“SKEL_Neck_1”,“4103”,"39317"
“SKEL_Head”,“4103”,"31086"
“IK_Head”,“119”,"12844"
“FACIAL_facialRoot”,“4103”,"65068"
“FB_L_Brow_Out_000”,“1799”,"58331"
“FB_L_Lid_Upper_000”,“1911”,"45750"
“FB_L_Eye_000”,“1799”,"25260"
“FB_L_CheekBone_000”,“1799”,"21550"
“FB_L_Lip_Corner_000”,“1911”,"29868"
“FB_R_Lid_Upper_000”,“1911”,"43536"
“FB_R_Eye_000”,“1799”,"27474"
“FB_R_CheekBone_000”,“1799”,"19336"
“FB_R_Brow_Out_000”,“1799”,"1356"
“FB_R_Lip_Corner_000”,“1911”,"11174"
“FB_Brow_Centre_000”,“1799”,"37193"
“FB_UpperLipRoot_000”,“5895”,"20178"
“FB_UpperLip_000”,“6007”,"61839"
“FB_L_Lip_Top_000”,“1911”,"20279"
“FB_R_Lip_Top_000”,“1911”,"17719"
“FB_Jaw_000”,“5895”,"46240"
“FB_LowerLipRoot_000”,“5895”,"17188"
“FB_LowerLip_000”,“6007”,"20623"
“FB_L_Lip_Bot_000”,“1911”,"47419"
“FB_R_Lip_Bot_000”,“1911”,"49979"
“FB_Tongue_000”,“1911”,"47495"
“RB_Neck_1”,“7”,"35731"
“IK_Root”,“119”,“56604”


#18

fixed.

change
TriggerClientEvent("drag", source, tonumber(argument))
to
TriggerClientEvent("drag", tonumber(argument), source)


#19

Legend.


#20

Hopefully none of you have a problem with this?


#21

and for Vrp Framework ? :S not found