Attach entity to closest bone

Hello, I wonder if is it possible to Attach entity using AttachEntityToEntity to closest bone or a bone player is standing on? For example I would like to attach player ped to vehicle roof / vehicle trailer the player is standing on.
I guess the touching part can be done with IsEntityTouchingModel

IF it’s exactly possible to detect the “closest bone” i’m not sure though,
But i do have an example which uses bones in one of my scripts:

And in this post of mine it shows some extra bones information:

The " Player Bones (To attach objects to)" section :slight_smile:

1 Like

Indeed this is possible, but i SUSPECT you would still have to ‘specify’ an array/table of supported models, just ‘randomly’ attaching to ‘possibly everything’ won’t go ‘that well’ i suppose (Not 100% certain though, so don’t “nail me to the cross” for it :joy:.

Reason for giving the link to my RideAnimals script btw is that even that i’m still using the same bone(s), it still needs an offset to properly put the player on different animals :wink: :slight_smile:

Yeah you said about getting player bone thats not a problem, my point is to be able to attach player to a roof of a vehicle (and getting that vehicle bone there is a problem) to dont fell off while vehicle is moving, anyway ill try something

1 Like

Doing that (if you want to have it permanently) can “easily” be done in vehicles.meta :slight_smile:
by adding a tag :slight_smile:

This for example is a flag setting for one of my own Stockade mods:

      <flags>FLAG_BIG FLAG_NO_BOOT FLAG_AVOID_TURNS FLAG_DELIVERY FLAG_PEDS_CAN_STAND_ON_TOP FLAG_DAMPEN_STICKBOMB_DAMAGE FLAG_DONT_SPAWN_IN_CARGEN FLAG_USE_FAT_INTERIOR_LIGHT FLAG_IS_BULKY FLAG_BLOCK_FROM_ATTRACTOR_SCENARIO FLAG_FLEE_FROM_COMBAT</flags>

Notice the: **FLAG_PEDS_CAN_STAND_ON_TOP **

And via script:

GetEntityBoneIndexByName()

This could help. I’ve used it in my spotlight script - https://github.com/FAXES/Spotlight

https://runtime.fivem.net/doc/natives/#_0xFB71170B7E76ACBA

1 Like

Never heard of that, but I will try something. Anyway adding that to like 30 vehicles may be pain in the ass hehe.

1 Like

GREAT suggestion actually indeed!, :smile::+1:

2 Likes

Will be but be much less ‘issues’ INGAME, since when you want to be able to put multiple people on one vehicle for example you will need to make sure they won’t clip.

And if you don’t want multiple’s ontop you will need to make a check to see if there isn’t anyone else ontop (not that big of a deal though, done it in my animals script to).

But keep in mind that that flag also makes it more ‘realistic’ and normal behaviour, ‘attaching players’ to roofs will also FORCE them to stay on when the vehicle flips (and thus clipping through the ground and such)

I’ve had to do several handlings and ragdoll stuff to overcome that with the animal script

Wow nice, so as I see this could be easily done by attaching only for chassis for example and should work for every vehicle i guess, another thing is how to get player position and attach it to the exact same spot player is standing? (example: if player is standing on the back of a trailer / vehicle attach him on the back, even getting closest vehicle this could not be done to check if is in front or not right? I dont want to put a specifed place and attach only on center or something

Calculating an offset between the player location and vehicle location, but then you would still have a ‘small problem’ since “big vehicles” have a different ‘offset’ compared smaller/lower vehicles.

Take a look at the spotlight script as that has a few things, as well as through my GitHub.

@Sandacz definitly recommened to do so indeed :slight_smile:
AND if you need examples on how to handle it when the vehicle or so ‘flips’ (and make the player fall/ragdoll off it), just use the examples in my animals script where i check on the animal dying, getting hit by a car etc :slight_smile:

@FAXES see that you used GetEntityForwardVector but how to use it properly to check if im on front of a vehicle or on a back? And @VenomXNL when the vehicle flips i will try to use GetEntityRoll and IsEntityUpsidedown

Indeed those will do about the same as i did :slight_smile:
Maybe you can do some offset calculation from vehicle location, forwardvector and heading? (just some ‘top of my head ideas’) :slight_smile:

GetEntityForwardVector() gets the forward vector, so which way the ped is facing. It does not set it only gets

1 Like

Wasn’t referring to setting it though (IF you meant my message :wink: ), but to use those (together) in some ‘mix’ to create a detection on where the player is located on the vehicle.

I KNOW/bet there are better methods though (just havn’t worked on it myself since working through other aspects of the server first atm), but i have seen scripts coming by which detected if the player is near the trunk or boot for example (sorry no example now, but i guess it should be possible and not ‘that hard’ to do then) :slight_smile:

1 Like

:wink: