-
Notifications
You must be signed in to change notification settings - Fork 0
/
autotaker.lua
795 lines (726 loc) · 25.5 KB
/
autotaker.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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
script_name('AutoTaker')
script_author('Akionka')
script_version('1.8.0')
script_version_number(21)
if getMoonloaderVersion() >= 027 then
require 'deps' {
'fyp:samp-lua',
'fyp:moon-imgui',
'Akionka:lua-semver',
}
end
local sampev = require 'lib.samp.events'
local encoding = require 'encoding'
local imgui = require 'imgui'
local v = require 'semver'
local updatesAvaliable = false
local lastTagAvaliable = '1.0'
encoding.default = 'cp1251'
local u8 = encoding.UTF8
local prefixesByColor = {
[0xFF2A51E2] = 'police',
[0xFF4422FF] = 'fbi',
[0xFF33AA33] = 'army',
[0xFF4682B4] = 'gov',
}
local prefixesByTypeScriptWork = {'police', 'fbi', 'army', 'gov'}
local close_next = false
local orderList = {}
local lockedAdditional = false
local lockedGuns = false
encoding.default = 'cp1251'
u8 = encoding.UTF8
local defaultProfile = {
title = 'Profile1',
typescriptwork = 0, --[[
0 - PD,
1 - FBI,
2 - Army
3 - Goverment
]]
police_items = {
armor = false,
larmor = false,
nightvision = false,
holster = false,
shield = false,
flashlight = false,
camera = false,
bhelmet = false,
whelmet = false,
mask = false,
blkglasses = false,
redglasses = false,
bluglasses = false,
gasmask = false,
ceremonialcap = false,
officercap = false,
blkphelmet = false,
bluphelmet = false,
phelmet = false,
pcap = false,
stick = false,
vest = false,
blkhat = false,
brnhat = false,
},
fbi_items = {
armor = false,
larmor = false,
nightvision = false,
holster = false,
shield = false,
flashlight = false,
camera = false,
bhelmet = false,
whelmet = false,
mask = false,
blkglasses = false,
redglasses = false,
bluglasses = false,
gasmask = false,
},
army_items = {
armor = false,
larmor = false,
nightvision = false,
holster = false,
loudspeaker = false,
bereta = false,
beretk = false,
beretd = false,
bshield = false,
},
gov_items = {
armor = false,
icamera = false,
briefcase = false,
},
police_guns = {
stick = false,
m4 = false,
mp5 = false,
shotgun = false,
spas12 = false,
rifle = false,
deagle = false,
smkbomb = false,
srifle = false,
},
fbi_guns = {
stick = false,
m4 = false,
mp5 = false,
shotgun = false,
spas12 = false,
rifle = false,
deagle = false,
srifle = false,
sawnoff = false,
grenades = false,
smkbomb = false,
},
army_guns = {
m4 = false,
mp5 = false,
deagle = false,
rifle = false,
shotgun = false,
spas12 = false,
smkbomb = false,
srifle = false,
},
gov_guns = {
stick = false,
m4 = false,
mp5 = false,
shotgun = false,
rifle = false,
deagle = false,
smkbomb = false,
},
}
local data = {
settings = {
active = false,
alwaysAutoCheckUpdates = true,
selectedProfile = 1,
},
profiles = {
defaultProfile,
},
}
local mainWindowState = imgui.ImBool(false)
local active = imgui.ImBool(false)
local typescriptwork = imgui.ImInt(0)
local selectedProfile = 1
local selectedTab = 1
local tempBuffers = {}
-- Список названий всех возможных предметов и оружия
-- Ключ - внутрений ID предмета, значение - его название в ImGui диалоге
local names = {
items = {
['_'] = '',
armor = 'Бронежилет',
larmor = 'Легкий бронежилет',
nightvision = 'Прибор ночного видения',
holster = 'Кобура',
shield = 'Полицейский щит',
flashlight ='Фонарик',
camera = 'Фотоаппарат',
bhelmet = 'Чёрный шлем SWAT',
whelmet ='Белый шлем SWAT',
mask = 'Вязаная маска',
blkglasses = 'Очки «Police Black»',
redglasses = 'Очки «Police Red»',
bluglasses = 'Очки «Police Blue»',
gasmask = 'Противогаз',
ceremonialcap = 'Парадная фуражка',
officercap = 'Офицерская фуражка',
blkphelmet = 'Черная полицейская каска',
bluphelmet = 'Синяя полицейская каска',
phelmet = 'Шлем патрульного',
pcap = 'Полицейская кепка',
stick = 'Жезл регулировщика',
vest = 'Оранжевый жилет',
blkhat = 'Черная шляпа шерифа',
brnhat = 'Коричневая шляпа шерифа',
loudspeaker = 'Громкоговоритель',
bereta = 'Берет «Army»',
beretk = 'Берет «Krap»',
beretd = 'Берет «Desant»',
bshield = 'Баллистический щит',
icamera = 'Фотоаппарат для инспекций',
briefcase = 'Чемоданчик для инспекций',
},
guns = {
stick = 'Дубинка',
m4 = 'M4',
mp5 = 'MP5',
shotgun = 'Shotgun',
rifle = 'Rifle',
deagle = 'Desert Eagle',
srifle = 'Снайперская винтовка',
sawnoff = 'Обрез',
grenades = 'Гранаты',
smkbomb = 'Дымовая шашка',
spas12 = 'Spas-12',
},
}
-- То, как предметы расставлены в серверных диалогах
-- Значение - внутрений ID предмета
local lists = {
police_items = {
'armor',
'larmor',
'nightvision',
'holster',
'shield',
'flashlight',
'camera',
'bhelmet',
'whelmet',
'mask',
'blkglasses',
'redglasses',
'bluglasses',
'gasmask',
'ceremonialcap',
'officercap',
'blkphelmet',
'bluphelmet',
'phelmet',
'pcap',
'stick',
'vest',
'blkhat',
'brnhat',
},
fbi_items = {
'armor',
'larmor',
'nightvision',
'holster',
'shield',
'flashlight',
'camera',
'bhelmet',
'whelmet',
'mask',
'blkglasses',
'redglasses',
'bluglasses',
'gasmask',
},
army_items = {
'armor',
'larmor',
'nightvision',
'holster',
'loudspeaker',
'bereta',
'beretk',
'beretd',
'bshield',
},
gov_items = {
'armor',
'icamera',
'briefcase',
},
police_guns = {
'stick',
'm4',
'mp5',
'shotgun',
'spas12',
'rifle',
'deagle',
'smkbomb',
'srifle'
},
fbi_guns = {
'stick',
'm4',
'mp5',
'shotgun',
'spas12',
'rifle',
'deagle',
'srifle',
'sawnoff',
'grenades',
'smkbomb',
},
army_guns = {
'm4',
'mp5',
'deagle',
'rifle',
'shotgun',
'spas12',
'smkbomb',
'srifle'
},
gov_guns = {
'stick',
'm4',
'mp5',
'shotgun',
'rifle',
'deagle',
'smkbomb',
},
}
function imgui.OnDrawFrame()
if mainWindowState.v then
local resX, resY = getScreenResolution()
imgui.SetNextWindowSize(imgui.ImVec2(700, 400), 2)
imgui.SetNextWindowPos(imgui.ImVec2(resX/2, resY/2), 2, imgui.ImVec2(0.5, 0.5))
imgui.Begin('Autotaker v'..thisScript()['version'], mainWindowState, imgui.WindowFlags.NoResize)
imgui.BeginGroup()
imgui.BeginChild('Left panel', imgui.ImVec2(100, 0), true)
if imgui.Selectable('Профили', selectedTab == 1) then selectedTab = 1 end
if imgui.Selectable('Настройки', selectedTab == 2) then selectedTab = 2 end
if imgui.Selectable('Информация', selectedTab == 3) then selectedTab = 3 end
imgui.EndChild()
imgui.EndGroup()
imgui.SameLine()
if selectedTab == 1 then
imgui.BeginGroup()
imgui.BeginChild('Profiles', imgui.ImVec2(145, -imgui.GetItemsLineHeightWithSpacing() * 4 - imgui.GetStyle().ItemSpacing.y), true)
for i, v in ipairs(data['profiles']) do
if imgui.Selectable(v['title']..'##'..i, selectedProfile == i, imgui.SelectableFlags.AllowDoubleClick) then
selectedProfile = i
if imgui.IsMouseDoubleClicked(0) then
tempBuffers['title'] = imgui.ImBuffer(data['profiles'][selectedProfile]['title'], 32)
imgui.OpenPopup('Изменить настройки профиля##'..i)
end
data['settings']['selectedProfile'] = i
typescriptwork.v = data['profiles'][selectedProfile]['typescriptwork']
saveData()
end
if imgui.BeginPopupModal('Изменить настройки профиля##'..i, nil, 64) then
imgui.InputText('Название', tempBuffers['title'])
imgui.Separator()
imgui.SetCursorPosX((imgui.GetWindowWidth() - 240 + imgui.GetStyle().ItemSpacing.x) / 2)
if imgui.Button('Готово', imgui.ImVec2(120, 0)) then
data['profiles'][selectedProfile] = data['profiles'][selectedProfile]
data['profiles'][selectedProfile]['title'] = tempBuffers['title'].v
saveData()
imgui.CloseCurrentPopup()
end
imgui.SameLine()
if imgui.Button('Отмена', imgui.ImVec2(120, 0)) then imgui.CloseCurrentPopup() end
imgui.EndPopup()
end
end
imgui.EndChild()
if imgui.Button('Добавить', imgui.ImVec2(145/2-5, 0)) then
tempBuffers['title'] = imgui.ImBuffer('Profile', 32)
imgui.OpenPopup('Добавление профиля##'..#data['profiles'])
end
imgui.SameLine()
if selectedProfile ~= 0 and imgui.Button('Удалить', imgui.ImVec2(145/2-5, 0)) then
imgui.OpenPopup('Удаление профиля')
end
if imgui.BeginPopupModal('Добавление профиля##'..#data['profiles'], nil, 64) then
imgui.InputText('Название', tempBuffers['title'])
imgui.Separator()
imgui.SetCursorPosX((imgui.GetWindowWidth() - 240 + imgui.GetStyle().ItemSpacing.x) / 2)
if imgui.Button('Готово', imgui.ImVec2(120, 0)) then
table.insert(data['profiles'], table.copy(defaultProfile))
data['profiles'][#data['profiles']]['title'] = tempBuffers['title'].v..''
saveData()
imgui.CloseCurrentPopup()
end
imgui.SameLine()
if imgui.Button('Отмена', imgui.ImVec2(120, 0)) then
imgui.CloseCurrentPopup()
end
imgui.EndPopup()
end
if imgui.BeginPopupModal('Удаление профиля', nil, 2) then
imgui.Text('Удаление профиля приведет к полной потере всех данных.\nЖелаете продолжить?')
imgui.Separator()
imgui.SetCursorPosX((imgui.GetWindowWidth() - 240 + imgui.GetStyle().ItemSpacing.x) / 2)
if imgui.Button('Да', imgui.ImVec2(120, 0)) then
table.remove(data['profiles'], selectedProfile)
selectedProfile = 0
data['settings']['selectedProfile'] = 0
saveData()
imgui.CloseCurrentPopup()
end
imgui.SameLine()
if imgui.Button('Нет', imgui.ImVec2(120, 0)) then
imgui.CloseCurrentPopup()
end
imgui.EndPopup()
end
if selectedProfile ~= 0 then
imgui.Text('Режим работы')
imgui.PushItemWidth(145)
if imgui.ListBox('', typescriptwork, {'Police', 'FBI', 'Army', 'Goverment'}, imgui.ImInt(4)) then
data['profiles'][selectedProfile]['typescriptwork'] = typescriptwork.v
saveData()
end
imgui.PopItemWidth()
end
imgui.EndGroup()
imgui.SameLine()
imgui.BeginGroup()
imgui.BeginChild('Weapons', imgui.ImVec2(145, 0), true)
if selectedProfile ~= 0 then
for k, v in pairs(lists[getPrefixByTypeScriptWork() .. '_guns']) do
if imgui.Selectable(names['guns'][v], data['profiles'][selectedProfile][getPrefixByTypeScriptWork() .. '_guns'][v]) then
data['profiles'][selectedProfile][getPrefixByTypeScriptWork() .. '_guns'][v] = not data['profiles'][selectedProfile][getPrefixByTypeScriptWork() .. '_guns'][v]
saveData()
end
end
end
imgui.EndChild()
imgui.EndGroup()
imgui.SameLine()
imgui.BeginGroup()
imgui.BeginChild('Items', imgui.ImVec2(0, 0), true)
if selectedProfile ~= 0 then
for k, v in pairs(lists[getPrefixByTypeScriptWork() .. '_items']) do
if imgui.Selectable(names['items'][v], data['profiles'][selectedProfile][getPrefixByTypeScriptWork() .. '_items'][v]) then
data['profiles'][selectedProfile][getPrefixByTypeScriptWork() .. '_items'][v] = not data['profiles'][selectedProfile][getPrefixByTypeScriptWork() .. '_items'][v]
saveData()
end
end
end
imgui.EndChild()
imgui.EndGroup()
elseif selectedTab == 2 then
imgui.BeginGroup()
imgui.BeginChild('Settings')
if imgui.Checkbox('Всегда автоматически проверять обновления', imgui.ImBool(data['settings']['alwaysAutoCheckUpdates'])) then
data['settings']['alwaysAutoCheckUpdates'] = not data['settings']['alwaysAutoCheckUpdates']
saveData()
end
if imgui.Checkbox('Активно?', imgui.ImBool(data['settings']['active'])) then
data['settings']['active'] = not data['settings']['active']
saveData()
end
imgui.EndChild()
imgui.EndGroup()
elseif selectedTab == 3 then
imgui.BeginGroup()
imgui.BeginChild('Information')
imgui.Text('Название: Autotaker')
imgui.Text('Автор: Akionka')
imgui.Text('Версия: '..thisScript()['version_num']..' ('..thisScript()['version']..')')
imgui.Text('Команды: /autotaker')
if getMoonloaderVersion() >= 027 and updatesAvaliable and imgui.Button('Скачать обновление', imgui.ImVec2(150, 0)) then
update()
mainWindowState.v = false
end
if getMoonloaderVersion() >= 027 and not updatesAvaliable and imgui.Button('Проверить обновления', imgui.ImVec2(150, 0)) then
checkUpdates()
end
if getMoonloaderVersion() >= 027 then imgui.SameLine() end
if imgui.Button('Группа ВКонтакте', imgui.ImVec2(150, 0)) then os.execute('explorer "https://vk.com/akionkamods"') end
if imgui.Button('Bug report [VK]', imgui.ImVec2(150, 0)) then os.execute('explorer "https://vk.com/akionka"') end
imgui.SameLine()
if imgui.Button('Bug report [Telegram]', imgui.ImVec2(150, 0)) then os.execute('explorer "https://t.me/akionka"') end
imgui.EndChild()
imgui.EndGroup()
end
imgui.End()
end
end
function get_pickup_model(id, handle)
return readMemory(id * 20 + 61444 + sampGetPickupPoolPtr(), 4, true)
end
function sampev.onSendPickedUpPickup(id)
if not data['settings']['active'] then
return
end
local pickup = sampGetPickupHandleBySampId(id)
local pickuppoolPtr = sampGetPickupPoolPtr()
if getPrefixByPlayerColor == nil then return true end
-- Дополнительное снаряжение
if get_pickup_model(id, pickup) == 1242 then
if lockedAdditional then return false end
if #orderList ~= 0 then return end
for k, v in pairs(data['profiles'][selectedProfile][getPrefixByPlayerColor() .. '_items']) do
if v then
local i = searchForItem(lists[getPrefixByPlayerColor() .. '_items'], k)
table.insert(orderList, i - ((getPrefixByPlayerColor() == 'police' or getPrefixByPlayerColor() == 'fbi') and 0 or 1))
end
end
end
-- Оружейная
if get_pickup_model(id, pickup) == 2061 then
if lockedGuns then return false end
if #orderList ~= 0 then return end
for k, v in pairs(data['profiles'][selectedProfile][getPrefixByPlayerColor() .. '_guns']) do
if v then
local i = searchForItem(lists[getPrefixByPlayerColor() .. '_guns'], k)
table.insert(orderList, i - 1)
end
end
end
end
function sampev.onShowDialog(id, stytle, title, btn1, btn2, text)
print(id, stytle, title, btn1, btn2)
-- Диалог "Дополнительное снаряжения"
if (id == 81 or id == 83) and data['settings']['active'] then
if #orderList == 0 then
lockedAdditional = true
alert('Можете отходить от пикапа. В течение следующих {9932cc}6 секунд{FFFFFF} он будет неактивен')
lua_thread.create(function()
wait(6000)
lockedAdditional = false
end)
sampSendDialogResponse(id, 0, 0, '')
return false
end
for k, v in pairs(orderList) do
print(k, v)
if v then
close_next = true
sampSendDialogResponse(id, 1, orderList[1], '')
return false
end
end
end
-- Диалог с текстом "Вот ваш(а) ..."
if (id == 82 or id == 83 or id == 84 or id == 45) and close_next then
table.remove(orderList, 1)
close_next = false
sampSendDialogResponse(id, 1, 0, '')
return false
end
-- Диалог "Оружейная"
if (id == 76 or id == 77 or id == 78) and data['settings']['active'] then
for k, v in pairs(orderList) do
sampSendDialogResponse(id, 1, orderList[1], '')
table.remove(orderList, 1)
if #orderList == 0 then
lockedGuns = true
alert('Можете отходить от пикапа. В течение следующих {9932cc}6 секунд{FFFFFF} он будет неактивен')
lua_thread.create(function()
wait(6000)
lockedGuns = false
end)
return false
end
return false
end
end
return {id, stytle, id..' | '..title, btn1, btn2, text}
end
function applyCustomStyle()
imgui.SwitchContext()
local style = imgui.GetStyle()
local colors = style.Colors
local clr = imgui.Col
local function ImVec4(color)
local r = bit.band(bit.rshift(color, 24), 0xFF)
local g = bit.band(bit.rshift(color, 16), 0xFF)
local b = bit.band(bit.rshift(color, 8), 0xFF)
local a = bit.band(color, 0xFF)
return imgui.ImVec4(r/255, g/255, b/255, a/255)
end
style['WindowRounding'] = 10.0
style['WindowTitleAlign'] = imgui.ImVec2(0.5, 0.5)
style['ChildWindowRounding'] = 5.0
style['FrameRounding'] = 5.0
style['ItemSpacing'] = imgui.ImVec2(5.0, 5.0)
style['ScrollbarSize'] = 13.0
style['ScrollbarRounding'] = 5
colors[clr['Text']] = ImVec4(0xFFFFFFFF)
colors[clr['TextDisabled']] = ImVec4(0x212121FF)
colors[clr['WindowBg']] = ImVec4(0x212121FF)
colors[clr['ChildWindowBg']] = ImVec4(0x21212180)
colors[clr['PopupBg']] = ImVec4(0x212121FF)
colors[clr['Border']] = ImVec4(0xFFFFFF10)
colors[clr['BorderShadow']] = ImVec4(0x21212100)
colors[clr['FrameBg']] = ImVec4(0xC3E88D90)
colors[clr['FrameBgHovered']] = ImVec4(0xC3E88DFF)
colors[clr['FrameBgActive']] = ImVec4(0x61616150)
colors[clr['TitleBg']] = ImVec4(0x212121FF)
colors[clr['TitleBgActive']] = ImVec4(0x212121FF)
colors[clr['TitleBgCollapsed']] = ImVec4(0x212121FF)
colors[clr['MenuBarBg']] = ImVec4(0x21212180)
colors[clr['ScrollbarBg']] = ImVec4(0x212121FF)
colors[clr['ScrollbarGrab']] = ImVec4(0xEEFFFF20)
colors[clr['ScrollbarGrabHovered']] = ImVec4(0xEEFFFF10)
colors[clr['ScrollbarGrabActive']] = ImVec4(0x80CBC4FF)
colors[clr['ComboBg']] = colors[clr['PopupBg']]
colors[clr['CheckMark']] = ImVec4(0x212121FF)
colors[clr['SliderGrab']] = ImVec4(0x212121FF)
colors[clr['SliderGrabActive']] = ImVec4(0x80CBC4FF)
colors[clr['Button']] = ImVec4(0xC3E88D90)
colors[clr['ButtonHovered']] = ImVec4(0xC3E88DFF)
colors[clr['ButtonActive']] = ImVec4(0x61616150)
colors[clr['Header']] = ImVec4(0x151515FF)
colors[clr['HeaderHovered']] = ImVec4(0x252525FF)
colors[clr['HeaderActive']] = ImVec4(0x303030FF)
colors[clr['Separator']] = colors[clr['Border']]
colors[clr['SeparatorHovered']] = ImVec4(0x212121FF)
colors[clr['SeparatorActive']] = ImVec4(0x212121FF)
colors[clr['ResizeGrip']] = ImVec4(0x212121FF)
colors[clr['ResizeGripHovered']] = ImVec4(0x212121FF)
colors[clr['ResizeGripActive']] = ImVec4(0x212121FF)
colors[clr['CloseButton']] = ImVec4(0x212121FF)
colors[clr['CloseButtonHovered']] = ImVec4(0xD41223FF)
colors[clr['CloseButtonActive']] = ImVec4(0xD41223FF)
colors[clr['PlotLines']] = ImVec4(0x212121FF)
colors[clr['PlotLinesHovered']] = ImVec4(0x212121FF)
colors[clr['PlotHistogram']] = ImVec4(0x212121FF)
colors[clr['PlotHistogramHovered']] = ImVec4(0x212121FF)
colors[clr['TextSelectedBg']] = ImVec4(0x212121FF)
colors[clr['ModalWindowDarkening']] = ImVec4(0x21212180)
end
function main()
if not isSampfuncsLoaded() or not isSampLoaded() then return end
while not isSampAvailable() do wait(0) end
if not doesDirectoryExist(getWorkingDirectory()..'\\config') then createDirectory(getWorkingDirectory()..'\\config') end
applyCustomStyle()
loadData()
print(u8:decode('{FFFFFF}Скрипт успешно загружен.'))
print(u8:decode('{FFFFFF}Версия: {9932cc}'..thisScript()['version']..'{FFFFFF}. Автор: {9932cc}Akionka{FFFFFF}.'))
print(u8:decode('{FFFFFF}Приятного использования! :)'))
if data['settings']['alwaysAutoCheckUpdates'] and getMoonloaderVersion() >= 027 then
checkUpdates()
end
sampRegisterChatCommand('autotaker', function()
mainWindowState.v = not mainWindowState.v
end)
while true do
wait(0)
imgui.Process = mainWindowState.v
end
end
function checkUpdates()
local fpath = os.tmpname()
if doesFileExist(fpath) then os.remove(fpath) end
downloadUrlToFile('https://api.github.com/repos/akionka/'..thisScript()['name']..'/releases', fpath, function(_, status, _, _)
if status == 58 then
if doesFileExist(fpath) then
local f = io.open(fpath, 'r')
if f then
local info = decodeJson(f: read('*a'))
f:close()
os.remove(fpath)
if v(info[1]['tag_name']) > v(thisScript()['version']) then
updatesAvaliable = true
lastTagAvaliable = info[1]['tag_name']
alert('Найдено объявление. Текущая версия: {9932cc}'..thisScript()['version']..'{FFFFFF}, новая версия: {9932cc}'..info[1]['tag_name']..'{FFFFFF}')
return true
else
updatesAvaliable = false
alert('У вас установлена самая свежая версия скрипта')
end
else
updatesAvaliable = false
alert('Что-то пошло не так, упс. Попробуйте позже')
end
end
end
end)
end
function update()
downloadUrlToFile('https://github.com/akionka/'..thisScript()['name']..'/releases/download/'..lastTagAvaliable..'/autotaker.lua', thisScript()['path'], function(_, status, _, _)
if status == 6 then
alert('Новая версия установлена! Чтобы скрипт обновился нужно либо перезайти в игру, либо ...')
alert('... если у вас есть автоперезагрузка скриптов, то новая версия уже готова и снизу вы увидите приветственное сообщение')
alert('Если что-то пошло не так, то сообщите мне об этом в VK или Telegram > {2980b0}vk.com/akionka t.me/akionka{FFFFFF}')
thisScript():reload()
end
end)
end
function loadData()
if not doesFileExist(getWorkingDirectory()..'\\config\\autotaker.json') then
local configFile = io.open(getWorkingDirectory()..'\\config\\autotaker.json', 'w+')
configFile:write(encodeJson(data))
configFile:close()
return
end
local configFile = io.open(getWorkingDirectory()..'\\config\\autotaker.json', 'r')
data = decodeJson(configFile:read('*a'))
configFile:close()
active.v = data['settings']['active'] or false
selectedProfile = data['settings']['selectedProfile'] or 1
if selectedProfile == 0 then return end
if selectedProfile < 0 or selectedProfile > #data['profiles'] then
selectedProfile = 0
return
end
typescriptwork.v = data['profiles'][selectedProfile]['typescriptwork'] or 0
end
function saveData()
local configFile = io.open(getWorkingDirectory()..'\\config\\autotaker.json', 'w+')
configFile:write(encodeJson(data))
configFile:close()
end
function alert(text)
local prefix = 'Autotaker'
sampAddChatMessage(u8:decode('[' .. prefix .. ']: ' .. text), -1)
end
function searchForItem(table, item)
for i, v in ipairs(table) do
if v == item then return i end
end
end
function getPrefixByPlayerColor()
local res, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
local color = sampGetPlayerColor(id)
return prefixesByColor[color] or ''
end
function getPrefixByTypeScriptWork()
return prefixesByTypeScriptWork[data['profiles'][selectedProfile]['typescriptwork'] + 1]
end
function table.copy(t)
local new_t = {}
for k, v in pairs(t) do
if type(v) == 'table' then
new_t[k] = table.copy(v)
end
end
return new_t
end