How can I spawn a prop and attach it to the player ped?
Try this
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),'amb@world_human_stand_fishing@base','base',4,3000)
Citizen.Wait(time)
StopAnimTask(GetPlayerPed(-1), 'amb@world_human_stand_fishing@idle_a','idle_c',2.0)
DeleteEntity(FishRod)
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
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
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
Ped is just whatever the ped variable is… so GetPlayerPed(-1)
This attaches the briefcase (which I retextured) to the right hand
This is what i made (with help from @Syntasu 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
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