Log in to reply

C# - Making a player hold an object/prop

  • Hey guys

    Just wondering if anyone has code that will attach/remove a prop from a players hand? Such as them holding a small object e.g. a bag in their hand.

    I've come across ENTITY::ATTACH_ENTITY_TO_ENTITY but haven't had much luck.

    If anyone knows how too do this I'd appreciate some help :)

  • That's the correct native. There's also ATTACH_ENTITY_TO_ENTITY_PHYSICALLY.

    Here's an old snippet for picking up vehicles:

    void AttachEntityToEntity(Entity e1, Entity e2, int boneIndexE2, Vector3 offsetPos, Vector3 rotation, bool useSoftPinning = false, bool collisionBetweenEnts = false, bool entOneIsPed = false, int vertexIndex = 0, bool fixedRot = false)
     Function.Call(Hash.ATTACH_ENTITY_TO_ENTITY, e1, e2, boneIndexE2, offsetPos.X, offsetPos.Y, offsetPos.Z, rotation.X, rotation.Y, rotation.Z, -1 f, useSoftPinning, collisionBetweenEnts, entOneIsPed, vertexIndex, fixedRot);
    Ped player = Game.Player.Character;
    Vector3 source = player.Position;
    Vehicle veh = getClosestVehicle(source, 6 f, null);
    veh.SetNoCollision(player, true);
    if (veh.Model.GetDimensions().Z >= veh.Model.GetDimensions().X)
     AttachEntityToEntity(veh, player, player.GetBoneIndex(Bone.IK_R_Hand), new Vector3(player.GetOffsetFromWorldCoords(veh.Position).X + (veh.Model.GetDimensions().X / 2) - 0.2 f, 0, -0.35 f), new Vector3(70 f, -20 f, 20 f), false, false, false, 2, true);
     AttachEntityToEntity(veh, player, player.GetBoneIndex(Bone.IK_R_Hand), new Vector3((veh.Model.GetDimensions().X / 2), 0, -0.2 f), new Vector3(70 f, -20 f, 20 f), false, false, false, 2, true);

  • Thanks for the help! Got it working.

Log in to reply

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.