Spawning an object and attaching to the player ped

How can I spawn a prop and attach it to the player ped?

Try this

2 Likes

Example of something from a very old script I was working on.

Client Script

local FishRod = AttachEntityToPed('prop_fishing_rod_01',60309, 0,0,0, 0,0,0)
			PlayAnim(GetPlayerPed(-1),'[email protected][email protected]','base',4,3000)
			Citizen.Wait(time)
			StopAnimTask(GetPlayerPed(-1), '[email protected][email protected]_a','idle_c',2.0)
			DeleteEntity(FishRod)
2 Likes

In the AttachEntityToEntity function, instead of 'prop_riot_shield', you need to put the variable for the actual object you just created. In your case, it would be prop

3 Likes

You will need to play with all the arguments you have there. They handle offset and rotation. You can see what each argument does here: https://runtime.fivem.net/doc/reference.html#_0x6B9BBD38AB0796DF

1 Like

In the arguments, there is way to attach it to the entity bone, too. You will need to lookup the bone index number for hand/arm or whatever it is.

No, so do:
GetEntityBoneIndexByName(ped, "SKEL_L_Finger00");
That will return the proper number.
https://runtime.fivem.net/doc/reference.html#_0xFB71170B7E76ACBA

2 Likes

Ped is just whatever the ped variable is… so GetPlayerPed(-1)

1 Like

This attaches the briefcase (which I retextured) to the right hand

This is what i made (with help from @Buggeroff I believe)

local toggleKit = false 
local medkit = nil


RegisterCommand("togglemedkit", function(source, args, raw)
    toggleKit = not toggleKit
    TriggerEvent( 'fivemedical:medkit' )
end, false)

RegisterNetEvent("fivemedical:togmedkit")
AddEventHandler("fivemedical:togmedkit", function()

    if toggleKit then
	
        if medkit == nil then
			medkit = CreateObject(GetHashKey("prop_med_bag_01b"), 0, 0, 0, true, true, true) -- creates object
        end			
        AttachEntityToEntity(medkit, GetPlayerPed(-1), GetPedBoneIndex(GetPlayerPed(-1), 57005), 0.4, 0, 0, 0, 270.0, 60.0, true, true, false, true, 1, true) -- object is attached to right hand    
    else
        if medkit ~= nil then
            DeleteEntity(medkit) -- deletes medkit
            medkit = nil
        end			
    end
end)

To attach it to other parts change

to the correct value (refer to the ped bone index on the fivem wiki)

And then adjust these values to your liking

2 Likes

I know how to do this but now I need to change the arm position like in my other post: Change arm position

equipt a weapon and hide current weapon in simple trainer

I need to play an animation to hold the sield like I explained in my other post

how do you dowload spawning-an-object-and-attaching-to-the-player-ped

2 Likes