-
Notifications
You must be signed in to change notification settings - Fork 6
/
vaos.lua
371 lines (302 loc) · 18.7 KB
/
vaos.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
local softLicenses = [[
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
(Это свободная программа: вы можете перераспространять ее и/или изменять
ее на условиях Стандартной общественной лицензии GNU в том виде, в каком
она была опубликована Фондом свободного программного обеспечения; либо
версии 3 лицензии, либо (по вашему выбору) любой более поздней версии.
Эта программа распространяется в надежде, что она будет полезной,
но БЕЗО ВСЯКИХ ГАРАНТИЙ; даже без неявной гарантии ТОВАРНОГО ВИДА
или ПРИГОДНОСТИ ДЛЯ ОПРЕДЕЛЕННЫХ ЦЕЛЕЙ. Подробнее см. в Стандартной
общественной лицензии GNU.
Вы должны были получить копию Стандартной общественной лицензии GNU
вместе с этой программой. Если это не так, см.
<https://www.gnu.org/licenses/>.)
]]
local h = require('samp.events')
local bit = require('numberlua')
local objectsTable = { }
local lastPlayerState = -1
function main()
if not isSampLoaded() or not isSampfuncsLoaded() then return end
while not isSampAvailable() do wait(100) end
sampAddChatMessage('Vehicle Attached Objects Stealer loaded by f0Re3t', 0xFFFFDAB9)
sampAddChatMessage('VAOS: commands - /vaos [vehicle id]', 0xFFFFDAB9)
sampRegisterChatCommand('vaos', vaos)
while true do
wait(0)
local pState = sampGetGamestate()
if pState == 5 and lastPlayerState ~= 5 and lastPlayerState ~= -1 then
for i = 1, #objectsTable do
if objectsTable[i] ~= nil then
objectsTable[i] = nil
end
end
lastPlayerState = pState
end
end
end
function vaos(id)
if tonumber(id) == nil then return sampAddChatMessage('Invalid vehicle id', 0xFF9ACD32) end
local res, vHandle = sampGetCarHandleBySampVehicleId(id)
if not res then return sampAddChatMessage('Vehicle not in stream', 0xFF9ACD32) end
local sIp, sPort = sampGetCurrentServerAddress()
local sName = sIp .. '_' .. sPort
sName = sName:gsub('[|%%%[%]! :\\/*|"<>•!' .. string.char(0x08) .. string.char(0x3F) .. ']', '_')
if not doesDirectoryExist('VAOS') then createDirectory('VAOS') end
if not doesDirectoryExist(string.format('VAOS\\%s', sName)) then createDirectory(string.format('VAOS\\%s', sName)) end
local fID = io.open(string.format('VAOS\\%s\\%s', sName, tostring(id)), 'w+')
local vPosX, vPosY, vPosZ = getCarCoordinates(vHandle)
local vAngle = getCarHeading(vHandle)
local vColorPrim, vColorSec = getCarColours(vHandle)
fID:write(string.format('new vehicleid = CreateVehicle(%i, %f, %f, %f, %f, %i, %i, -1);', getCarModel(vHandle), vPosX, vPosY, vPosZ, vAngle, vColorPrim, vColorSec) .. '\n\n')
for i = 1, #objectsTable do
if objectsTable[i] ~= nil then
if objectsTable[i]['id'] == tonumber(id) then
local setDrawDist = 'STREAMER_OBJECT_DD'
local setDrawDistNum = '0.0'
if objectsTable[i]['data']['drawDistance'] > 0 then
setDrawDist = tostring(objectsTable[i]['data']['drawDistance'])
setDrawDistNum = tostring(objectsTable[i]['data']['drawDistance'])
if setDrawDist == nil and setDrawDistNum == nil then
setDrawDist = 'STREAMER_OBJECT_DD'
setDrawDistNum = '0.0'
else
setDrawDist = tostring(math.floor(objectsTable[i]['data']['drawDistance'])) .. '.0'
setDrawDistNum = tostring(math.floor(objectsTable[i]['data']['drawDistance'])) .. '.0'
end
end
local objVar = 'vaos_' .. tostring(i)
if objectsTable[i]['data']['materialNum'] == 0 and objectsTable[i]['data']['materialTxtNum'] == 0 then
if objectsTable[i]['data']['streamerDynamic'] then
fID:write(string.format('%sCreateDynamicObject(%d, %f, %f, %f, %f, %f, %f, %d, %d, -1, STREAMER_OBJECT_SD, %s); // %d', 'new ' .. objVar .. ' = ', objectsTable[i]['data']['modelId'],
objectsTable[i]['data']['position']['x'], objectsTable[i]['data']['position']['y'], objectsTable[i]['data']['position']['z'],
objectsTable[i]['data']['rotation']['x'], objectsTable[i]['data']['rotation']['y'], objectsTable[i]['data']['rotation']['z'],
0, 0, setDrawDist, objectsTable[i]['data']['materialNum'] + objectsTable[i]['data']['materialTxtNum']) .. '\n')
if objectsTable[i]['data']['cameraCol'] == 1 then fID:write(string.format('SetDynamicObjectNoCameraCol(%s);', objVar) .. '\n') end
fID:write(string.format('AttachDynamicObjectToVehicle(%s, vehicleid, %f, %f, %f, %f, %f, %f);', objVar, objectsTable[i]['OffsetX'], objectsTable[i]['OffsetY'], objectsTable[i]['OffsetZ'],
objectsTable[i]['RotX'], objectsTable[i]['RotY'], objectsTable[i]['RotZ']) .. '\n\n')
else
fID:write(string.format('%sCreateObject(%d, %f, %f, %f, %f, %f, %f, %s); // %d', 'new ' .. objVar .. ' = ', objectsTable[i]['data']['modelId'], objectsTable[i]['data']['position']['x'],
objectsTable[i]['data']['position']['y'], objectsTable[i]['data']['position']['z'], objectsTable[i]['data']['rotation']['x'],
objectsTable[i]['data']['rotation']['y'], objectsTable[i]['data']['rotation']['z'], setDrawDistNum, objectsTable[i]['data']['materialNum'] +
objectsTable[i]['data']['materialTxtNum']) .. '\n')
if objectsTable[i]['data']['cameraCol'] == 1 then fID:write(string.format('SetObjectNoCameraCol(%s);', objVar) .. '\n') end
fID:write(string.format('AttachObjectToVehicle(%s, vehicleid, %f, %f, %f, %f, %f, %f);', objVar, objectsTable[i]['OffsetX'], objectsTable[i]['OffsetY'], objectsTable[i]['OffsetZ'],
objectsTable[i]['RotX'], objectsTable[i]['RotY'], objectsTable[i]['RotZ']) .. '\n\n')
end
else
if objectsTable[i]['data']['streamerDynamic'] then
fID:write(string.format('%sCreateDynamicObject(%d, %f, %f, %f, %f, %f, %f, %d, %d, -1, STREAMER_OBJECT_SD, %s); // %d', 'new ' .. objVar .. ' = ', objectsTable[i]['data']['modelId'],
objectsTable[i]['data']['position']['x'], objectsTable[i]['data']['position']['y'], objectsTable[i]['data']['position']['z'],
objectsTable[i]['data']['rotation']['x'], objectsTable[i]['data']['rotation']['y'], objectsTable[i]['data']['rotation']['z'],
0, 0, setDrawDist, objectsTable[i]['data']['materialNum'] + objectsTable[i]['data']['materialTxtNum']) .. '\n')
if objectsTable[i]['data']['cameraCol'] == 1 then fID:write(string.format('SetDynamicObjectNoCameraCol(%s);', objVar) .. '\n') end
for j = 1, #objectsTable[i]['data'] do
if objectsTable[i]['data'][j] ~= nil then
if objectsTable[i]['data'][j]['materialType'] == true then
fID:write(string.format('SetDynamicObjectMaterial(%s, %d, %d, "%s", "%s", %s);', objVar, objectsTable[i]['data'][j]['materialId'],
objectsTable[i]['data'][j]['modelId'], objectsTable[i]['data'][j]['libraryName'], objectsTable[i]['data'][j]['textureName'],
objectsTable[i]['data'][j]['color']) .. '\n')
else
fID:write(string.format('SetDynamicObjectMaterialText(%s, %d, "%s", %d, "%s", %d, %d, %s, %s, %d);', objVar, objectsTable[i]['data'][j]['materialId'],
objectsTable[i]['data'][j]['text'], objectsTable[i]['data'][j]['materialSize'], objectsTable[i]['data'][j]['fontName'],
objectsTable[i]['data'][j]['fontSize'], objectsTable[i]['data'][j]['bold'], objectsTable[i]['data'][j]['fontColor'],
objectsTable[i]['data'][j]['backGroundColor'], objectsTable[i]['data'][j]['align']) .. '\n')
end
end
end
fID:write(string.format('AttachDynamicObjectToVehicle(%s, vehicleid, %f, %f, %f, %f, %f, %f);', objVar, objectsTable[i]['OffsetX'], objectsTable[i]['OffsetY'], objectsTable[i]['OffsetZ'],
objectsTable[i]['RotX'], objectsTable[i]['RotY'], objectsTable[i]['RotZ']) .. '\n\n')
else
fID:write(string.format('%sCreateObject(%d, %f, %f, %f, %f, %f, %f, %s); // %d', 'new ' .. objVar .. ' = ', objectsTable[i]['data']['modelId'], objectsTable[i]['data']['position']['x'],
objectsTable[i]['data']['position']['y'], objectsTable[i]['data']['position']['z'], objectsTable[i]['data']['rotation']['x'],
objectsTable[i]['data']['rotation']['y'], objectsTable[i]['data']['rotation']['z'], setDrawDistNum, objectsTable[i]['data']['materialNum'] +
objectsTable[i]['data']['materialTxtNum']) .. '\n')
if objectsTable[i]['data']['cameraCol'] == 1 then fID:write(string.format('SetObjectNoCameraCol(%s);', objVar) .. '\n') end
for j = 1, #objectsTable[i]['data'] do
if objectsTable[i]['data'][j] ~= nil then
if objectsTable[i]['data'][j]['materialType'] == true then
fID:write(string.format('SetObjectMaterial(%s, %d, %d, "%s", "%s", %s);', objVar, objectsTable[i]['data'][j]['materialId'],
objectsTable[i]['data'][j]['modelId'], objectsTable[i]['data'][j]['libraryName'], objectsTable[i]['data'][j]['textureName'],
objectsTable[i]['data'][j]['color']) .. '\n')
else
fID:write(string.format('SetObjectMaterialText(%s, "%s", %d, %d, "%s", %d, %d, %s, %s, %d);', objVar, objectsTable[i]['data'][j]['text'],
objectsTable[i]['data'][j]['materialId'], objectsTable[i]['data'][j]['materialSize'], objectsTable[i]['data'][j]['fontName'],
objectsTable[i]['data'][j]['fontSize'], objectsTable[i]['data'][j]['bold'], objectsTable[i]['data'][j]['fontColor'],
objectsTable[i]['data'][j]['backGroundColor'], objectsTable[i]['data'][j]['align']) .. '\n')
end
end
end
fID:write(string.format('AttachObjectToVehicle(%s, vehicleid, %f, %f, %f, %f, %f, %f);', objVar, objectsTable[i]['OffsetX'], objectsTable[i]['OffsetY'], objectsTable[i]['OffsetZ'],
objectsTable[i]['RotX'], objectsTable[i]['RotY'], objectsTable[i]['RotZ']) .. '\n\n')
end
end
end
end
end
sampAddChatMessage('GOOD! ATTACHED OBJECTS COPPIED!', 0xFFFFDAB9)
io.close(fID)
end
function h.onCreateObject(objectId, data)
local tempObj = { }
tempObj['objectId'] = objectId
tempObj['modelId'] = data.modelId
tempObj['position'] = data.position
tempObj['rotation'] = data.rotation
tempObj['drawDistance'] = data.drawDistance
tempObj['cameraCol'] = data.cameraCol
tempObj['materialHave'] = false
tempObj['materialNum'] = 0
tempObj['materialTxtNum'] = 0
if sampGetGamestate() == 2 then tempObj['streamerDynamic'] = false else tempObj['streamerDynamic'] = true end
if data.texturesCount > 0 then
if #data.materials ~= 0 then
for i = 1, #data.materials do
local tempMatObj = { }
tempMatObj['objectId'] = data.objectId
tempMatObj['materialId'] = data.materials[i]['materialId']
tempMatObj['modelId'] = data.materials[i]['modelId']
tempMatObj['libraryName'] = data.materials[i]['libraryName']
tempMatObj['textureName'] = data.materials[i]['textureName']
tempMatObj['materialType'] = true
if data.materials[i]['color'] == 0 then tempMatObj['color'] = '0' else
tempMatObj['color'] = string.format('0x%X', bit.band(0xFFFFFFFF, data.materials[i]['color']))
end
tempObj['materialHave'] = true
tempObj['materialNum'] = tempObj['materialNum'] + 1
table.insert(tempObj, tempMatObj)
end
end
if #data.materialText ~= 0 then
for i = 1, #data.materialText do
local tempMatObj = {}
tempMatObj['objectId'] = data.objectId
tempMatObj['materialId'] = data.materialText[i]['materialId']
tempMatObj['materialSize'] = data.materialText[i]['materialSize']
tempMatObj['fontName'] = data.materialText[i]['fontName']
tempMatObj['fontSize'] = data.materialText[i]['fontSize']
tempMatObj['bold'] = data.materialText[i]['bold']
tempMatObj['materialType'] = false
if data.materialText[i]['fontColor'] == 0 then tempMatObj['fontColor'] = '0' else
tempMatObj['fontColor'] = string.format('0x%X', bit.band(0xFFFFFFFF, data.materialText[i]['fontColor']))
end
if data.materialText[i]['backGroundColor'] == 0 then tempMatObj['backGroundColor'] = '0' else
tempMatObj['backGroundColor'] = string.format('0x%X', bit.band(0xFFFFFFFF, data.materialText[i]['backGroundColor']))
end
tempMatObj['align'] = data.materialText[i]['align']
data.materialText[i]['text'] = string.gsub(data.materialText[i]['text'], '\n', '\\n')
tempMatObj['text'] = data.materialText[i]['text']
tempObj['materialHave'] = true
tempObj['materialTxtNum'] = tempObj['materialTxtNum'] + 1
table.insert(tempObj, tempMatObj)
end
end
end
function h.onMoveObject(objectId, fromPos, destPos, speed, rotation)
if tempObj['objectId'] == objectId then
if tempObj['position']['x'] ~= destPos.x then tempObj['position']['x'] = destPos.x end
if tempObj['position']['y'] ~= destPos.y then tempObj['position']['y'] = destPos.y end
if tempObj['position']['z'] ~= destPos.z then tempObj['position']['z'] = destPos.z end
if tempObj['rotation']['x'] ~= rotation.x and rotation.x ~= -1000.0 then tempObj['rotation']['x'] = rotation.x end
if tempObj['rotation']['y'] ~= rotation.y and rotation.y ~= -1000.0 then tempObj['rotation']['y'] = rotation.y end
if tempObj['rotation']['z'] ~= rotation.z and rotation.z ~= -1000.0 then tempObj['rotation']['z'] = rotation.z end
end
end
function h.onSetObjectMaterial(objectId, data)
if tempObj['objectId'] == objectId then
local tempMatObj = {}
tempMatObj['objectId'] = objectId
tempMatObj['materialId'] = data.materialId
tempMatObj['modelId'] = data.modelId
tempMatObj['libraryName'] = data.libraryName
tempMatObj['textureName'] = data.textureName
tempMatObj['materialType'] = true
if data.color == 0 then tempMatObj['color'] = '0' else tempMatObj['color'] = string.format('0x%X', bit.band(0xFFFFFFFF, data.color)) end
tempObj['materialHave'] = true
tempObj['materialNum'] = tempObj['materialNum'] + 1
table.insert(tempObj, tempMatObj)
end
end
function h.onSetObjectMaterialText(objectId, data)
if tempObj['objectId'] == objectId then
local tempMatObj = {}
tempMatObj['objectId'] = objectId
tempMatObj['materialId'] = data.materialId
tempMatObj['materialSize'] = data.materialSize
tempMatObj['fontName'] = data.fontName
tempMatObj['fontSize'] = data.fontSize
tempMatObj['bold'] = data.bold
tempMatObj['materialType'] = false
if data.fontColor == 0 then tempMatObj['fontColor'] = '0' else tempMatObj['fontColor'] = string.format('0x%X', bit.band(0xFFFFFFFF, data.fontColor)) end
if data.backGroundColor == 0 then tempMatObj['backGroundColor'] = '0' else tempMatObj['backGroundColor'] = string.format('0x%X', bit.band(0xFFFFFFFF,
data.backGroundColor)) end
tempMatObj['align'] = data.align
data.text = string.gsub(data.text, '\n', '\\n')
tempMatObj['text'] = data.text
tempObj['materialHave'] = true
tempObj['materialTxtNum'] = tempObj['materialTxtNum'] + 1
table.insert(tempObj, tempMatObj)
end
end
function h.onSetObjectPosition(objectId, position)
if tempObj['objectId'] == objectId then
if tempObj['position']['x'] ~= position.x then tempObj['position']['x'] = position.x end
if tempObj['position']['y'] ~= position.y then tempObj['position']['y'] = position.y end
if tempObj['position']['z'] ~= position.z then tempObj['position']['z'] = position.z end
end
end
function h.onSetObjectRotation(objectId, rotation)
if tempObj['objectId'] == objectId then
if tempObj['rotation']['x'] ~= rotation.x then tempObj['rotation']['x'] = rotation.x end
if tempObj['rotation']['y'] ~= rotation.y then tempObj['rotation']['y'] = rotation.y end
if tempObj['rotation']['z'] ~= rotation.z then tempObj['rotation']['z'] = rotation.z end
end
end
if data.attachToPlayerId ~= nil then
if data.attachToPlayerId ~= 65535 then
if not sampIsPlayerConnected(data.attachToPlayerId) then return false end
if tempObj['position']['x'] ~= data.attachOffsets.x and data.attachOffsets.x < -10.0 or data.attachOffsets.x > 10.0 and data.attachOffsets.x ~= nil then
tempObj['position']['x'] = data.attachOffsets.x else return false end
if tempObj['position']['y'] ~= data.attachOffsets.y and data.attachOffsets.y < -10.0 or data.attachOffsets.y > 10.0 and data.attachOffsets.y ~= nil then
tempObj['position']['y'] = data.attachOffsets.y else return false end
if tempObj['position']['z'] ~= data.attachOffsets.z and data.attachOffsets.z < -10.0 or data.attachOffsets.z > 10.0 and data.attachOffsets.z ~= nil then
tempObj['position']['z'] = data.attachOffsets.z else return false end
if tempObj['rotation']['x'] ~= data.attachRotation.x and data.attachRotation.x ~= nil then tempObj['rotation']['x'] = data.attachRotation.x end
if tempObj['rotation']['y'] ~= data.attachRotation.y and data.attachRotation.y ~= nil then tempObj['rotation']['y'] = data.attachRotation.y end
if tempObj['rotation']['z'] ~= data.attachRotation.z and data.attachRotation.z ~= nil then tempObj['rotation']['z'] = data.attachRotation.z end
end
end
if data.attachToVehicleId ~= nil then
if data.attachToVehicleId ~= 65535 then
local vehicleData = {}
vehicleData['id'] = data.attachToVehicleId
vehicleData['data'] = tempObj
vehicleData['OffsetX'] = data.attachOffsets.x
vehicleData['OffsetY'] = data.attachOffsets.y
vehicleData['OffsetZ'] = data.attachOffsets.z
vehicleData['RotX'] = data.attachRotation.x
vehicleData['RotY'] = data.attachRotation.y
vehicleData['RotZ'] = data.attachRotation.z
table.insert(objectsTable, vehicleData)
end
end
end
function h.onDestroyObject(objectId)
for i = 1, #objectsTable do
if objectsTable[i] ~= nil then
if objectsTable[i]['data']['objectId'] == objectId then
objectsTable[i] = nil
break
end
end
end
end