forked from ghosty2004/samp-mapstealer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapstealer.lua
311 lines (268 loc) · 11.6 KB
/
mapstealer.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
script_author('Ghosty2004');
--[[ Modules ]]
local ev = require('samp.events');
--[[ Variables ]]
local mapstealer = false;
local objects = {};
local count = 0;
local temp_stream_data = {};
local remove_objects = {};
local remove_objects_count = 0;
local temp_remove_building_data = {};
local temp_remove_building_count = 0;
--[[ Main ]]
function main()
repeat wait(0) until isSampAvailable()
SCM("Loaded.");
sampRegisterChatCommand("mapstealer", function()
mapstealer = not mapstealer;
if(mapstealer) then
SCM("Started.");
else
local map = "";
local objects_count = 0;
local materials_count = 0;
local materialstext_count = 0;
local remove_building_count = 0;
local maps = {};
table.insert(maps, "public OnFilterScriptInit()");
table.insert(maps, "{");
table.insert(maps, " new ghosty2004_map;");
for key, value in pairs(objects) do
--[[ Objects ]]
if(value[1]) then
for key_object, value_object in pairs(value[1]) do
objects_count = objects_count + 1;
table.insert(maps, string.format(" %s", value_object));
end
end
--[[ Materials ]]
if(value[2]) then
for key_material, value_material in pairs(value[2]) do
materials_count = materials_count + 1;
table.insert(maps, string.format(" %s", value_material));
end
end
--[[ Materials Text ]]
if(value[3]) then
for key_materialtext, value_materialtext in pairs(value[3]) do
materialstext_count = materialstext_count + 1;
table.insert(maps, string.format(" %s", value_materialtext));
end;
end
end
table.insert(maps, "}");
table.insert(maps, "\n");
table.insert(maps, "public OnPlayerConnect(playerid)");
table.insert(maps, "{");
for key, value in pairs(remove_objects) do
table.insert(maps, string.format(" %s", value));
remove_building_count = remove_building_count + 1;
end
table.insert(maps, "}");
for key, value in pairs(maps) do map = string.format("%s\n%s", map, value); end
for key, value in pairs(temp_stream_data) do
if(value.label) then sampDestroy3dText(value.label); end
end
SCM(string.format("Saved: %d objects, %d remove buildings, %d materials and %d materials text.", objects_count, remove_building_count, materials_count, materialstext_count));
local header = "/* ======================== */\n/* Ghosty2004's map stealer */\n/* ======================== */";
local ip, port = sampGetCurrentServerAddress();
createDirectory("ghosty2004_mapstealer");
local file = io.open(string.format("ghosty2004_mapstealer\\%s_%d.txt", ip, port), "w");
file:write(string.format("\n%s\n\n%s", header, map));
file:close();
objects = {};
temp_stream_data = {};
end
end)
while true do
wait(0);
if(mapstealer) then
--[[ Remove Building ]]
local pPositionX, pPositionY, pPositionZ = getCharCoordinates(PLAYER_PED);
for key, value in pairs(temp_remove_building_data) do
local distance = getDistanceBetweenCoords3d(pPositionX, pPositionY, pPositionZ, value.position.x, value.position.y, value.position.z)
if(distance <= 400) then
remove_object_string = string.format("RemoveBuildingForPlayer(playerid, %d, %f, %f, %f, %f);", value.modelId, value.position.x, value.position.y, value.position.z, value.radius)
if(not checkIfThisRemoveBuildingSrcExists(remove_object_string)) then
table.insert(remove_objects, remove_object_string);
end
end
end
local objects_count = 0;
local materials_count = 0;
local materialstext_count = 0;
local remove_building_count = 0;
for key, value in pairs(objects) do
if(value[1]) then for _ in pairs(value[1]) do objects_count = objects_count + 1; end end
if(value[2]) then for _ in pairs(value[2]) do materials_count = materials_count + 1; end end
if(value[3]) then for _ in pairs(value[3]) do materialstext_count = materialstext_count + 1; end end
end
for key, value in pairs(remove_objects) do remove_building_count = remove_building_count + 1; end;
info(string.format("Recording...~n~~w~~h~Objects: ~y~~h~%d ~w~~h~| Remove Buildings: ~y~~h~%d ~n~~w~~h~Materials: (~y~~h~%d~w~ Textures | ~y~~h~%d~w~~h~ Texts)", objects_count, remove_building_count, materials_count, materialstext_count), 1);
end
end
end
function onExitScript(quitGame)
for key, value in pairs(temp_stream_data) do
if(value.label) then sampDestroy3dText(value.label); end
end
end
--[[ Events ]]
function ev.onRemoveBuilding(modelId, position, radius)
temp_remove_building_count = temp_remove_building_count + 1;
temp_remove_building_data[temp_remove_building_count] = {
modelId = modelId;
position = position;
radius = radius;
}
end
function ev.onDestroyObject(objectId)
if(temp_stream_data[objectId]) then sampDestroy3dText(temp_stream_data[objectId].label); end
temp_stream_data[objectId] = {};
end
function ev.onCreateObject(objectId, data)
if(mapstealer) then
local object_string = string.format("ghosty2004_map = CreateDynamicObject(%d, %f, %f, %f, %f, %f, %f, %d, %d, %d, %f, %f);", data.modelId, data.position.x, data.position.y, data.position.z, data.rotation.x, data.rotation.y, data.rotation.z, -1, -1, -1, 400, 400);
if(not checkIfThisObjectSrcExists(object_string)) then
count = count + 1;
if(not objects[count]) then
objects[count] = {};
objects[count][1] = {};
table.insert(objects[count][1], object_string);
local positionX, positionY, positionZ = getCharCoordinates(PLAYER_PED);
addOneOffSound(positionX, positionY, positionZ, 1058);
end
end
temp_stream_data[objectId] = {
index = thisObjectSrcKey(object_string);
objectInfo = {
model = data.modelId;
},
label = sampCreate3dText("", -1, data.position.x, data.position.y, data.position.z, data.drawDistance, true, -1, -1);
}
updateThisLabel(thisObjectSrcKey(object_string));
end
end
function ev.onSetObjectMaterial(objectId, data)
if(mapstealer) then
local index = temp_stream_data[objectId].index;
if(index ~= -1 and index) then
if(objects[index]) then
local material_string = string.format("SetDynamicObjectMaterial(ghosty2004_map, %d, %d, \"%s\", \"%s\", %d);", data.materialId, data.modelId, data.libraryName, data.textureName, data.color);
if(not isMaterialExists(index, material_string)) then
if(not objects[index][2]) then objects[index][2] = {}; end
table.insert(objects[index][2], material_string);
updateThisLabel(index);
end
end
end
end
end
function ev.onSetObjectMaterialText(objectId, data)
if(mapstealer) then
local index = temp_stream_data[objectId].index;
if(index ~= -1 and index) then
if(objects[index]) then
local materialtext_string = string.format("SetDynamicObjectMaterialText(ghosty2004_map, %d, \"%s\", %d, \"%s\", %d, %d, %d, %d, %d);", data.materialId, data.text, data.materialSize, data.fontName, data.fontSize, data.bold, data.fontColor, data.backGroundColor, data.align);
if(not isMaterialTextExists(index, materialtext_string)) then
if(not objects[index][3]) then objects[index][3] = {}; end
table.insert(objects[index][3], materialtext_string);
updateThisLabel(index);
end
end
end
end
end
--[[ Functions ]]
function SCM(text)
tag = '{FF5656}[Ghosty2004 Map Stealer]: ';
sampAddChatMessage(tag .. text, -1);
end
function info(text, time)
printStringNow(string.format("~r~~h~[Ghosty2004 Map Stealer] ~g~~h~%s", text), time)
end
function updateThisLabel(labelIndex)
for key, value in pairs(temp_stream_data) do
if(value.index == labelIndex) then
sampSet3dTextString(value.label, string.format("Object Info:\nID: %s | Model: %s\nMaterials: %s | Materials Text: %s", value.index, value.objectInfo.model, getMaterialCount(value.index), getMaterialTextCount(value.index)));
end
end
end
function checkIfThisRemoveBuildingSrcExists(src)
local exists = false;
for key, value in pairs(remove_objects) do
if(value == src) then exists = true; end
end
return exists;
end
function checkIfThisObjectSrcExists(src)
local exists = false;
for key, value in pairs(objects) do
if(value[1]) then
for key_object, value_object in pairs(value[1]) do
if(src == value_object) then exists = true; end
end
end
end
return exists;
end
function getMaterialCount(index)
local count = 0;
for key, value in pairs(objects) do
if(value[2]) then
if(key == index) then
for _, value_material in pairs(value[2]) do count = count + 1; end
end
end
end
return count;
end
function getMaterialTextCount(index)
local count = 0;
for key, value in pairs(objects) do
if(value[3]) then
if(key == index) then
for _, value_material in pairs(value[3]) do count = count + 1; end
end
end
end
return count;
end
function isMaterialExists(index, src)
local exists = false;
for key, value in pairs(objects) do
if(value[2]) then
if(key == index) then
for key_object, value_material in pairs(value[2]) do
if(src == value_material) then exists = true; end
end
end
end
end
return exists;
end
function isMaterialTextExists(index, src)
local exists = false;
for key, value in pairs(objects) do
if(value[3]) then
if(key == index) then
for key_object, value_materialtext in pairs(value[3]) do
if(src == value_materialtext) then exists = true; end
end
end
end
end
return exists;
end
function thisObjectSrcKey(src)
local key_value = -1;
for key, value in pairs(objects) do
if(value[1]) then
for _, value_object in pairs(value[1]) do
if(src == value_object) then key_value = key; end
end
end
end
return key_value;
end