-
Notifications
You must be signed in to change notification settings - Fork 1
/
taximate.lua
4203 lines (3936 loc) · 172 KB
/
taximate.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
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
script_author("21se")
script_moonloader(026)
script_version("1.3.7")
script_version_number(61)
script_url("github.com/21se/Taximate")
script_name(string.format("Taximate v%s (%d)", thisScript().version, thisScript().version_num))
local script_updates = {update = false}
local script_branch = "master"
local moonloader = require "moonloader"
local inicfg = require "inicfg"
local encoding = require "encoding"
local vkeys = require "vkeys"
local sampev = require "samp.events"
local imgui = require "imgui"
encoding.default = "CP1251"
local u8 = encoding.UTF8
local chat, orders, vehicle
local player, sounds, binds, ini
local notificationsQueue = {}
local fastMapKey = 0
local VEHICLE_MODEL_IDS = {
["Premier"] = 420,
["Cabbie"] = 438,
["Sentinel"] = 405,
["Sultan"] = 560,
["Buffalo"] = 402
}
local COLOR_LIST = {
"[0] Без цвета",
"[1] Зелёный",
"[2] Светло-зелёный",
"[3] Ярко-зелёный",
"[4] Бирюзовый",
"[5] Жёлто-зелёный",
"[6] Тёмно-зелёный",
"[7] Серо-зелёный",
"[8] Красный",
"[9] Ярко-красный",
"[10] Оранжевый",
"[11] Коричневый",
"[12] Тёмно-красный",
"[13] Серо-красный",
"[14] Жёлто-оранжевый",
"[15] Малиновый",
"[16] Розовый",
"[17] Синий",
"[18] Голубой",
"[19] Синяя сталь",
"[20] Cине-зелёный",
"[21] Тёмно-синий",
"[22] Фиолетовый",
"[23] Индиго",
"[24] Серо-синий",
"[25] Жёлтый",
"[26] Кукурузный",
"[27] Золотой",
"[28] Старое золото",
"[29] Оливковый",
"[30] Серый",
"[31] Серебро",
"[32] Чёрный",
"[33] Белый"
}
local MESSAGES = {
newOrder = "^ %[Таксопарк%] Диспетчер: Вызов от [a-zA-Z0-9_]+%[%d+%] .+%. Примерное расстояние .+м$",
newOrderFormat = "^ %[Таксопарк%] Диспетчер: Вызов от (.+)%[(%d+)%] .+%. Примерное расстояние (.+)$",
orderAccepted = "^ %[Таксопарк%] Диспетчер: [a-zA-Z0-9_]+%[%d+%] принял[а]? вызов от [a-zA-Z0-9_]+%[%d+%]$",
orderAcceptedFormat = "^ %[Таксопарк%] Диспетчер: (.+)%[%d+%] принял[а]? вызов от (.+)%[%d+%]$",
wrongPerson = " ^%[Таксопарк%] Диспетчер: Вызов от этого человека не поступал$",
orderCanceled = "^ %[Таксопарк%] Диспетчер: [a-zA-Z0-9_]+%[%d+%] отменил вызов$",
orderCanceledFormat = "^ %[Таксопарк%] Диспетчер: (.+)%[%d+%] отменил вызов$",
orderCanceledByTaxi = "^ %[Таксопарк%] Диспетчер: Вы отказались от вызова$",
orderCanceledByQuit = "^ %[Таксопарк%] Диспетчер: (.+) отменил вызов %(Выход из игры%)$",
noOrders1 = "^ Вызовов не поступало$",
noOrders2 = " ^%[Таксопарк%] Диспетчер: От вас вызовов не поступало$",
enterService1 = "^ Введите: /service$",
enterService2 = "^ Введите: /service %[call / ac / cancel / chat%] %[police / medic / mechanic / food / taxi%]$",
clist = "^ Цвет выбран$",
payCheck = "^ Вы заработали .+ вирт. Деньги будут зачислены на ваш банковский счет в .+$",
payCheckFormat = "^ Вы заработали (.+) / (.+) вирт. Деньги будут зачислены на ваш банковский счет в .+$",
service = "^ %(%( Введите '/service' чтобы принять вызов %)%)$",
GPS = "^ '.+' помечено на карте красной меткой. Дистанция .+ метров$",
finishWork = "^ {00A86B}Используйте телефон {FFFFFF}%(%( /call %)%){00A86B} чтобы вызвать механика / таксиста$",
passengerOut = "^ Пассажир вышел из такси. Использован купон на бесплатный проезд$",
passengerOutFree = "^ Пассажир вышел из такси. Деньги будут зачислены во время зарплаты$",
pay = "^ Вы получили (%d+) вирт, от [a-zA-Z0-9_]+%[%d+%]$",
payFormat = "Вы получили (%d+) вирт, от (.+)%[",
payDay = "^=.+=%[.+:.+%]=.+=$",
antiFlood = "^ Не флуди!$",
taxiChecker = "<< Бесплатное такси >>",
skill = "Скилл: (%d+) Опыт: .+ (%d+%.%d+)%%",
rank = "Ранг: (%d+) Опыт: .+ (%d+%.%d+)%%",
order = "([a-zA-Z0-9_]+)%[ID:(%d+)%](.+[^%d.])(%d.+).+%(",
repair = "^ Механик [a-zA-Z0-9_]+ хочет отремонтировать ваш автомобиль за %d+ вирт{FFFFFF} %(%( Нажмите Y/N для принятия/отмены %)%)$",
refill = "^ Механик [a-zA-Z0-9_]+ хочет заправить ваш автомобиль за %d+ вирт{FFFFFF} %(%( Нажмите Y/N для принятия/отмены %)%)$",
refillFormat = "^ Механик .+ хочет заправить ваш автомобиль за (%d+) вирт{FFFFFF} %(%( Нажмите Y/N для принятия/отмены %)%)$",
fuelClassic = "FUEL ~w~%d+",
fuelClassicFormat = "FUEL ~w~(%d+)",
currentOrderTextdraw = "([a-zA-Z0-9_]+)~n~distance: (%d+)m",
currentOrderTextdrawInDoors = "([a-zA-Z0-9_]+)~n~~r~%[indoors%]"
}
local FORMAT_NOTIFICATIONS = {
newOrder = "Вызов от {4296f9}%s[%s]{ffffff} (%s)\nДистанция: {4296f9}%s",
orderAccepted = "Принят вызов от {4296f9}%s[%s]\nДистанция: {4296f9}%s",
cruiseControlEnabled = "Круиз-контроль {42ff96}включён",
cruiseControlDisabled = "Круиз-контроль {d44331}выключен"
}
function main()
if not isSampLoaded() or not isSampfuncsLoaded() then
return
end
while not isSampAvailable() do
wait(100)
end
repeat
wait(100)
until sampGetCurrentServerName() ~= "SA-MP"
addEventHandler("onReceiveRpc", onReceiveRpc)
local _, playerID = sampGetPlayerIdByCharHandle(PLAYER_PED)
player.nickname = sampGetPlayerNickname(playerID)
player.id = playerID
chat.sendMessage("Меню настроек скрипта - {00CED1}/tm{FFFFFF}, страница скрипта: {00CED1}" .. thisScript().url)
repeat
wait(100)
until sampGetPlayerScore(player.id) ~= 0
if not doesDirectoryExist(getWorkingDirectory() .. "/config") then
createDirectory(getWorkingDirectory() .. "/config")
end
if not doesDirectoryExist(getWorkingDirectory() .. "/config/Taximate") then
createDirectory(getWorkingDirectory() .. "/config/Taximate")
end
ini = inicfg.load({settings = ini.settings}, "Taximate/settings.ini")
imgui.initBuffers()
sounds.loadSound("new_order")
sounds.loadSound("correct_order")
sounds.loadSound("new_passenger")
imgui.ApplyCustomStyle()
imgui.GetIO().Fonts:AddFontFromFileTTF(
"C:/Windows/Fonts/arial.ttf",
toScreenX(6),
nil,
imgui.GetIO().Fonts:GetGlyphRangesCyrillic()
)
binds.list = binds.get()
blacklist.players = blacklist.get()
blacklist.sortNicknames()
imgui.Process = true
chat.initQueue()
player.connected = true
lua_thread.create(binds.pressProcessingThread)
lua_thread.create(chat.checkQueueThread)
lua_thread.create(chat.disableFrozenMessagesProcessingThread)
lua_thread.create(vehicle.refreshInfoThread)
lua_thread.create(orders.deleteOrdersThread)
lua_thread.create(updateTextdrawInfoThread)
sampRegisterChatCommand(
"taximate",
function()
imgui.showSettings.v = not imgui.showSettings.v
end
)
sampRegisterChatCommand(
"tm",
function()
imgui.showSettings.v = not imgui.showSettings.v
end
)
sampRegisterChatCommand(
"tmup",
function()
checkUpdates(false)
update()
end
)
sampRegisterChatCommand("tmblacklist", blacklist.command)
sampRegisterChatCommand("tmbl", blacklist.command)
if ini.settings.checkUpdates then
lua_thread.create(checkUpdates)
end
if doesFileExist(getGameDirectory() .. "/map.asi") and doesFileExist(getGameDirectory() .. "/map.ini") then
local fastMap = inicfg.load(_, getGameDirectory() .. "/map.ini")
fastMapKey = fastMap.MAP.key
fastMap = nil
end
while true do
wait(0)
imgui.ShowCursor = false
if player.onWork then
local result, orderNickname, orderDistance, orderClock = orders.get()
if result then
orders.handle(orderNickname, orderDistance, orderClock)
end
orders.autoAccept = table.isEmpty(vehicle.passengersList) and not orders.currentOrder
orders.refreshCurrentOrder()
if ini.settings.ordersDistanceUpdate then
orders.updateOrdersDistance()
end
if isKeysPressed(ini.settings.key3, ini.settings.key3add, false) and ini.settings.hotKeys then
player.onWork = false
if ini.settings.autoClist then
chat.addMessageToQueue("/clist 0", true, true)
end
if orders.currentOrder then
if orders.currentOrderTextdrawExist then
orders.startOrderCanceling()
else
orders.cancelCurrentOrder(true)
end
end
end
if isKeyJustPressed(vkeys.VK_2) then
if vehicle.name then
chat.antifloodClock = os.clock()
end
end
if not orders.currentOrder then
if orders.lastCorrectOrderNickname then
if isKeysPressed(ini.settings.key2, ini.settings.key2add, false) and ini.settings.hotKeys then
orders.accept(orders.lastCorrectOrderNickname, orders.lastCorrectOrderClock)
end
end
else
if isKeysPressed(ini.settings.key2, ini.settings.key2add, false) and ini.settings.hotKeys then
if orders.currentOrderTextdrawExist then
orders.startOrderCanceling()
else
orders.cancelCurrentOrder(true)
end
end
end
elseif orders.currentOrder then
if orders.currentOrderTextdrawExist then
if os.clock() - orders.lastOrderCanceling > 2 then
orders.startOrderCanceling()
orders.lastOrderCanceling = os.clock()
end
else
orders.cancelCurrentOrder(true)
end
else
orders.autoAccept = false
if isKeysPressed(ini.settings.key3, ini.settings.key3add, false) and ini.settings.hotKeys then
player.onWork = true
if ini.settings.autoClist and ini.settings.workClist ~= 0 then
chat.addMessageToQueue("/clist " .. ini.settings.workClist, true, true)
end
end
end
if ini.settings.markers and vehicle.name then
vehicle.drawMarkers()
else
vehicle.clearMarkers()
end
if ini.settings.cruiseControl then
vehicle.cruiseControl()
else
vehicle.cruiseControlEnabled = false
end
end
end
chat = {
queue = {},
queueSize = 10,
antifloodClock = os.clock(),
lastMessage = "",
antifloodDelay = 0.6,
dialogClock = os.clock(),
hiddenMessages = {
["/service"] = {bool = false, dialog = true, clock = os.clock()},
["/paycheck"] = {bool = false, dialog = false, clock = os.clock()},
["/clist"] = {bool = false, dialog = false, clock = os.clock()},
["/jskill"] = {bool = false, dialog = true, clock = os.clock()},
["/gps"] = {bool = false, dialog = true, clock = os.clock()}
}
}
function chat.sendMessage(...)
local message = ""
local pack = table.pack(...)
for i = 1, pack.n do
message = message .. tostring(pack[i]) .. " "
end
sampAddChatMessage(
u8:decode("\
{00CED1}[Taximate v" .. thisScript().version .. "]{FFFFFF} " .. message),
0xFFFFFF
)
end
function chat.updateAntifloodClock()
chat.antifloodClock = os.clock()
if string.sub(chat.lastMessage, 1, 5) == "/sms " or string.sub(chat.lastMessage, 1, 3) == "/t " then
chat.antifloodClock = chat.antifloodClock + 0.5
end
end
function chat.disableFrozenMessagesProcessingThread()
while true do
wait(1000)
for key, value in pairs(chat.hiddenMessages) do
if os.clock() - value.clock > 5 and value.bool then
value.bool = false
end
end
if os.clock() - orders.lastAcceptedOrderClock > 5 and orders.acceptedNickname ~= nil then
orders.acceptedNickname = nil
end
end
end
function chat.checkQueueThread()
while true do
wait(0)
for messageIndex = 1, chat.queueSize do
local message = chat.queue[messageIndex]
if message.message ~= "" then
if string.sub(chat.lastMessage, 1, 1) ~= "/" and string.sub(message.message, 1, 1) ~= "/" then
chat.antifloodDelay = chat.antifloodDelay + 0.5
end
if os.clock() - chat.antifloodClock > chat.antifloodDelay then
local sendMessage = true
local command = string.match(message.message, "^(/[^ ]*).*")
if message.hideResult then
if chat.hiddenMessages[command] then
if chat.hiddenMessages[command].bool then
chat.hiddenMessages[command].bool = false
sendMessage = false
else
chat.hiddenMessages[command].bool =
(not sampIsDialogActive() or not chat.hiddenMessages[command].dialog) and
chat.dialogClock < os.clock()
chat.hiddenMessages[command].clock = os.clock()
sendMessage = chat.hiddenMessages[command].bool
end
end
end
if sendMessage then
if message.message == "/en" then
sendMessage = vehicle.maxPassengers and not isCarEngineOn(vehicle.handle)
elseif message.message:find("/service ac taxi") then
sendMessage = not orders.currentOrder
end
end
if sendMessage then
chat.lastMessage = u8:decode(message.message)
sampSendChat(u8:decode(message.message))
end
message.hideResult = false
message.message = ""
end
chat.antifloodDelay = 0.6
end
end
end
end
function chat.subSMSText(prefix, text)
if text:find("{zone}") then
local posX, posY = getCharCoordinates(PLAYER_PED)
text = text:gsub("{zone}", getZone(posX, posY))
end
if orders.currentOrder then
text = text:gsub("{distance}", metersToString(orders.currentOrder.currentDistance, false))
else
text = text:gsub("{distance}", "123 м")
end
if vehicle.name then
text = text:gsub("{carname}", vehicle.name)
else
text = text:gsub("{carname}", "Sentinel")
end
if prefix ~= "" then
prefix = prefix .. " "
end
return prefix .. text
end
function chat.sendNotification(order)
if ini.settings.sendSMS then
if not order.arrived and order.showMark then
if order.currentDistance < 30 and ini.settings.SMSArrival ~= "" then
chat.addMessageToQueue(
string.format(
"/service chat %s", chat.subSMSText(ini.settings.SMSPrefix, ini.settings.SMSArrival)
)
)
order.arrived = true
elseif order.SMSClock < os.clock() and order.updateDistance and ini.settings.SMSText ~= "" then
chat.addMessageToQueue(
string.format("/service chat %s", chat.subSMSText(ini.settings.SMSPrefix, ini.settings.SMSText))
)
if
order.firstSMS and vehicle.maxPassengers == 1 and ini.settings.seatsNotify and
ini.settings.SMSSeats ~= ""
then
chat.addMessageToQueue(
string.format(
"/service chat %s", chat.subSMSText(ini.settings.SMSPrefix, ini.settings.SMSSeats)
)
)
order.firstSMS = false
end
order.SMSClock = os.clock() + ini.settings.SMSTimer
end
end
end
end
function chat.handleInputMessage(message)
lua_thread.create(
function()
if string.find(message, MESSAGES.newOrder) then
local time = os.clock()
local nickname, id, distance = string.match(message, MESSAGES.newOrderFormat)
distance = stringToMeters(distance)
orders.add(nickname, id, distance, time)
elseif string.find(message, MESSAGES.orderCanceled) then
local nickname = string.match(message, MESSAGES.orderCanceledFormat)
if orders.currentOrder then
if orders.currentOrder.nickname == nickname then
orders.cancelCurrentOrder(false)
end
end
elseif string.find(message, MESSAGES.orderCanceledByTaxi) then
orders.cancelCurrentOrder(true)
elseif string.find(message, MESSAGES.orderCanceledByQuit) then
local nickname = string.match(message, MESSAGES.orderCanceledByQuit)
if orders.currentOrder then
if orders.currentOrder.nickname == nickname then
orders.cancelCurrentOrder(false)
end
end
elseif string.find(message, MESSAGES.orderAccepted) then
local driverNickname, passengerNickname = string.match(message, MESSAGES.orderAcceptedFormat)
if driverNickname == player.nickname and player.onWork then
if vehicle.maxPassengers and ini.settings.startEngine then
if not isCarEngineOn(vehicle.handle) then
chat.addMessageToQueue("/en")
end
end
if orders.currentOrder then
if orders.currentOrder.nickname ~= passengerNickname then
if ini.settings.notifications and ini.settings.sounds then
sounds.play("new_order")
end
if ini.settings.notifications then
imgui.addNotification(
string.format(
FORMAT_NOTIFICATIONS.orderAccepted,
orders.list[passengerNickname].nickname,
orders.list[passengerNickname].id,
metersToString(orders.list[passengerNickname].distance)
),
10
)
end
end
elseif orders.list[passengerNickname] then
if ini.settings.notifications and ini.settings.sounds then
sounds.play("new_order")
end
if ini.settings.notifications then
imgui.addNotification(
string.format(
FORMAT_NOTIFICATIONS.orderAccepted,
orders.list[passengerNickname].nickname,
orders.list[passengerNickname].id,
metersToString(orders.list[passengerNickname].distance)
),
10
)
end
orders.currentOrder = orders.list[passengerNickname]
orders.currentOrder.SMSClock = os.clock()
end
end
orders.delete(passengerNickname)
elseif string.find(message, MESSAGES.GPS) and player.onWork and not orders.currentOrder then
local text = "Метка на карте обновлена"
local result, x, y = getGPSMarkCoords3d()
if result then
text = text .. "\nРайон: {4296f9}" .. getZone(x, y)
if ini.settings.notifications and ini.settings.sounds then
sounds.play("correct_order")
end
if ini.settings.notifications then
imgui.addNotification(text, 5)
end
end
elseif
string.find(message, MESSAGES.finishWork) and player.onWork and ini.settings.finishWork and
not orders.currentOrder
then
player.onWork = false
if ini.settings.autoClist and not chat.hiddenMessages["/clist"].bool then
chat.addMessageToQueue("/clist 0", true, true)
end
elseif string.find(message, MESSAGES.passengerOut) or string.find(message, MESSAGES.passengerOutFree) then
player.refresh()
elseif string.find(message, MESSAGES.pay) then
local sum, nickname = string.match(message, MESSAGES.payFormat)
if table.contains(nickname, vehicle.lastPassengersList) then
player.tips = player.tips + sum
end
elseif string.find(message, MESSAGES.payDay) then
player.tips = 0
player.refresh()
elseif string.find(message, MESSAGES.antiFlood) then
chat.updateAntifloodClock()
for qMessage in pairs(chat.hiddenMessages) do
chat.hiddenMessages[qMessage].bool = false
end
orders.acceptedNickname = nil
elseif string.find(message, MESSAGES.repair) and ini.settings.autoRepair then
if isCharInAnyCar(PLAYER_PED) then
local vehicleHandle = storeCarCharIsInNoSave(PLAYER_PED)
if getCarHealth(vehicleHandle) ~= 1000 then
chat.addMessageToQueue("/ac repair")
else
chat.addMessageToQueue("/cancel repair")
end
end
elseif string.find(message, MESSAGES.refill) and ini.settings.autoRefill and vehicle.fuel then
local cost = tonumber(string.match(message, MESSAGES.refillFormat))
if cost <= ini.settings.maxAutoRefillCost and vehicle.fuel <= ini.settings.autoRefillGauge then
chat.addMessageToQueue("/ac refill")
else
chat.addMessageToQueue("/cancel refill")
end
end
end
)
end
function chat.initQueue()
chat.queue[1] = {message = "/jskill", hideResult = true}
chat.queue[2] = {message = "/paycheck", hideResult = true}
for messageIndex = 3, chat.queueSize do
chat.queue[messageIndex] = {message = "", hideResult = false}
end
end
function chat.addMessageToQueue(string, nonRepeat, hideResult)
local isRepeat = false
local nonRepeat = nonRepeat or false
local hideResult = hideResult or false
if nonRepeat then
for messageIndex = 1, chat.queueSize do
if string == chat.queue[messageIndex].message then
isRepeat = true
end
end
end
if not isRepeat then
for messageIndex = 1, chat.queueSize - 1 do
chat.queue[messageIndex].message = chat.queue[messageIndex + 1].message
chat.queue[messageIndex].hideResult = chat.queue[messageIndex + 1].hideResult
end
chat.queue[chat.queueSize].message = string
chat.queue[chat.queueSize].hideResult = hideResult
end
end
orders = {
list = {},
canceled = {},
GPSMark = nil,
autoAccept = false,
lastAcceptedOrderClock = os.clock(),
lastCorrectOrderNickname = nil,
lastCorrectOrderClock = os.clock(),
acceptedNickname = nil,
updateOrdersDistanceClock = os.clock(),
currentOrder = nil,
currentOrderBlip = nil,
currentOrderCheckpoint = nil,
lastOrderCanceling = os.clock(),
currentOrderTextdrawExist = false
}
function orders.startOrderCanceling()
chat.addMessageToQueue(
string.format("/service chat %s", chat.subSMSText(ini.settings.SMSPrefix, ini.settings.SMSCancel))
)
chat.addMessageToQueue("/service cancel taxi", true, true)
end
function orders.cancelCurrentOrder(canceledByTaxi)
if ini.settings.notifications and ini.settings.sounds then
sounds.play("correct_order")
end
if ini.settings.notifications then
imgui.addNotification("Вызов отменён\nМетка на карте удалена", 5)
end
if canceledByTaxi then
orders.canceled[orders.currentOrder.nickname] = os.clock()
orders.removeGPSMark()
end
orders.currentOrder = nil
end
function orders.removeGPSMark()
if orders.currentOrderBlip then
deleteCheckpoint(orders.currentOrderCheckpoint)
removeBlip(orders.currentOrderBlip)
orders.currentOrderBlip = nil
orders.currentOrderCheckpoint = nil
end
chat.addMessageToQueue("/gps", true, true)
end
function orders.calculate2dCoords(circle1, circle2, circle3)
local dX = circle2.x - circle1.x
local dY = circle2.y - circle1.y
local d = math.sqrt((dY * dY) + (dX * dX))
if d > (circle1.radius + circle2.radius) then
return false
end
if d < math.abs(circle1.radius - circle2.radius) then
return false
end
local a = ((circle1.radius * circle1.radius) - (circle2.radius * circle2.radius) + (d * d)) / (2.0 * d)
local point2X = circle1.x + (dX * a / d)
local point2Y = circle1.y + (dY * a / d)
local h = math.sqrt((circle1.radius * circle1.radius) - (a * a))
local rX = -dY * (h / d)
local rY = dX * (h / d)
local intersectionPoint1X = point2X + rX
local intersectionPoint2X = point2X - rX
local intersectionPoint1Y = point2Y + rY
local intersectionPoint2Y = point2Y - rY
dX = intersectionPoint1X - circle3.x
dY = intersectionPoint1Y - circle3.y
local d1 = math.sqrt((dY * dY) + (dX * dX))
dX = intersectionPoint2X - circle3.x
dY = intersectionPoint2Y - circle3.y
local d2 = math.sqrt((dY * dY) + (dX * dX))
if math.abs(d1 - circle3.radius) < math.abs(d2 - circle3.radius) then
return true, intersectionPoint1X, intersectionPoint1Y
else
return true, intersectionPoint2X, intersectionPoint2Y
end
end
function orders.updateOrdersDistance()
if vehicle.name then
if orders.updateOrdersDistanceClock < os.clock() then
if not orders.currentOrder then
if not chat.hiddenMessages["/service"].bool then
chat.addMessageToQueue("/service", true, true)
orders.updateOrdersDistanceClock = os.clock() + ini.settings.ordersDistanceUpdateTimer
end
end
end
end
end
function orders.add(nickname, id, distance, time)
local posX, posY = getCharCoordinates(PLAYER_PED)
local level = sampGetPlayerScore(id)
orders.list[nickname] = {
nickname = nickname,
id = id,
distance = distance,
pos = {x = nil, y = nil, z = nil},
currentDistance = distance,
time = time,
correct = false,
showMark = false,
SMSClock = os.clock() - ini.settings.SMSTimer,
firstSMS = true,
arrived = false,
updateDistance = true,
direction = 0,
tempCircles = {{x = posX, y = posY, radius = distance}, nil, nil},
zone = "Неизвестно",
level = level
}
end
function orders.refreshCurrentOrder()
if orders.currentOrder then
if sampIsPlayerConnected(orders.currentOrder.id) then
if vehicle.maxPassengers then
chat.sendNotification(orders.currentOrder)
local charInStream, charHandle = sampGetCharHandleBySampPlayerId(orders.currentOrder.id)
if charInStream and ini.settings.updateOrderMark then
local newPosX, newPosY = getCharCoordinates(charHandle)
-- если дистанция резко сменилась считаем что клиент телепортировался в виртуальный мир
if getDistanceBetweenCoords2d(newPosX, newPosY, orders.currentOrder.pos.x, orders.currentOrder.pos.y) < 200 then
orders.currentOrder.pos.x, orders.currentOrder.pos.y, orders.currentOrder.pos.z =
getCharCoordinates(charHandle)
orders.currentOrder.zone = getZone(orders.currentOrder.pos.x, orders.currentOrder.pos.y)
end
end
if orders.currentOrder.showMark then
if not orders.currentOrderBlip then
orders.currentOrderBlip =
addBlipForCoord(
orders.currentOrder.pos.x,
orders.currentOrder.pos.y,
orders.currentOrder.pos.z
)
changeBlipColour(orders.currentOrderBlip, 0xBB0000FF)
orders.currentOrderCheckpoint =
createCheckpoint(
1,
orders.currentOrder.pos.x,
orders.currentOrder.pos.y,
orders.currentOrder.pos.z,
orders.currentOrder.pos.x,
orders.currentOrder.pos.y,
orders.currentOrder.pos.z,
2.99
)
else
removeBlip(orders.currentOrderBlip)
orders.currentOrderBlip =
addBlipForCoord(
orders.currentOrder.pos.x,
orders.currentOrder.pos.y,
orders.currentOrder.pos.z
)
changeBlipColour(orders.currentOrderBlip, 0xBB0000FF)
setCheckpointCoords(
orders.currentOrderCheckpoint,
orders.currentOrder.pos.x,
orders.currentOrder.pos.y,
orders.currentOrder.pos.z
)
end
end
if orders.currentOrder.pos.x then
orders.currentOrder.currentDistance =
getDistanceToCoords3d(
orders.currentOrder.pos.x,
orders.currentOrder.pos.y,
orders.currentOrder.pos.z
)
orders.currentOrder.updateDistance = true
end
if vehicle.isPassengerIn(vehicle.handle, orders.currentOrder.nickname) then
orders.currentOrder = nil
end
end
else
if ini.settings.notifications then
imgui.addNotification("Клиент оффлайн\nВызов отменён", 5)
end
if ini.settings.notifications and ini.settings.sounds then
sounds.play("correct_order")
end
orders.currentOrder = nil
orders.removeGPSMark()
end
else
removeBlip(orders.currentOrderBlip)
deleteCheckpoint(orders.currentOrderCheckpoint)
orders.currentOrderBlip = nil
orders.currentOrderCheckpoint = nil
end
end
function orders.delete(nickname)
orders.list[nickname] = nil
end
function orders.accept(nickname, orderClock)
if orders.canceled[nickname] and ini.settings.ignoreCanceledOrder then
return
end
if orders.list[nickname] then
if orderClock then
if orders.lastAcceptedOrderClock ~= orderClock then
if orders.acceptedNickname == nil then
orders.lastAcceptedOrderClock = orders.list[nickname].time
orders.acceptedNickname = nickname
chat.addMessageToQueue("/service ac taxi " .. orders.list[nickname].id)
end
end
end
end
end
function orders.deleteOrdersThread()
while true do
wait(1000)
for nickname, order in pairs(orders.list) do
if os.clock() - order.time > 600 or not sampIsPlayerConnected(order.id) then
orders.delete(nickname)
end
end
for nickname, clock in pairs(orders.canceled) do
if os.clock() - clock > ini.settings.canceledOrderDelay then
orders.canceled[nickname] = nil
end
end
end
end
function orders.get()
for keyIndex, key in ipairs(table.getTableKeysSortedByValue(orders.list, "time", false)) do
if orders.list[key] then
return true, key, orders.list[key].distance, orders.list[key].time
end
end
return false, nil, nil, nil
end
function orders.handle(orderNickname, orderDistance, orderClock)
if not orders.currentOrder then
local level = orders.list[orderNickname].level
if not table.contains(orderNickname, vehicle.lastPassengersList) then
if table.isEmpty(vehicle.passengersList) then
local acceptByLevel =
level == 0 or (level >= 1 and level <= 2 and ini.settings.autoAccept1_2) or
(level >= 3 and level <= 5 and ini.settings.autoAccept3_5) or
(level >= 6 and ini.settings.autoAccept6)
local ignoreByBlacklist = ini.settings.blacklistIgnore and blacklist.check(orderNickname)
if orders.autoAccept and acceptByLevel and not ignoreByBlacklist then
if orderDistance <= ini.settings.maxDistanceToAcceptOrder and os.clock() - 60 < orderClock then
orders.accept(orderNickname, orderClock)
end
end
else
if orderDistance <= ini.settings.maxDistanceToGetOrder and os.clock() - 60 < orderClock then
if not orders.list[orderNickname].correct then
orders.list[orderNickname].correct = true
orders.lastCorrectOrderNickname = orderNickname
orders.lastCorrectOrderClock = os.clock()
lua_thread.create(
function()
wait(500)
if orders.list[orderNickname] then
if ini.settings.notifications and ini.settings.sounds then
sounds.play("correct_order")
end
if ini.settings.notifications then
imgui.addNotificationWithButton(
string.format(
FORMAT_NOTIFICATIONS.newOrder,
orderNickname,
orders.list[orderNickname].id,
orders.list[orderNickname].level,
orderDistance,
orders.list[orderNickname].zone
),
15,
orderNickname
)
end
end
end
)
end
end
end
end
end
end
vehicle = {
lastPassengersList = {},
lastPassengersListSize = 3,
passengersList = {},
maxPassengers = nil,
name = nil,
handle = nil,
markers = {},
cruiseControlEnabled = false,
gasPressed = false
}
function vehicle.refreshInfoThread()
while true do
wait(0)
vehicle.name, vehicle.handle, vehicle.maxPassengers = vehicle.getInfo()
vehicle.refreshPassengersList()
end
end
function vehicle.addPassenger(passengerNickname)
local isPassengerInVehicle = false
for passengerIndex = 1, vehicle.lastPassengersListSize do
if passengerNickname == vehicle.lastPassengersList[passengerIndex] then
isPassengerInVehicle = true
break
end
end
if not isPassengerInVehicle then
for passengerindex = vehicle.lastPassengersListSize, 1, -1 do
vehicle.lastPassengersList[passengerindex] = vehicle.lastPassengersList[passengerindex - 1]
end
vehicle.lastPassengersList[1] = passengerNickname
if ini.settings.notifications and ini.settings.sounds then
sounds.play("new_passenger")
end
end
end
function searchMarker()
for id = 0, 175 do
local MarkerStruct = 0xBA86F0 + id * 40
local color = readMemory(MarkerStruct + 0, 8, false)
local posX = representIntAsFloat(readMemory(MarkerStruct + 8, 4, false))
local posY = representIntAsFloat(readMemory(MarkerStruct + 12, 4, false))
local posZ = representIntAsFloat(readMemory(MarkerStruct + 16, 4, false))
if color == -16776961 and MarkerPosX ~= 0.0 and MarkerPosY ~= 0.0 and MarkerPosZ ~= 0.0 then
return true, posX, posY, posZ
end
end
return false, nil, nil, nil
end
function updateTextdrawInfoThread()
while true do
wait(0)
if os.clock() - player.textdrawUpdateClock > 1 then
vehicle.fuel = nil
orders.currentOrderTextdrawExist = false
for textdrawId = 0, 2100 do
if sampTextdrawIsExists(textdrawId) then
local textdrawString = sampTextdrawGetString(textdrawId)
-- Обновление количества топлива
if ini.settings.autoRefill then
if textdrawString == "Fuel" and sampTextdrawIsExists(textdrawId - 1) then
vehicle.fuel = tonumber(sampTextdrawGetString(textdrawId - 1))
elseif string.find(textdrawString, MESSAGES.fuelClassic) then
vehicle.fuel = tonumber(string.match(textdrawString, MESSAGES.fuelClassicFormat))
end
end
-- Обновление активного вызова
local acceptOrder = false
local inDoors = false