Jump to content

[HELP] attachElementToBone


Recommended Posts

This is included with the script itself.

attachElementToBone(element,ped,bone,x,y,z,rx,ry,rz) : attaches element to the bone of the ped. Server and client function.

element : Element which you want to attach.

ped : Ped or player which you want to attach element to.

bone : Bone which you want to attach element to.

x,y,z : Position offset from the bone.

rx,ry,rz : Rotation offset from the bone.

Returns true if element was successfully attached, false otherwise.

detachElementFromBone(element) : detaches element from the bone of the ped. Server and client function.

element : Element which you want to detach.

Returns true if element was successfully detached, false otherwise.

isElementAttachedToBone(element) : checks if element is attached to a bone. Server and client function.

element : Element which you want to check.

Returns true if element is attached to a bone, false otherwise.

getElementBoneAttachmentDetails(element) : gets ped, bone and offset of attached element. Server and client function.

element : Element which you want to get attachment details of.

Returns ped,bone,x,y,z,rx,ry,rz used in attachElementToBone if element is attached, false otherwise.

setElementBonePositionOffset(element,x,y,z) : changes position offset of attached element. Server and client function.

element : Element which you want to change offset of.

x,y,z : New position offset.

Returns true if position set successfully, false otherwise.

setElementBoneRotationOffset(element,rx,ry,rz) : changes rotation offset of attached element. Server and client function.

element : Element which you want to change offset of.

rx,ry,rz : New rotation offset.

Returns true if rotation set successfully, false otherwise.

getBonePositionAndRotation(ped,bone) : gets position and rotation of the ped bone. Client-only function.

Returns bone x,y,z position and rotation if ped is streamed in and bone number is valid, false otherwise.

Bone IDs:

1: head

2: neck

3: spine

4: pelvis

5: left clavicle

6: right clavicle

7: left shoulder

8: right shoulder

9: left elbow

10: right elbow

11: left hand

12: right hand

13: left hip

14: right hip

15: left knee

16: right knee

17: left ankle

18: right ankle

19: left foot

20: right foot

Link to comment
This is included with the script itself.
attachElementToBone(element,ped,bone,x,y,z,rx,ry,rz) : attaches element to the bone of the ped. Server and client function.

element : Element which you want to attach.

ped : Ped or player which you want to attach element to.

bone : Bone which you want to attach element to.

x,y,z : Position offset from the bone.

rx,ry,rz : Rotation offset from the bone.

Returns true if element was successfully attached, false otherwise.

detachElementFromBone(element) : detaches element from the bone of the ped. Server and client function.

element : Element which you want to detach.

Returns true if element was successfully detached, false otherwise.

isElementAttachedToBone(element) : checks if element is attached to a bone. Server and client function.

element : Element which you want to check.

Returns true if element is attached to a bone, false otherwise.

getElementBoneAttachmentDetails(element) : gets ped, bone and offset of attached element. Server and client function.

element : Element which you want to get attachment details of.

Returns ped,bone,x,y,z,rx,ry,rz used in attachElementToBone if element is attached, false otherwise.

setElementBonePositionOffset(element,x,y,z) : changes position offset of attached element. Server and client function.

element : Element which you want to change offset of.

x,y,z : New position offset.

Returns true if position set successfully, false otherwise.

setElementBoneRotationOffset(element,rx,ry,rz) : changes rotation offset of attached element. Server and client function.

element : Element which you want to change offset of.

rx,ry,rz : New rotation offset.

Returns true if rotation set successfully, false otherwise.

getBonePositionAndRotation(ped,bone) : gets position and rotation of the ped bone. Client-only function.

Returns bone x,y,z position and rotation if ped is streamed in and bone number is valid, false otherwise.

Bone IDs:

1: head

2: neck

3: spine

4: pelvis

5: left clavicle

6: right clavicle

7: left shoulder

8: right shoulder

9: left elbow

10: right elbow

11: left hand

12: right hand

13: left hip

14: right hip

15: left knee

16: right knee

17: left ankle

18: right ankle

19: left foot

20: right foot

YEah thanks but

3: spine

Not Work.. i try to attach the bag to the back of the player...but the id 3 only not work... but others work.

Link to comment
In his script, he's replacing the 1 till 20 with other bones, you can try to work around that and use GetPedBonePosition to get the position of bone 3,4 or 5. Whatever suits you the best. See if that works. :)

I think you don't understand me :) !

        exports.bone_attach:attachElementToBone(bagb,thePlayer,3,0,0,0,0,0,0)        

when i do this don't show the object...like the object's hidden...but with another id it works. like head or neck

Link to comment
  • 5 months later...
  • 4 months later...
  • 3 months later...

Replace function "getBoneMatrix" in file "bone_pos_rot.lua" with this implementation

  
  
function getBoneMatrix(ped,bone) 
        local x,y,z,tx,ty,tz,fx,fy,fz 
        x,y,z = getPedBonePosition(ped,bone_0[bone]) 
        if bone == 1 then 
            local x6,y6,z6 = getPedBonePosition(ped,6) 
            local x7,y7,z7 = getPedBonePosition(ped,7) 
            tx,ty,tz = (x6+x7)*0.5,(y6+y7)*0.5,(z6+z7)*0.5 
        elseif bone == 3 then 
            local x21,y21,z21, x31,y31,z31 
  
            x21,y21,z21 = getPedBonePosition(ped,21) 
            x31,y31,z31 = getPedBonePosition(ped,31)  
  
            if math.round(x21, 2) == math.round(x31, 2) and math.round(y21, 2) == math.round(y31, 2) and math.round(z21, 2) == math.round(z31, 2) then  
                x21,y21,z21 = getPedBonePosition(ped,21) 
                local _,_,rZ = getElementRotation(ped) 
  
                tx,ty,tz = getPointInFrontOfPoint(x21, y21, z21, rZ, 0.0001) 
            else 
                tx,ty,tz = (x21+x31)*0.5,(y21+y31)*0.5,(z21+z31)*0.5 
            end          
        else 
            tx,ty,tz = getPedBonePosition(ped,bone_t[bone]) 
        end 
        fx,fy,fz = getPedBonePosition(ped,bone_f[bone]) 
        local xx,xy,xz,yx,yy,yz,zx,zy,zz = getMatrixFromPoints(x,y,z,tx,ty,tz,fx,fy,fz) 
        if bone == 1 or bone == 3 then xx,xy,xz,yx,yy,yz = -yx,-yy,-yz,xx,xy,xz end 
        return xx,xy,xz,yx,yy,yz,zx,zy,zz 
    end 
  
  

Also you need this one functions:

  
  
  
function getPointInFrontOfPoint(x, y, z, rZ, dist) 
    local offsetRot = math.rad(rZ) 
    local vx = x + dist * math.cos(offsetRot) 
    local vy = y + dist * math.sin(offsetRot)   
    return vx, vy, z 
end 
  
function math.round(number, decimals, method) 
    decimals = decimals or 0 
    local factor = 10 ^ decimals 
    if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor 
    else return tonumber(("%."..decimals.."f"):format(number)) end 
end 
  

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...