-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsave_loot.lua
2832 lines (2555 loc) · 76 KB
/
save_loot.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
destroy_objects = {}
destroy_objects["mp_ammo_9x18_fmj"] = true
destroy_objects["ammo_gravi"] = true
destroy_objects["wpn_rpg7"] = true
ignore_save_loot = {}
ignore_save_loot["bolt"] = true
ignore_save_loot["mp_wpn_knife"] = true
ignore_save_loot["device_pda"] = true
ignore_save_loot["mp_device_torch"] = true
ignore_save_loot["mp_wpn_binoc"] = true
ignore_save_loot["wpn_addon_scope_none"] = true
ignore_save_loot["mp_ammo_9x18_fmj"] = true
ignore_save_loot["ammo_gravi"] = true
local need_save_loot = true
local passwords = {}
local death_count = {}
local authorization_time = {}
local authorization_count = {}
local max_authorization_count = 3
local packet = net_packet ()
local hard_key_two = {}
local not_kicked_person = {}
local player_by_name = {}
local max_player_money = {}
local spawn_loot_queue_process_size = 10
local deffered_iterate_inventory = {}
local not_destroy_item = {}
local is_zooombe = {}
local actual_team_leader = {}
local is_very_very_dead = {}
local agit_time_delta = 5 * 60 * 1000
local agit_time = time_global() + agit_time_delta
xrLua.TermenateProcess = function()
error_log("Server was shut down.")
end
game_object.take_item = function (self, obj)
-- local P = net_packet ()
u_EventGen (packet, 1, self:id())
packet:w_u16 (obj:id())
u_EventSend (packet)
-- self:transfer_item(obj, self)
end
game_object.destroy_object = function (self)
u_EventGen (packet, 8, self:id())
u_EventSend (packet)
end
game_object.set_actor_position = function (self, pos)
u_EventGen (packet, 29, self:id())
packet:w_vec3(pos)
packet:w_vec3(self:direction())
SendBroadcast (packet)
end
game_object.allow_sprint = function (self, allow_sprint)
u_EventGen(packet, 47, self:id())
packet:w_u8(allow_sprint and -1 or 1)
SendBroadcast (packet)
end
function send_tip_server(text)
for i = 0, 65535 do
local obj = level.object_by_id(i)
if obj and obj:section() == "mp_actor" then
u_EventGen(packet, 107, i)
packet:w_stringZ("st_tip")
packet:w_stringZ(text)
packet:w_stringZ("ui_inGame2_Vibros")
u_EventSend(packet)
end
end
end
function send_to_user(text, user)
if user then
u_EventGen(packet, 107, user:id())
packet:w_stringZ("st_tip")
packet:w_stringZ(text)
packet:w_stringZ("ui_inGame2_Polucheni_koordinaty_taynika")
u_EventSend(packet)
end
end
local log_packet = net_packet()
function log_test(text)
if xrLua then
xrLua.log("$ " .. text)
return
end
get_console():execute("cfg_load ~" .. text)
end
function fix_no_alife_object(obj)
if obj and alife() then
local binder = obj:binded_object()
local se_obj
if binder and binder.is_ammo then
se_obj = alife():create_ammo(obj:section(), db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), -1, binder.ammo_cnt)
else
se_obj = alife():create(obj:section(), db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id())
end
level.client_spawn_manager():add(se_obj.id, 0, spawn_callback, obj)
end
end
--- Make a shallow copy of a table, including any metatable (for a
-- deep copy, use tree.clone).
-- @param t table
-- @param nometa if non-nil don't copy metatable
-- @return copy of table
function table.clone (t, nometa)
local u = {}
if not nometa then
setmetatable (u, getmetatable (t))
end
for i, v in pairs (t) do
u[i] = v
end
return u
end
--- Merge two tables.
-- If there are duplicate fields, u's will be used. The metatable of
-- the returned table is that of t.
-- @param t first table
-- @param u second table
-- @return merged table
function table.merge (t, u)
local r = table.clone (t)
for i, v in pairs (u) do
r[i] = v
end
return r
end
function get_item_table(item)
local sobj = alife():object(item:id())
local tbl = get_object_data(sobj)
local t = {}
if not tbl or (tbl and not tbl.condition) then
log_test("Why? " .. item:name())
item:destroy_object()
return nil
end
t.ammo_elapsed = tbl.ammo_elapsed
-- t.ammo_current = tbl.ammo_current
t.addon_flags = tbl.addon_flags
t.condition = item:condition()
t.ammo_type = tbl.ammo_type
t.ammo_left = tbl.ammo_left
t.section = item:section()
return t
end
local last_tick = {}
local last_hit_tick = {}
local last_pos_tick = {}
local last_in_safe_zone = {}
local is_surge_real_started = false
function update_save_loot(obj)
if not obj then
return true
end
if authorization_time[obj:id()] then
if authorization_time[obj:id()] < time_global() then
if authorization_count[obj:id()] == max_authorization_count then
logf_test("[%s] error authorization!!!", obj:name())
--cheak_ban_char(obj:name(), obj:name())
return true
end
authorization_count[obj:id()] = authorization_count[obj:id()] + 1
authorization_time[obj:id()] = time_global() + 5000
obj:give_info_portion("need_check_autorize=" .. device().frame)
end
return false
end
if not hard_key_two[obj:id()] then
logf_test("[%s] error hard key 2!!!", obj:name())
--cheak_ban_char(obj:name(), obj:name())
xrLua.KickPlayer(obj:id())
not_kicked_person[obj:name()] = true
return true
end
if is_very_very_dead[obj:id()] then
save_player_loot_table(obj)
return true
end
if not last_tick[obj:id()] then
last_tick[obj:id()] = 0
end
if not last_hit_tick[obj:id()] then
last_hit_tick[obj:id()] = 0
end
if not last_pos_tick[obj:id()] then
last_pos_tick[obj:id()] = 0
end
if obj:alive() then
local zone = db.zone_by_name["sr_surge"]
if zone and not is_zooombe[obj:id()] then
if is_surge_real_started and last_hit_tick[obj:id()] < time_global() then
if not zone:inside(obj:position()) then
local h = hit()
h.draftsman = obj
h.type = hit.radiation
h.direction = vector():set(0, 1, 0)
h.power = math.random(3, 20) * 0.01
h.impulse = 1
obj:hit(h)
end
last_hit_tick[obj:id()] = time_global() + 2000
end
end
local safe_zone = db.zone_by_name["sr_safe_zone"]
if safe_zone then
if last_in_safe_zone[obj:id()] then
if not safe_zone:inside(obj:position()) then
last_in_safe_zone[obj:id()] = false
send_to_user("Âû âûøëè èç áåçîïàñíîé çîíû. Âàø ïðîãðåññ íå áóäåò ñîõðàíåí.", obj)
end
else
if safe_zone:inside(obj:position()) then
last_in_safe_zone[obj:id()] = true
send_to_user("Âû âîøëè â áåçîïàñíóþ çîíó. Âàø ïðîãðåññ áóäåò ñîõðàíåí.", obj)
end
end
end
if last_pos_tick[obj:id()] < time_global() then
if obj:position().y > 60.0 then
local pos = obj:position()
get_console():execute("chat %c[255,190,20,20][ANTI-CHEAT] " .. obj:name() .. " - Ïîäîçðåâàåòñÿ â èñïîëüçîâàíèå çàïðåùåííîãî ïðîãðàììíîãî îáåñïå÷åíèÿ.")
pos.y = 55.0
obj:set_actor_position(pos)
end
last_pos_tick[obj:id()] = time_global() + 500
end
if last_tick[obj:id()] > time_global() then
return false
end
save_player_loot_table(obj)
end
last_tick[obj:id()] = time_global() + math.random(3000, 5000)
return false
end
function spawn_in_inv(sect, parent)
local so_obj = alife():create(sect, db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), -1)
level.client_spawn_manager():add(so_obj.id, 0, spawn_in_inv_callback, {parent:id(), sect})
--level.client_spawn_manager():add(so_obj.id, 0, spawn_in_inv_callback)
return so_obj
end
function spawn_in_inv_callback(parent_id, id, obj)
local new_parent = level.object_by_id(parent_id[1])
--local new_parent = level.object_by_id(parent_id)
if new_parent then
if obj:parent() then
obj:parent():transfer_item(obj, new_parent)
return
end
new_parent:take_item(obj)
if parent_id[2] ~= obj:section() then logf_test("Why random %s, %s", parent_id[2], obj:section()) end
end
end
function kill_player(obj)
-- if obj then
-- local h = hit()
-- h.draftsman = db.actor or obj
-- h.type = hit.explosion
-- h.direction = vector():set(0, 1, 0)
-- h.power = 10000
-- h.impulse = 0
-- obj:hit(h)
-- end
end
function cheak_ban_char(name, char)
if name:find(char) then
get_console():execute(string.format("sv_listplayers %s", char))
get_console():execute("sv_kick_id last_printed")
kill_player(player_by_name[name])
return true
end
return false
end
function sv_kick_vasan(name)
local ban = false
ban = ban or cheak_ban_char(name, [[/]])
ban = ban or cheak_ban_char(name, [[\]])
ban = ban or cheak_ban_char(name, [[:]])
ban = ban or cheak_ban_char(name, [[*]])
ban = ban or cheak_ban_char(name, [[?]])
ban = ban or cheak_ban_char(name, [["]])
ban = ban or cheak_ban_char(name, [[<]])
ban = ban or cheak_ban_char(name, [[>]])
ban = ban or cheak_ban_char(name, [[|]])
ban = ban or cheak_ban_char(name, [[#]])
ban = ban or cheak_ban_char(name, [["]])
ban = ban or cheak_ban_char(name, [[']])
ban = ban or cheak_ban_char(name, [[=]])
return ban
end
function process_spawn_loot(spawn_loot_queue)
if need_save_loot then
local process_spawn = function ()
local process_size = math.min(spawn_loot_queue_process_size, #spawn_loot_queue)
for j = 1, process_size do
local index = 1 -- do so for now
local t = spawn_loot_queue[index].loot_table
local obj = level.object_by_id(spawn_loot_queue[index].parent_id)
if obj and t and t.condition then
if obj:name() ~= spawn_loot_queue[index].parent_name then
logf_test("Why [%s] spizdil u [%s]",
tostring(obj:name()), tostring(spawn_loot_queue[index].parent_name)) end
local sobj = spawn_in_inv(t.section, obj)
if sobj then
local tpk = get_object_data(sobj)
if tpk then
t = table.merge(tpk, t)
t.level_vertex_id = tpk.level_vertex_id
t.game_vertex_id = tpk.game_vertex_id
set_object_data(t, sobj)
end
end
end
table.remove(spawn_loot_queue, index)
end
return #spawn_loot_queue == 0
end
level.add_call(process_spawn, function() end)
end
end
function load_player_loot(obj)
if obj:get_visual_name():find("stalker_monolith_4") or
obj:get_visual_name():find("stalker_monolith_5") or
obj:get_visual_name():find("stalker_monolith_6") then
obj:allow_sprint(false)
is_zooombe[obj:id()] = true
end
if not_kicked_person[obj:name()] then
kill_player(obj)
end
player_by_name[obj:name()] = obj
is_very_very_dead[obj:id()] = false
max_player_money[obj:id()] = 0
hard_key_two[obj:id()] = true
authorization_time[obj:id()] = time_global() + 10000
authorization_count[obj:id()] = 2
logf_test("[%s] try to spawn", obj:name())
if obj:get_visual_name():find("spectrum") then
if level.name() == "jupiter_stnet_v2" then
local jupiter_spectrum_rpoint = math.random(1, 2)
if jupiter_spectrum_rpoint == 1 then
obj:set_actor_position(vector():set(-358.39, 5.10, 405.14))
end
if jupiter_spectrum_rpoint == 2 then
obj:set_actor_position(vector():set(-309.44, 14.63, 413.27))
end
elseif level.name() == "zaton" then
local zaton_spectrum_rpoint = math.random(1, 5)
if zaton_spectrum_rpoint == 1 then
obj:set_actor_position(vector():set(-416.90, 24.20, -327.99))
end
if zaton_spectrum_rpoint == 2 then
obj:set_actor_position(vector():set(-337.02, 41.62, -398.52))
end
if zaton_spectrum_rpoint == 3 then
obj:set_actor_position(vector():set(-318.99, 41.60, -307.21))
end
if zaton_spectrum_rpoint == 4 then
obj:set_actor_position(vector():set(-414.37, 41.90, -306.83))
end
if zaton_spectrum_rpoint == 5 then
obj:set_actor_position(vector():set(-371.02, 41.55, -330.85))
end
end
end
if xrLua.CheakBanWord(obj:id()) then
xrLua.KickPlayer(obj:id())
return true
end
local path = getFS():update_path("$app_data_root$", "accounts\\")
local data = io.open(path .. obj:name() .. "_inventory.lua")
if not data then return true end
local tbl = loadstring(data:read("*a"))()
data:close()
if not tbl then return true end
if not obj:alive() then
return true
end
local spawn_loot_queue = {}
if not death_count[obj:id()] then
death_count[obj:id()] = 0
end
for k, v in pairs(tbl) do
if k == "password" then
passwords[obj:id()] = tostring(v)
elseif k == "death_count" then
death_count[obj:id()] = tonumber(v)
elseif k == "position" then
-- obj:set_actor_position(vector():set(v.x, v.y, v.z))
else
local t = {}
t.loot_table = v
t.parent_id = obj:id()
t.parent_name = obj:name()
if need_save_loot then
table.insert(spawn_loot_queue, t)
end
-- execute deffered
end
end
process_spawn_loot(spawn_loot_queue)
return false
end
function objects_equal(obj1, obj2)
if obj1 and obj2 then
if obj2:name() == obj1:name() and obj2:id() == obj1:id() then
return true
end
end
return false
end
function save_player_loot_table(player)
local loot_table = {}
local function add_items (parent, item)
local owner = item:parent()
if objects_equal(owner, player) and
not ignore_save_loot[item:section()] and alife():object(item:id()) then
local tbl = get_item_table(item)
if tbl then
table.insert(loot_table, tbl)
end
end
end
if player:alive() and need_save_loot then
player:iterate_inventory(add_items, player)
local position = player:position()
-- loot_table["position"] = {x=position.x, y=position.y + 0.1, z=position.z}
end
if passwords[player:id()] then
loot_table["password"] = passwords[player:id()]
end
if death_count[player:id()] then
loot_table["death_count"] = death_count[player:id()]
end
local script = print_tableg(loot_table, "mp_actor")
script = script .. "return mp_actor \n"
printfile(script, player)
end
function printfile(text, obj)
local path = getFS():update_path("$app_data_root$", "accounts\\")
local file = io.open(path .. obj:name() .. "_inventory.lua", "w")
if not file or xrLua.CheakBanWord(obj:id()) then
if file then
file:close()
end
return
end
file:write(text)
file:close()
end
function printfg(fmt,...) return string.format(fmt, ...) .. "\n" end
-- ¾å÷àòàåò òàáëèöó êàê äåðåâî.
function print_tableg(table, sub)
if not sub then sub = "" end
if not table then table = _G sub = "_G" end
local text = sub .. " = {}\n"
for k,v in pairs(table) do
if type(k) == "string" then k = [["]]..k..[["]] end
if type(v) == "table" then
-- text = text .. printfg(sub.."[%s] = {}", tostring(k))
text = text .. print_tableg(v, sub.."["..tostring(k).."]")
elseif type(v) == "function" then
text = text .. printfg(sub.."[%s] = function() end", tostring(k))
elseif type(v) == "userdata" then
text = text .. printfg(sub.."[%s] = userdata", tostring(k))
elseif type(v) == "boolean" then
if v == true then
if(type(k)~="userdata") then
text = text .. printfg(sub.."[%s] = true", tostring(k))
else
text = text .. printfg(sub.."userdata:true")
end
else
if(type(k)~="userdata") then
text = text .. printfg(sub.."[%s] = false", tostring(k))
else
text = text .. printfg(sub.."userdata:false")
end
end
else
if v ~= nil then
if type(v) == "string" then
text = text .. printfg(sub.."[%s] = [[%s]]", tostring(k),v)
else
text = text .. printfg(sub..[[[%s] = %s]], tostring(k),v)
end
else
text = text .. printfg(sub..[[[%s] = nil]], tostring(k))
end
end
end
return text
end
function spawn_callback(obj, id, wpn)
local par = obj:parent()
obj:destroy_object()
if par then
spawn_in_inv_callback({par:id(), wpn:section()}, id, wpn)
end
end
function logf_test(fmt, ...)
log_test(string.format(fmt, ...))
end
function death_callback(obj, npc, who)
local torch = npc:item_in_slot(10)
if torch then
torch:destroy_object()
end
-- local safe_zone = db.zone_by_name["sr_safe_zone"]
-- if safe_zone and not safe_zone:inside(npc:position()) then
-- is_very_very_dead[npc:id()] = true
-- end
actual_team_leader[npc:id()] = nil
if not death_count[npc:id()] then
death_count[npc:id()] = 0
else
death_count[npc:id()] = death_count[npc:id()] + 1
end
if who and who:id() ~= obj:id() and not is_zooombe[obj:id()] then
local binder = who:binded_object()
if binder and binder.community == "stalker" then
is_very_very_dead[who:id()] = true
end
end
local binder = npc:binded_object()
if binder then
binder:death_callback(obj, who)
end
end
function drop_callback(npc, obj)
last_tick[npc:id()] = time_global() + 200
bind_taynik_box.on_item_drop(npc, obj)
if not npc:alive() and not not_destroy_item[obj:id()] then
obj:destroy_object()
end
not_destroy_item[obj:id()] = nil
local binder = npc:binded_object()
if binder and (alife():object(obj:id()) or ignore_save_loot[obj:section()]) then
binder:on_item_drop(obj)
end
end
function take_callback(npc, obj)
if not npc:alive() then
return
end
if need_save_loot then
if destroy_objects[obj:section()] then
obj:destroy_object()
return
end
if not (alife():object(obj:id()) or ignore_save_loot[obj:section()]) then
fix_no_alife_object(obj)
end
else
if destroy_objects[obj:section()] then
obj:destroy_object()
end
end
last_tick[npc:id()] = time_global() + 200
end
db.add_actor = function(obj)
db.actor = obj
db.actor_proxy:net_spawn( obj )
db.add_obj(obj)
if alife() then
obj:set_fastcall(server_update, nil)
obj:set_callback(callback.inventory_info, single_actor_info, obj)
end
log_test("module save_loot connected...")
end
local start_surge_time = nil
local end_surge_time = nil
local is_surge_started = false
function server_update()
if level.is_wfx_playing() and not is_surge_started then
is_surge_real_started = false
is_surge_started = true
local time = math.random(15000, 40000)
start_surge_time = time_global() + time
end_surge_time = time_global() + 190000
send_tip_server(string.format("Âûáðîñ íà÷íåòñÿ ÷åðåç %.1f ñåêóíä!", time * 0.001))
elseif not level.is_wfx_playing() and is_surge_started then
is_surge_started = false
end
if is_surge_started and start_surge_time and start_surge_time < time_global() and not is_surge_real_started then
is_surge_real_started = true
start_surge_time = nil
end
if end_surge_time and end_surge_time < time_global() then
send_tip_server("Âûáðîñ çàêîí÷èëñÿ!")
end_surge_time = nil
is_surge_real_started = false
end
if agit_time < time_global() then
local path = getFS():update_path("$app_data_root$", "agait_manager.ltx")
local agait_table = {}
for line in io.lines(path) do
if line then
table.insert(agait_table, line)
end
end
agit_time = time_global() + agit_time_delta
if #agait_table > 0 then
get_console():execute("chat " .. agait_table[math.random(1, #agait_table)])
end
end
return false
end
function use_callback (self, obj, who)
if is_very_very_dead[obj:id()] then
local drop_table = {}
local drop_table_count = {}
local function drop_items (parent, item)
if not ignore_save_loot[item:section()] then
table.insert(drop_table, item:id())
not_destroy_item[item:id()] = true
end
end
obj:iterate_inventory(drop_items, obj)
if #drop_table > 0 then
who:allow_sprint(false)
local function time_transfer_items()
local size = math.min(#drop_table, spawn_loot_queue_process_size)
for i = 1, size do
local index = #drop_table
local item = level.object_by_id(drop_table[index])
if item then
local parent = item:parent()
if who and parent then
parent:transfer_item(item, who)
local name = game.translate_string(system_ini():r_string(item:section(), "inv_name"))
if drop_table_count[name] then
drop_table_count[name] = drop_table_count[name] + 1
else
drop_table_count[name] = 1
end
end
end
table.remove(drop_table, index)
end
return #drop_table == 0
end
function on_time_transfer_items()
local temp_tbl = {}
for k, v in pairs(drop_table_count) do
table.insert(temp_tbl, k .. " = " .. v)
end
if who then
who:allow_sprint(true)
send_to_user(table.concat(temp_tbl, ", "), who)
end
end
level.add_call(time_transfer_items, on_time_transfer_items)
end
end
end
db.add_obj = function ( obj )
if obj:section() == "mp_actor" and alife() then
obj:set_fastcall(update_save_loot, obj)
obj:set_callback(callback.inventory_info, info_callback, obj)
obj:set_callback(callback.on_item_take, take_callback, obj)
obj:set_callback(callback.on_item_drop, drop_callback, obj)
obj:set_callback(callback.death, death_callback, obj)
obj:set_callback(callback.use_object, use_callback, obj)
local is_new = load_player_loot(obj)
end
printf("adding object %s",obj:name())
db.storage[obj:id()].object = obj
end
function single_actor_info(self, obj, info)
logf_test("actor has %s", info)
if info:find("game_player_flag_very_very_dead=") then
is_very_very_dead[tonumber(string_expl(info, "=")[2])] = true
end
end
function info_callback (self, obj, id)
log_test(obj:name() .. " " .. id)
local id_expl = string_expl(id, "=")
local binder = obj:binded_object()
local safe_nickname = obj:name()
if not binder then
-- cheak_ban_char(obj:name(), obj:name())
xrLua.KickPlayer(obj:id())
return
end
if id:find("password=") and id_expl[2] and id_expl[2] ~= "" then
local password = id_expl[2]
if passwords[obj:id()] then
if passwords[obj:id()] ~= password then
-- cheak_ban_char(obj:name(), obj:name())
xrLua.KickPlayer(obj:id())
return
end
else
passwords[obj:id()] = password:gsub("{", ""):gsub("}", "") --:gsub("[", ""):gsub("]", "")
end
local path = getFS():update_path("$app_data_root$", "team_leads.lua")
local data = io.open(path)
if data then
local tbl = loadstring(data:read("*a"))()
if tbl and tbl[safe_nickname] then
obj:give_info_portion("player_team_lead_" .. binder.community)
-- obj:give_info_portion("add_list_command=" .. binder.community .. "=" .. obj:name() .. "=" .. device().frame)
actual_team_leader[obj:id()] = tbl[safe_nickname]
data:close()
return
end
data:close()
end
local path = getFS():update_path("$app_data_root$", "team_players.lua")
local data = io.open(path)
if data then
local tbl = loadstring(data:read("*a"))()
--get_console():execute("chat %c[0,183,0,20][FACTION-SYSTEM] " .. obj:name() .. " ïîäêëþ÷èëñÿ ê ãðóïïèðîâêå " .. binder.community .. " ")
if tbl then
if binder.community ~= "stalker" and (binder.community ~= tbl[safe_nickname] or not tbl[safe_nickname]) then
logf_test("Íå ÿâëÿåòñÿ ó÷àñòíèêîì ãðóïïèðîâêè %s %s", obj:name(), binder.community)
get_console():execute("chat %c[0,183,0,20][FACTION-SYSTEM] " .. obj:name() .. " Íå ÿâëÿåòñÿ ó÷àñòíèêîì ãðóïïèðîâêè " .. binder.community .. " - Automatically kicked...")
-- cheak_ban_char(obj:name(), obj:name())
xrLua.KickPlayer(obj:id())
end
end
data:close()
end
authorization_time[obj:id()] = nil
authorization_count[obj:id()] = nil
elseif id:find("user_key=") or (id:find("hard_key") and id:find("=")) or id:find("computer_name=") or id:find("user_name=")then
local user_key = id_expl[2]
local path = getFS():update_path("$app_data_root$", "banned_list_cmd.ltx")
local data = io.open(path)
if data then
local ini = create_ini_file(data:read("*a"))
if ini:line_exist("banned_list", user_key) then
get_console():execute("chat %c[147,203,255,20][BAN-SYSTEM] " .. obj:name() .. " - Îáíàðóæåíî íàëè÷èå áëîêèðîâêè. Automatically kicked...")
-- cheak_ban_char(obj:name(), obj:name())
xrLua.KickPlayer(obj:id())
not_kicked_person[obj:name()] = true
end
data:close()
end
if id:find("hard_key2") then
hard_key_two[obj:id()] = true
end
elseif id:find("delta_money=") then
local delta_money = tonumber(id_expl[2])
max_player_money[obj:id()] = max_player_money[obj:id()] + delta_money
if max_player_money[obj:id()] > 150000 then
get_console():execute("chat %c[255,190,20,20][ANTI-CHEAT] " .. obj:name() .. " - Ïîäîçðåâàåòñÿ â èñïîëüçîâàíèå çàïðåùåííîãî ïðîãðàììíîãî îáåñïå÷åíèÿ.")
-- cheak_ban_char(obj:name(), obj:name())
xrLua.KickPlayer(obj:id())
not_kicked_person[obj:name()] = true
end
elseif id:find("add_list_command=") then
if actual_team_leader[obj:id()] == binder.community and binder.community == id_expl[2] then
local name = tostring(id_expl[3]):gsub("'", ''):gsub('"', ''):gsub('?', '')
local path = getFS():update_path("$app_data_root$", "team_players.lua")
local data = io.open(path)
local tbl = {}
if data then
tbl = loadstring(data:read("*a"))()
data:close()
end
if tbl then
tbl[name] = tostring(id_expl[2]):gsub("'", '?'):gsub('"', '?')
end
local text = print_tableg(tbl, "tbl")
text = text .. "return tbl \n"
local data = io.open(path, "w")
if data then
data:write(text)
data:close()
end
end
elseif id:find("remove_list_command=") then
if actual_team_leader[obj:id()] == binder.community and binder.community == id_expl[2] then
local name = tostring(id_expl[3]):gsub("'", ''):gsub('"', ''):gsub('?', '')
local path = getFS():update_path("$app_data_root$", "team_players.lua")
local data = io.open(path)
if data then
local tbl = loadstring(data:read("*a"))()
if tbl then
tbl[name] = nil
end
data:close()
local text = print_tableg(tbl, "tbl")
text = text .. "return tbl \n"
data = io.open(path, "w")
if data then
data:write(text)
data:close()
end
end
end
elseif id:find("update_list_command=") then
if actual_team_leader[obj:id()] == binder.community and binder.community == id_expl[2] then
local path = getFS():update_path("$app_data_root$", "team_players.lua")
local data = io.open(path)
if data then
local tbl = loadstring(data:read("*a"))()
if tbl then
for player, community in pairs(tbl) do
if community == binder.community then
obj:give_info_portion("add_player_to_my_list=" .. player .. "=" .. device().frame)
end
end
end
data:close()
end
end
elseif id:find("anticheat_executed") then
get_console():execute("chat %c[255,20,220,20][ANTI-CHEAT] " .. obj:name() .. " - Îòêëþ÷åí çà èñïîëüçîâàíèå çàïðåùåííîãî ïðîãðàììíîãî îáåñïå÷åíèÿ.")
end
end
function string_expl(sStr, sDiv, Mode, bNoClear)
sStr = tostring(sStr)
if not (sStr ~= "nil" and sStr ~= '') then return {} end --> íå÷åãî ðàçäåëÿòü
local tRet = {}
local sPattern = '[%w%_]+' --> äåôîëòíûé ïàòåðí (ðàçäåëåíèå ïî 'ñëîâàì')
if type(sDiv) == "string" then --> åñëè çàäàí ñåïàðàòîð: ðàçäåëÿåì ïî íåìó
if bNoClear then --> åñëè ÍÅ óêàçàíî '÷èñòèòü ïðîáåëû'
sPattern = '([^'..sDiv..']+)'
else --> èíà÷å ñ ÷èñòêîé ïðîáåëîâ
sPattern = '%s*([^'..sDiv..']+)%s*'
end
end
--* ðàçäåëÿåì ñòðîêó ïî ïàòåðíó
if Mode == nil then --> îáû÷íûé ìàññèâ
for sValue in sStr:gmatch(sPattern) do
table.insert(tRet, sValue)
end
else
local sTypeMode = type(Mode)
if sTypeMode == "boolean" then --> òàáëèöà '[çíà÷åíèå] = true èëè false'
for sValue in sStr:gmatch(sPattern) do
tRet[sValue] = Mode
end
elseif sTypeMode == "number" then --> òàáëèöà '[idx] = ÷èñëî èëè ñòðèíã'
for sValue in sStr:gmatch(sPattern) do
tRet[#tRet+1] = tonumber(sValue) or sValue
end
end
end
return tRet --> âîçâðàùàåì òàáëèöó
end
-- stpk_utils
-- Alundaio
local stpk = net_packet()
local uppk = net_packet()
-- only use if you don't know the object class, otherwise call get_* directly to avoid needless overhead
function get_object_data(sobj)
if not (sobj) then
return nil
end
local m_classes =
{
["S_ACTOR"] = get_actor_data,
["O_ACTOR"] = get_actor_data,
["ARTEFACT"] = get_item_data,
["SCRPTART"] = get_item_data,
["II_ATTCH"] = get_item_data,
["II_BTTCH"] = get_item_data,
["II_DOC"] = get_item_document_data,
["TORCH_S"] = get_item_data,
["TORCH"] = get_item_data,
["DET_SIMP"] = get_item_data,
["DET_ADVA"] = get_item_data,
["DET_ELIT"] = get_item_data,
["DET_SCIE"] = get_item_data,
["E_STLK"] = get_item_data,
["E_HLMET"] = get_item_data,
["EQU_STLK"] = get_item_data,
["EQU_HLMET"] = get_item_data,
["II_BANDG"] = get_item_data,
["II_MEDKI"] = get_item_data,
["II_ANTIR"] = get_item_data,
["II_BOTTL"] = get_item_data,
["II_FOOD"] = get_item_data,
["S_FOOD"] = get_item_data,
["S_PDA"] = get_item_pda_data,
["D_PDA"] = get_item_pda_data,
["II_BOLT"] = get_item_data,
["WP_AK74"] = get_weapon_data,
["WP_ASHTG"] = get_weapon_data,
["WP_BINOC"] = get_weapon_data,
["WP_BM16"] = get_weapon_data,
["WP_GROZA"] = get_weapon_data,
["WP_HPSA"] = get_weapon_data,
["WP_KNIFE"] = get_weapon_data,
["WP_LR300"] = get_weapon_data,
["WP_PM"] = get_weapon_data,
["WP_RG6"] = get_weapon_data,
["WP_RPG7"] = get_weapon_data,
["WP_SVD"] = get_weapon_data,
["WP_SVU"] = get_weapon_data,
["WP_VAL"] = get_weapon_data,
["S_EXPLO"] = get_item_data,
["II_EXPLO"] = get_item_data,
["AMMO"] = get_ammo_data,
["AMMO_S"] = get_ammo_data,
["S_OG7B"] = get_ammo_data,
["S_VOG25"] = get_ammo_data,
["S_M209"] = get_ammo_data,
["G_F1_S"] = get_item_data,
["G_RGD5_S"] = get_item_data,
["G_F1"] = get_item_data,
["G_RGD5"] = get_item_data,
["WP_SCOPE"] = get_item_data,
["WP_SILEN"] = get_item_data,
["W_SILENC"] = get_item_data,
["WP_GLAUN"] = get_item_data
}
local class = system_ini():r_string(sobj:section_name(),"class")
if (class == nil or class == "") then
return nil
end
return m_classes[class] and m_classes[class](sobj) or nil
end
function set_object_data(t,sobj)
if not (sobj) then
return nil
end
local m_classes = {
["S_ACTOR"] = set_actor_data,
["O_ACTOR"] = set_actor_data,
["ARTEFACT"] = set_item_data,
["SCRPTART"] = set_item_data,
["II_ATTCH"] = set_item_data,
["II_BTTCH"] = set_item_data,
["II_DOC"] = set_item_document_data,
["TORCH_S"] = set_item_data,
["TORCH"] = set_item_data,
["DET_SIMP"] = set_item_data,
["DET_ADVA"] = set_item_data,
["DET_ELIT"] = set_item_data,
["DET_SCIE"] = set_item_data,
["E_STLK"] = set_item_data,
["E_HLMET"] = set_item_data,