1
+ local collection = { }
2
+
3
+ addEvent ( " onClientAttachElementToBone" , true )
4
+ addEventHandler ( " onClientAttachElementToBone" , root ,
5
+ function ( ped , bone , x , y , z , rx , ry , rz )
6
+ if isElement ( ped ) then
7
+ collection [ source ] = { ped , bone , x , y , z , rx , ry , rz }
8
+ else
9
+ collection [ source ] = nil
10
+ end
11
+ end )
12
+
13
+ bone_0 , bone_t , bone_f = { }, { }, { }
14
+ bone_0 [ 1 ] , bone_t [ 1 ] , bone_f [ 1 ] = 5 , nil , 8 -- Голова
15
+ bone_0 [ 2 ] , bone_t [ 2 ] , bone_f [ 2 ] = 4 , 5 , 8 -- Шея
16
+ bone_0 [ 3 ] , bone_t [ 3 ] , bone_f [ 3 ] = 3 , 4 , 5 -- Спина (не работает)
17
+ bone_0 [ 4 ] , bone_t [ 4 ] , bone_f [ 4 ] = 1 , 2 , 3 -- Таз
18
+ bone_0 [ 5 ] , bone_t [ 5 ] , bone_f [ 5 ] = 4 , 32 , 5 -- Левая ключица
19
+ bone_0 [ 6 ] , bone_t [ 6 ] , bone_f [ 6 ] = 4 , 22 , 5 -- Правая ключица
20
+ bone_0 [ 7 ] , bone_t [ 7 ] , bone_f [ 7 ] = 32 , 33 , 34 -- Левое плечо
21
+ bone_0 [ 8 ] , bone_t [ 8 ] , bone_f [ 8 ] = 22 , 23 , 24 -- Правое плечо
22
+ bone_0 [ 9 ] , bone_t [ 9 ] , bone_f [ 9 ] = 33 , 34 , 32 -- Левый локоть
23
+ bone_0 [ 10 ] , bone_t [ 10 ] , bone_f [ 10 ] = 23 , 24 , 22 -- Правый локоть
24
+ bone_0 [ 11 ] , bone_t [ 11 ] , bone_f [ 11 ] = 34 , 35 , 36 -- Левая рука
25
+ bone_0 [ 12 ] , bone_t [ 12 ] , bone_f [ 12 ] = 24 , 25 , 26 -- Правая рука
26
+ bone_0 [ 13 ] , bone_t [ 13 ] , bone_f [ 13 ] = 41 , 42 , 43 -- Левое бедро
27
+ bone_0 [ 14 ] , bone_t [ 14 ] , bone_f [ 14 ] = 51 , 52 , 53 -- Правое бедро
28
+ bone_0 [ 15 ] , bone_t [ 15 ] , bone_f [ 15 ] = 42 , 43 , 44 -- Левое колено
29
+ bone_0 [ 16 ] , bone_t [ 16 ] , bone_f [ 16 ] = 52 , 53 , 54 -- Правое колено
30
+ bone_0 [ 17 ] , bone_t [ 17 ] , bone_f [ 17 ] = 43 , 42 , 44 -- Левая лодыжка
31
+ bone_0 [ 18 ] , bone_t [ 18 ] , bone_f [ 18 ] = 53 , 52 , 54 -- Правая лодыжка
32
+ bone_0 [ 19 ] , bone_t [ 19 ] , bone_f [ 19 ] = 44 , 43 , 42 -- Левая нога
33
+ bone_0 [ 20 ] , bone_t [ 20 ] , bone_f [ 20 ] = 54 , 53 , 52 -- Правая нога
34
+
35
+ addEventHandler ( " onClientPreRender" , root ,
36
+ function ( )
37
+ for element , property in pairs ( collection ) do
38
+ if isElement ( property [ 1 ] ) then
39
+ if isElementStreamedIn ( property [ 1 ] ) then
40
+ local x , y , z , tx , ty , tz , fx , fy , fz
41
+ x , y , z = getPedBonePosition ( property [ 1 ], bone_0 [ property [ 2 ] ] )
42
+ if property [ 2 ] == 1 then
43
+ local x6 , y6 , z6 = getPedBonePosition ( property [ 1 ], 6 )
44
+ local x7 , y7 , z7 = getPedBonePosition ( property [ 1 ], 7 )
45
+ tx , ty , tz = ( x6 + x7 ) * 0.5 , ( y6 + y7 ) * 0.5 , ( z6 + z7 ) * 0.5
46
+ else
47
+ tx , ty , tz = getPedBonePosition ( property [ 1 ], bone_t [ property [ 2 ] ] )
48
+ end
49
+ local fx , fy , fz = getPedBonePosition ( property [ 1 ], bone_f [ property [ 2 ] ] )
50
+ local xx , xy , xz , yx , yy , yz , zx , zy , zz = getMatrixFromPoints ( x , y , z , tx , ty , tz , fx , fy , fz )
51
+ local objx = x + property [ 3 ] * xx + property [ 4 ] * yx + property [ 5 ] * zx
52
+ local objy = y + property [ 3 ] * xy + property [ 4 ] * yy + property [ 5 ] * zy
53
+ local objz = z + property [ 3 ] * xz + property [ 4 ] * yz + property [ 5 ] * zz
54
+ local rxx , rxy , rxz , ryx , ryy , ryz , rzx , rzy , rzz = getMatrixFromEulerAngles ( property [ 6 ], property [ 7 ], property [ 8 ] )
55
+
56
+ local txx = rxx * xx + rxy * yx + rxz * zx
57
+ local txy = rxx * xy + rxy * yy + rxz * zy
58
+ local txz = rxx * xz + rxy * yz + rxz * zz
59
+ local tyx = ryx * xx + ryy * yx + ryz * zx
60
+ local tyy = ryx * xy + ryy * yy + ryz * zy
61
+ local tyz = ryx * xz + ryy * yz + ryz * zz
62
+ local tzx = rzx * xx + rzy * yx + rzz * zx
63
+ local tzy = rzx * xy + rzy * yy + rzz * zy
64
+ local tzz = rzx * xz + rzy * yz + rzz * zz
65
+ local offrx , offry , offrz = getEulerAnglesFromMatrix ( txx , txy , txz , tyx , tyy , tyz , tzx , tzy , tzz )
66
+
67
+ setElementPosition ( element , objx , objy , objz )
68
+ setElementRotation ( element , offrx , offry , offrz , " ZXY" )
69
+ else
70
+ setElementPosition ( element , getElementPosition ( property [ 1 ] ) )
71
+ end
72
+ else
73
+ collection [ element ] = nil
74
+ end
75
+ end
76
+ end
77
+ )
78
+
79
+ function isElementAttachedToBone ( element )
80
+ if isElement ( element ) and getElementType ( element ) == " object" then
81
+ if collection [ element ] then
82
+ return true
83
+ end
84
+ end
85
+
86
+ return false
87
+ end
88
+
89
+ function attachElementToBone ( element , ped , bone , x , y , z , rx , ry , rz )
90
+ if ( isElement ( element ) and getElementType ( element ) == " object" ) and isElement ( ped ) then
91
+
92
+ collection [ element ] = { ped , bone , x , y , z , rx , ry , rz }
93
+ end
94
+
95
+ return false
96
+ end
97
+
98
+ function detachElementFromBone ( element )
99
+ if isElement ( element ) and getElementType ( element ) == " object" then
100
+ if collection [ element ] then
101
+ collection [ element ] = nil
102
+
103
+ return true
104
+ end
105
+ end
106
+
107
+ return false
108
+ end
109
+
110
+ addEventHandler ( " onClientElementDestroy" , root ,
111
+ function ( )
112
+ if collection [ source ] then
113
+ collection [ source ] = nil
114
+ end
115
+ end
116
+ )
117
+
118
+ function getPositionByBoneOffset ( ped , bone , offx , offy , offz )
119
+ local x , y , z , tx , ty , tz , fx , fy , fz
120
+ x , y , z = getPedBonePosition ( ped , bone_0 [ bone ] )
121
+ if bone == 1 then
122
+ local x6 , y6 , z6 = getPedBonePosition ( ped , 6 )
123
+ local x7 , y7 , z7 = getPedBonePosition ( ped , 7 )
124
+ tx , ty , tz = ( x6 + x7 ) * 0.5 , ( y6 + y7 ) * 0.5 , ( z6 + z7 ) * 0.5
125
+ else
126
+ tx , ty , tz = getPedBonePosition ( ped , bone_t [ bone ] )
127
+ end
128
+
129
+ fx , fy , fz = getPedBonePosition ( ped , bone_f [ bone ] )
130
+ local xx , xy , xz , yx , yy , yz , zx , zy , zz = getMatrixFromPoints ( x , y , z , tx , ty , tz , fx , fy , fz )
131
+ local objx = x + offx * xx + offy * yx + offz * zx
132
+ local objy = y + offx * xy + offy * yy + offz * zy
133
+ local objz = z + offx * xz + offy * yz + offz * zz
134
+ --[[ local rxx, rxy, rxz, ryx, ryy, ryz, rzx, rzy, rzz = getMatrixFromEulerAngles ( 0, 0, 0 )
135
+
136
+ local txx = rxx * xx + rxy * yx + rxz * zx
137
+ local txy = rxx * xy + rxy * yy + rxz * zy
138
+ local txz = rxx * xz + rxy * yz + rxz * zz
139
+ local tyx = ryx * xx + ryy * yx + ryz * zx
140
+ local tyy = ryx * xy + ryy * yy + ryz * zy
141
+ local tyz = ryx * xz + ryy * yz + ryz * zz
142
+ local tzx = rzx * xx + rzy * yx + rzz * zx
143
+ local tzy = rzx * xy + rzy * yy + rzz * zy
144
+ local tzz = rzx * xz + rzy * yz + rzz * zz
145
+ local offrx, offry, offrz = getEulerAnglesFromMatrix ( txx, txy, txz, tyx, tyy, tyz, tzx, tzy, tzz )]]
146
+
147
+ return objx , objy , objz
148
+ end
149
+
150
+ ---- ------------------------------
151
+ -- UTILS
152
+ ---- ------------------------------
153
+ local BONE_HELPER_TOGGLE = false
154
+ local boneHelper = {
155
+ offsetX = 0 , offsetY = 0 , offsetZ = 0 ,
156
+ offsetRX = 0 , offsetRY = 0 , offsetRZ = 0 }
157
+
158
+ addCommandHandler ( " bonehelper" ,
159
+ function ( command , model , bone )
160
+ model , bone = tonumber ( model ), tonumber ( bone )
161
+ if model and bone then
162
+ if isElement ( boneHelper .element ) then
163
+ destroyElement ( boneHelper .element )
164
+ end
165
+ boneHelper .element = createObject ( model , 0 , 0 , 0 )
166
+ setElementCollisionsEnabled ( boneHelper .element , false )
167
+
168
+ boneHelper .bone = bone
169
+ attachElementToBone ( boneHelper .element , localPlayer , bone , boneHelper .offsetX , boneHelper .offsetY , boneHelper .offsetZ , boneHelper .offsetRX , boneHelper .offsetRY , boneHelper .offsetRZ )
170
+ BONE_HELPER_TOGGLE = true
171
+ else
172
+ outputChatBox ( " Bone helper: Вы не указали модель объекта" )
173
+ end
174
+ end )
175
+
176
+ addEventHandler ( " onClientRender" , root ,
177
+ function ( )
178
+ if BONE_HELPER_TOGGLE ~= true or isElement ( boneHelper .element ) ~= true then
179
+ return
180
+ end
181
+
182
+ if getKeyState ( " num_add" ) then
183
+ boneHelper .offsetZ = boneHelper .offsetZ - 0.05
184
+ attachElementToBone ( boneHelper .element , localPlayer , boneHelper .bone , boneHelper .offsetX , boneHelper .offsetY , boneHelper .offsetZ , boneHelper .offsetRX , boneHelper .offsetRY , boneHelper .offsetRZ )
185
+ elseif getKeyState ( " num_sub" ) then
186
+ boneHelper .offsetZ = boneHelper .offsetZ + 0.05
187
+ attachElementToBone ( boneHelper .element , localPlayer , boneHelper .bone , boneHelper .offsetX , boneHelper .offsetY , boneHelper .offsetZ , boneHelper .offsetRX , boneHelper .offsetRY , boneHelper .offsetRZ )
188
+ elseif getKeyState ( " num_8" ) then
189
+ boneHelper .offsetY = boneHelper .offsetY + 0.05
190
+ attachElementToBone ( boneHelper .element , localPlayer , boneHelper .bone , boneHelper .offsetX , boneHelper .offsetY , boneHelper .offsetZ , boneHelper .offsetRX , boneHelper .offsetRY , boneHelper .offsetRZ )
191
+ elseif getKeyState ( " num_2" ) then
192
+ boneHelper .offsetY = boneHelper .offsetY - 0.05
193
+ attachElementToBone ( boneHelper .element , localPlayer , boneHelper .bone , boneHelper .offsetX , boneHelper .offsetY , boneHelper .offsetZ , boneHelper .offsetRX , boneHelper .offsetRY , boneHelper .offsetRZ )
194
+ elseif getKeyState ( " num_6" ) then
195
+ boneHelper .offsetX = boneHelper .offsetX - 0.05
196
+ attachElementToBone ( boneHelper .element , localPlayer , boneHelper .bone , boneHelper .offsetX , boneHelper .offsetY , boneHelper .offsetZ , boneHelper .offsetRX , boneHelper .offsetRY , boneHelper .offsetRZ )
197
+ elseif getKeyState ( " num_4" ) then
198
+ boneHelper .offsetX = boneHelper .offsetX + 0.05
199
+ attachElementToBone ( boneHelper .element , localPlayer , boneHelper .bone , boneHelper .offsetX , boneHelper .offsetY , boneHelper .offsetZ , boneHelper .offsetRX , boneHelper .offsetRY , boneHelper .offsetRZ )
200
+ elseif getKeyState ( " num_7" ) then
201
+ boneHelper .offsetRX = boneHelper .offsetRX - 1
202
+ attachElementToBone ( boneHelper .element , localPlayer , boneHelper .bone , boneHelper .offsetX , boneHelper .offsetY , boneHelper .offsetZ , boneHelper .offsetRX , boneHelper .offsetRY , boneHelper .offsetRZ )
203
+ elseif getKeyState ( " num_9" ) then
204
+ boneHelper .offsetRX = boneHelper .offsetRX + 1
205
+ attachElementToBone ( boneHelper .element , localPlayer , boneHelper .bone , boneHelper .offsetX , boneHelper .offsetY , boneHelper .offsetZ , boneHelper .offsetRX , boneHelper .offsetRY , boneHelper .offsetRZ )
206
+ elseif getKeyState ( " num_mul" ) then
207
+ boneHelper .offsetRY = boneHelper .offsetRY - 1
208
+ attachElementToBone ( boneHelper .element , localPlayer , boneHelper .bone , boneHelper .offsetX , boneHelper .offsetY , boneHelper .offsetZ , boneHelper .offsetRX , boneHelper .offsetRY , boneHelper .offsetRZ )
209
+ elseif getKeyState ( " num_div" ) then
210
+ boneHelper .offsetRY = boneHelper .offsetRY + 1
211
+ attachElementToBone ( boneHelper .element , localPlayer , boneHelper .bone , boneHelper .offsetX , boneHelper .offsetY , boneHelper .offsetZ , boneHelper .offsetRX , boneHelper .offsetRY , boneHelper .offsetRZ )
212
+ elseif getKeyState ( " num_1" ) then
213
+ boneHelper .offsetRZ = boneHelper .offsetRZ - 1
214
+ attachElementToBone ( boneHelper .element , localPlayer , boneHelper .bone , boneHelper .offsetX , boneHelper .offsetY , boneHelper .offsetZ , boneHelper .offsetRX , boneHelper .offsetRY , boneHelper .offsetRZ )
215
+ elseif getKeyState ( " num_3" ) then
216
+ boneHelper .offsetRZ = boneHelper .offsetRZ + 1
217
+ attachElementToBone ( boneHelper .element , localPlayer , boneHelper .bone , boneHelper .offsetX , boneHelper .offsetY , boneHelper .offsetZ , boneHelper .offsetRX , boneHelper .offsetRY , boneHelper .offsetRZ )
218
+ end
219
+ end
220
+ )
221
+
222
+ addEventHandler ( " onClientKey" , root ,
223
+ function ( button , press )
224
+ if BONE_HELPER_TOGGLE == true and button == " l" and press then
225
+ local offsetStr = boneHelper .offsetX .. " , " .. boneHelper .offsetY .. " , " .. boneHelper .offsetZ .. " , " .. boneHelper .offsetRX .. " , " .. boneHelper .offsetRY .. " , " .. boneHelper .offsetRZ
226
+ setClipboard ( offsetStr )
227
+ outputChatBox ( " '" .. offsetStr .. " ' скопировано в буфер обмена" )
228
+ end
229
+ end
230
+ )
0 commit comments