-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.lua
3351 lines (2914 loc) · 121 KB
/
script.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
PermNone=0
PermAuth=1
PermMod=2
PermModPlus=2.69
PermAdmin=3
PermDev=69
PermOwner=420
PermsList={{PermAdmin,"Admin","Admin"},{PermMod,"Moderator","Mod"},{PermModPlus,"Moderator","Mod"},{PermDev,"Developer","Dev"},{PermOwner,"Owner","Owner"},{PermNone,"Player","Player"},{PermAuth,"Player","Player"}}
g_savedata = {}
NoSave={Player={},SeatQueue={},VehicleTPQueue={},ChatMessageClearQueue={},LastObjectID=0,CurrentObjectID=0,FlaresDetectedLast=0,AntiLagData={LastAbove=0,WeatherLastDetected=0}}
Ticks=0
LastMS=server.getTimeMillisec()
ServerStartTime=0
LastTimeUpdate=0
TimeDifference=0
LastSave=0
LastAnnounceTime=0
LastAnnouncement=0
ServerConfig={
Version="3.0.3",
TpsHistoryLength=12,
SpeedHistoryLength=5,
ResetSettings=false,
MessageHistoryLength=200,
ItemsPerRequest=8,
AdminPermLevel=PermMod,
ServerDataName="ServerA",
ServerData={
ServerA={
Port=8000,
AutoAuth=true,
AuthOnAcceptPopup=false,
AuthCommand={"accept","auth","bob"},
AuthPopupText="",
RequireReAuthOnWarn=true,
RemovePlayerVehiclesOnWarn=true,
DefaultKit={0,15,6},
Autosave=false,
ServerName="Stormworks Server",
RandomAnnouncementsFrequency=300,
BannedWords={},
RandomAnnouncements={
"You can do ?help for command help",
"?pvp [Player ID/Name] will tell you that players pvp status",
"If you want to know a vehicles pvp state at a glance do ?pvp_view",
"Spawning laggy vehicles is not allowed",
"Do ?rules to view the server rules",
"If you see someone breaking the rules do ?report (PlayerID) (Report Reason)",
"If you want to know a vehicles pvp state at a glance do ?pvp_view",
"Remember to check a players pvp status before pvping using ?pvp_view or ?pvp [Player ID/Name]",
"During pvp you must have your pvp on (To toggle your pvp do ?pvp)",
"You can teleport your vehicle to you by doing ?tvtm (Vehicle ID)",
"Don't fire into or out of the hanger",
"Consider the play experience of others: Don't spawn big vehicles"
}
}
}
}
TPS=0
TPSList={}
TPSDivisor=0
TpList={}
ScriptReloaded=false
for X =1,ServerConfig["TpsHistoryLength"],1 do
TPSDivisor=TPSDivisor + X
table.insert(TPSList,0)
end
TPSDivisor=1/TPSDivisor
SpeedDivisor=0
for X =1,ServerConfig["SpeedHistoryLength"],1 do
SpeedDivisor=SpeedDivisor + X
end
SpeedDivisor=1/SpeedDivisor
GiveItems={{"diving",1,{100,100},2}, {"firefighter",2,{nil,nil},2}, {"scuba",3,{100,100},2}, {"parachute",4,{1,nil},2}, {"arctic",5,{nil,nil},2}, {"binoculars",6,{nil,nil},0}, {"cable",7,{nil,nil},1}, {"compass",8,{nil,nil},0}, {"defibrillator",9,{4,nil},1}, {"fire_extinguisher",10,{nil,9},1}, {"first_aid",11,{4,nil},0}, {"flare",12,{4,nil},0}, {"flaregun",13,{1,nil},0}, {"flaregun_ammo",14,{4,nil},0}, {"flashlight",15,{nil,100},0}, {"hose",16,{nil,nil},1}, {"night_vision_binoculars",17,{nil,100},0}, {"oxygen_mask",18,{nil,100},0}, {"radio",19,{nil,100},0}, {"radio_signal_locator",20,{nil,100},1}, {"remote_control",21,{nil,100},0}, {"rope",22,{nil,nil},1}, {"strobe_light",23,{0,100},0}, {"strobe_light_infrared",24,{0,100},0}, {"transponder",25,{0,100},0}, {"underwater_welding_torch",26,{nil,250},1}, {"welding_torch",27,{nil,400},1}, {"coal",28,{nil,nil},0}, {"hazmat",29,{nil,nil},2},{"radiation_detector",30,{nil,100},0}, {"c4",31,{1,nil},0}, {"c4_detonator",32,{nil,nil},0}, {"speargun",33,{1,nil},1}, {"speargun_ammo",34,{4,nil},0}, {"pistol",35,{17,nil},0}, {"pistol_ammo",36,{17,nil},0}, {"smg",37,{40,nil},1}, {"smg_ammo",38,{40,nil},0}, {"rifle",39,{30,nil},1}, {"rifle_ammo",40,{30,nil},0}, {"grenade",41,{1,nil},0},{"glowstick",72,{12,nil},0},{"dog_whistle",73,{nil,nil},0},{"bomb_disposal",74,{nil,nil},2},{"chest_rig",75,{nil,nil},2},{"black_hawk_vest",76,{nil,nil},2},{"plate_vest",77,{nil,nil},2},{"armor_vest",78,{nil,nil},2},{"space_suit",79,{100,100},2},{"space_exploration_suit",80,{100,100},2},{"fishing_rod",81,{nil,nil},1}}
function GetServerConfigData()
return ServerConfig["ServerData"][ServerConfig["ServerDataName"]]
end
function Announce(Title,Message,PeerID)
if PeerID == nil then
PeerID=-1
end
server.announce(Title,Message,PeerID)
AddToMessageHistory(Title,Message,PeerID)
end
function FixBlankPlayer(PlayerName,PeerID)
if PlayerName == nil then
return PlayerName
end
if RemoveTrailingAndLeading(tostring(tostring(PlayerName):gsub('%W',''))) == "blank" then
PlayerName="Blank " .. tostring(PeerID)
--Announce("efawef",PlayerName)
end
return PlayerName
end
function AddToMessageHistory(Title,Message,PeerID)
if PeerID == -1 then
for _,Y in pairs(FilteredServerPlayers()) do
AddToPlayerMessageHistory(Title,Message,Y.id)
end
else
AddToPlayerMessageHistory(Title,Message,PeerID)
end
end
function AddToPlayerMessageHistory(Title,Message,PeerID)
if NoSave["Player"][PeerID] ~= nil then
table.insert(NoSave["Player"][PeerID]["MessageHistory"],{Title,Message})
if #NoSave["Player"][PeerID]["MessageHistory"] > ServerConfig["MessageHistoryLength"] then
table.remove(NoSave["Player"][PeerID]["MessageHistory"],1)
end
end
end
function SendMessageHistory()
for _,Y in pairs(FilteredServerPlayers()) do
for C=0, ServerConfig["MessageHistoryLength"] - #NoSave["Player"][Y.id]["MessageHistory"], 1 do
server.announce(" "," ",Y.id)
end
--S.announce("WEFewa",tostring(#NoSave["Player"][Y.id]["MessageHistory"]))
for _,B in pairs(NoSave["Player"][Y.id]["MessageHistory"]) do
server.announce(B[1],B[2],Y.id)
end
end
end
function HeartBeatSend()
local Uptime=FormatTime(math.floor(g_savedata["Seconds"] - ServerStartTime))
local UptimeString=tostring(Uptime[4] * 24 + Uptime[3]) .. "h," .. tostring(Uptime[2]) .. "m"
local Out={"HeartBeat",TPS,#server.getPlayers() - 1,UptimeString}
local PlayerList=" "
for _,Y in pairs(FilteredServerPlayers()) do
if tostring(Y.steam_id) ~= "0" then
PlayerList=PlayerList .. "- ".. Y.name .. " (" .. tostring(Y.id) .. ")/|n"
end
end
if PlayerList == " " then
PlayerList="No players online"
end
table.insert(Out,PlayerList)
SendHttp(Out)
end
function DiscordNotify(PeerID,Title,Message,Type,Discord)
if Discord == true then
SendHttp({"TypeDiscordCommandResponse",Title,Message,NotificationType})
else
server.notify(PeerID,Title,Message,Type)
end
end
function GetSteamID(PeerID)
if NoSave["Player"][PeerID] == nil then
return "0"
end
return tostring(NoSave["Player"][PeerID]["SteamID"])
end
function GetPlayerData(PeerID)
for X,Y in pairs(FilteredServerPlayers()) do
if Y.id == tonumber(PeerID) then
return Y
end
end
return nil
end
function SendHttp(List)
local Per=ServerConfig["ItemsPerRequest"]
local Total=math.ceil(#List / Per)
local TimeStamp=server.getTimeMillisec()
local StringList={"1/"..tostring(Total) .. "\n" .. tostring(TimeStamp) .. "\n"}
local Z=1
for X,Y in pairs(List) do
StringList[Z]=StringList[Z] .. tostring(Y) .. "\n"
if X % Per == 0 and X ~= 1 and X ~= #List then
Z=Z + 1
StringList[Z]=tostring(Z) .."/"..tostring(Total) .. "\n" .. tostring(TimeStamp) .. "\n"
end
end
for _,Y in pairs(StringList) do
server.httpGet(ServerConfig["ServerData"][ServerConfig["ServerDataName"]]["Port"], "HTTP/1.1 200 OK\n" .. Y)
--S.announce(tostring(X),tostring(Y))
end
end
function FormatTime(Seconds)
local Years=math.floor(Seconds / 31536000)
local Days=math.floor((Seconds % 31536000) / 86400)
local Hours=math.floor((Seconds % 86400) / 3600)
local Minutes=math.floor((Seconds % 3600) / 60)
local Seconds=math.floor((Seconds % 60))
return {Seconds,Minutes,Hours,Days,Years}
end
function OnlyNumbers(String)
return not (String == "" or String == nil or String:find("%D"))
end
function RemoveNonAscii(String)
return string.gsub(String, "[\128-\255]", "")
end
function RemoveTrailingAndLeading(String)
return string.match(String,'^%s*(.-)%s*$')
end
function AutoComplete(String,List)
local StartOfString={}
local MiddleOfString={}
for Y,X in pairs(List) do
local Start,End=string.find(X,String)
if X == String then
return X,Y
end
if Start == 1 then
table.insert(StartOfString,{X,Y})
elseif Start ~= nil then
if Start > 1 and string.len(String) > 1 then
table.insert(MiddleOfString,{X,Y})
end
end
end
local AllEqualStart=true
if #StartOfString > 0 then
for _,X in pairs(StartOfString) do
if X[1] ~= StartOfString[1][1] then
AllEqualStart=false
break
end
end
else
AllEqualStart=false
end
if #StartOfString == 1 or AllEqualStart == true then
return StartOfString[1][1],StartOfString[1][2]
elseif #StartOfString == 0 and #MiddleOfString == 1 then
return MiddleOfString[1][1],MiddleOfString[1][2]
end
return nil,nil
end
function ConvertToPeer(String,List)
if String == nil then
return
end
local ReturnSteamID=false
if List == nil then
List={}
else
ReturnSteamID=true
end
String=string.lower(String)
local FullyNumbers=OnlyNumbers(String)
local AutoCompletePlayerNames={}
for _,Y in pairs(List) do
local NameFiltered=string.lower(RemoveNonAscii(FixBlankPlayer(Y.Name,Y.id)))
if (tostring(Y.SteamID) == tostring(String) and FullyNumbers) or NameFiltered == String then
return tostring(Y.SteamID)
end
table.insert(AutoCompletePlayerNames,NameFiltered)
end
for _,Y in pairs(FilteredServerPlayers()) do
local NameFiltered=string.lower(RemoveNonAscii(FixBlankPlayer(Y.name,Y.id)))
if ((tonumber(Y.id) == tonumber(String) or tostring(Y.steam_id) == tostring(String)) and FullyNumbers) or NameFiltered == String then
if ReturnSteamID == true then
return tostring(Y.steam_id)
else
return Y.id
end
end
table.insert(AutoCompletePlayerNames,NameFiltered)
end
String=string.gsub(String, "%W", "%%%1" )
local AutoCompleteResult=AutoComplete(String,AutoCompletePlayerNames)
if AutoCompleteResult ~= nil then
for _,Y in pairs(List) do
if string.lower(RemoveNonAscii(Y.Name)) == string.lower(AutoCompleteResult) then
return tostring(Y.SteamID)
end
end
for _,Y in pairs(FilteredServerPlayers()) do
if string.lower(RemoveNonAscii(FixBlankPlayer(Y.name,Y.id))) == string.lower(AutoCompleteResult) then
if ReturnSteamID == true then
return tostring(Y.steam_id)
else
return Y.id
end
end
end
end
end
function Lines(String)
local LineList = {}
for X in String:gmatch("[^\r\n]+") do
table.insert(LineList, X)
end
return LineList
end
function ReplaceNil(Text)
if Text == "nil" then
return nil
end
return Text
end
function httpReply(Port, Request, Reply)
local ReplyList=Lines(Reply)
if ReplyList[1] == "TypeDiscordMessage" then
Announce("[Discord] " .. ReplyList[2],ReplyList[3])
elseif ReplyList[1] == "TypeServerRestarting" then
Announce("[Server]","The server will be restarting shortly")
server.save()
elseif ReplyList[1] == "TypeExecuteCommand" then
onCustomCommand(ReplyList[2], -1, true, true, ReplaceNil(ReplyList[3]), ReplaceNil(ReplyList[4]), ReplaceNil(ReplyList[5]), ReplaceNil(ReplyList[6]), ReplaceNil(ReplyList[7]),ReplaceNil(ReplyList[9]),true)
end
end
function FilteredServerPlayers()
local Output={}
for _,X in pairs(server.getPlayers()) do
if NoSave["Player"][X.id] ~= nil then
if g_savedata["PlayerData"][tostring(X["steam_id"])] ~= nil then
table.insert(Output,X)
end
end
end
return Output
end
function ParsePermissions(Permissions,ShortForm)
if ShortForm == nil then
ShortForm=false
end
if Permissions > 100000 then
if ShortForm == true then
return "Dev"
else
return "Developer"
end
end
for _,X in pairs(PermsList) do
if X[1] == Permissions then
if ShortForm == true then
return X[3]
else
return X[2]
end
end
end
end
function UpdatePlayerPermissionsMessage(PeerID,SendPermissionMessage)
if SendPermissionMessage == true then
local PermString=ParsePermissions(NoSave["Player"][PeerID]["Permissions"])
if PermString ~= nil then
Announce("[Server]","You have been given permission: " .. PermString,PeerID)
end
end
end
function UpdatePlayerPermissions(PeerID,SendPermissionMessage)
local SteamID=GetSteamID(PeerID)
local PlayerData=GetPlayerData(PeerID)
if PlayerData["admin"] and NoSave["Player"][PeerID]["Permissions"] < PermAdmin then
NoSave["Player"][PeerID]["Permissions"]=PermAdmin
UpdatePlayerPermissionsMessage(PeerID,SendPermissionMessage)
end
if PlayerData["auth"] and NoSave["Player"][PeerID]["Permissions"] < PermAuth then
NoSave["Player"][PeerID]["Permissions"]=PermAuth
UpdatePlayerPermissionsMessage(PeerID,SendPermissionMessage)
end
end
function InvalidPlayerID(PeerID,Discord)
DiscordNotify(PeerID, "Invalid ID", "Please enter a valid player ID/Name", 6,Discord)
end
function GetPerms(PeerID)
if PeerID == -1 then
return 100000000
end
if NoSave["Player"][PeerID] == nil then
return 0
end
return NoSave["Player"][PeerID]["Permissions"]
end
function AnnounceAbovePerms(Name,Message,MinimumPermissions,ExcludePlayerID)
if ExcludePlayerID == nil then
ExcludePlayerID=-1
end
for X,Y in pairs(FilteredServerPlayers()) do
if GetPerms(Y.id) >= MinimumPermissions then
if Y.id ~= ExcludePlayerID then
Announce(Name,Message,Y.id)
end
end
end
end
function PlayerOnline(PeerID)
if PeerID == nil then
return false
end
return NoSave["Player"][tonumber(PeerID)] ~= nil
end
function ValidateSettings(ResetSettings)
local ExpectedSettings={UIEnabled=true,UIDefaultState=true,VehicleTooltips=true,AllowPvpPrevent=true,AnnouncePvpChange=true,NonAdminTpToPlayer=false,NonAdminTeleportVehicles=true,NonAdminGoto=true,NonAdminGotoOnlyOwned=true,ClearVehiclesOnLeave=true,NonAdminTpCommand=true,EnforceVehicleLimit=true,VehicleLimit=1,NonAdminPrivateMessage=true,RemoveBodysOnLeave=true,NonAdminToolCommand=true,NonAdminRepair=true,NoDropsOnDeath=true,DisableItemDrops=false,EnforceItemLimit=true,ItemLimit=3,NonAdminViewStaff=true,NonAdminHeal=true,NonAdminHealOther=false,EnableSelfKill=true,NonAdminFlip=true,NonAdminPvpView=true,AntiRadiation=true,UseDefaultKit=true,RandomAnnouncementsEnabled=true,NonAdminEject=true,EjectTpLocation=4,NonAdminClearSelfInv=true,NonAdminCharge=true,NonAdminFill=true,NonAdminInfItems=true,ShowPermissionsInChat=false,AntiEMP=true,AntiOilSpill=true}
if g_savedata["Settings"] == nil then
g_savedata["Settings"]={}
end
for X,Y in pairs(ExpectedSettings) do
if g_savedata["Settings"][X] == nil or ResetSettings then
g_savedata["Settings"][X]=Y
end
end
end
function GetSetting(Setting)
return g_savedata["Settings"][Setting]
end
function ValidateVehicleData(GroupID,PeerID)
local ExpectedVehicleData={GroupID=GroupID,OwnerID=PeerID,OwnerSteamID=nil,Parts={},MainBody=-1,SpawnTime=g_savedata["Seconds"],Voxels=0,Mass=0,VehicleComponents={},Loaded=false,StartTPS=TPS,LoadedTime=0,AntiLagCleared=false,MaxTPS=TPS,AntiLagVehicleStrikes=0,Speeds={},LastPosition=server.getPlayerPos(PeerID),Speed=0,Name="Unknown"}
if g_savedata["Vehicles"][GroupID] == nil then
g_savedata["Vehicles"][GroupID]={}
end
for X,Y in pairs(ExpectedVehicleData) do
if g_savedata["Vehicles"][GroupID][X] == nil then
g_savedata["Vehicles"][GroupID][X]=Y
end
end
if PeerID ~= nil then
g_savedata["Vehicles"][GroupID]["OwnerSteamID"]=GetSteamID(PeerID)
end
end
function ValidatePlayerSaveData(PlayerSteamID,Name)
local ExpectedPlayerData={FirstJoin=-1,LastJoin=0,Playtime=0,Name=Name,History={},Banned={State=false,BanTime=0,BannedTime=0,Reason=""},WarnCount=0,KickCount=0,JoinCount=0,VehicleCount=0,DeathCount=0,Balance=4200}
if g_savedata["PlayerData"][PlayerSteamID] == nil then
g_savedata["PlayerData"][PlayerSteamID]={}
end
for X,Y in pairs(ExpectedPlayerData) do
if g_savedata["PlayerData"][PlayerSteamID][X] == nil then
g_savedata["PlayerData"][PlayerSteamID][X]=Y
end
end
g_savedata["PlayerData"][PlayerSteamID]["Balance"]=(math.floor((g_savedata["PlayerData"][PlayerSteamID]["Balance"] * 100)) / 100)
end
function ValidatePlayerData(PeerID)
local ExpectedNoSaveData={PeerID=PeerID,SteamID="",UI=GetSetting("UIDefaultState"),Pvp=not GetSetting("AllowPvpPrevent"),AntiSteal=true,Permissions=0,MessageHistory={},Seat={VehicleID=-1,GroupID=-1,X=0,Y=0,Z=0},Speeds={},LastPosition=server.getPlayerPos(PeerID),Speed=0,LastMessager=-1,Muted=false,PvpOffOnRespawn=false,LastShowedDeathMessage=0,PvpView=false,BanView=false,Muted=false,Joined=g_savedata["Seconds"],Freeze={State=false,Pos=nil},TrackVehicles={State=false},Blind=false,BlackListedPlayers={},Follow={State=false,Followed=-1,Height=100},DisableInv=false,Seated=false,DisableVehicleSpawning=false}
if NoSave["Player"][PeerID] == nil then
NoSave["Player"][PeerID]={}
end
for X,Y in pairs(ExpectedNoSaveData) do
if NoSave["Player"][PeerID][X] == nil then
NoSave["Player"][PeerID][X]=Y
end
end
if CountItems(NoSave["Player"][PeerID]["Speeds"]) < ServerConfig["SpeedHistoryLength"] then
for X =1,ServerConfig["SpeedHistoryLength"],1 do
table.insert(NoSave["Player"][PeerID]["Speeds"],0)
end
end
for _,Y in pairs(server.getPlayers()) do
if NoSave["Player"][Y.id] ~= nil then
NoSave["Player"][Y.id]["SteamID"]=tostring(Y["steam_id"])
end
end
local PlayerSteamID=GetSteamID(PeerID)
ValidatePlayerSaveData(PlayerSteamID,server.getPlayerName(PeerID))
UpdatePlayerPermissions(PeerID,true)
end
function CharacterIDToPlayerID(CharacterID)
for _,X in pairs(FilteredServerPlayers()) do
if tostring(server.getPlayerCharacterID(X.id)) == tostring(CharacterID) then
return X.id
end
end
end
function ChangePvp(PeerID,State,Notify)
local AnnounceChange=false
if NoSave["Player"][PeerID]["Pvp"] ~= State and Notify then
AnnounceChange=true
end
NoSave["Player"][PeerID]["Pvp"]=State
local PlayerName=FixBlankPlayer(server.getPlayerName(PeerID),PeerID)
SendHttp({"TypeChangePvp",PlayerName,GetSteamID(PeerID),tostring(NoSave["Player"][PeerID]["Pvp"])})
if AnnounceChange then
local RequiredPerms=PermMod
if GetSetting("AnnouncePvpChange") then
RequiredPerms=PermNone
end
AnnounceAbovePerms("[Pvp]", PlayerName .. " has changed their pvp state to " .. tostring(NoSave["Player"][PeerID]["Pvp"]),RequiredPerms,-1)
end
for _,Y in pairs(g_savedata["Vehicles"]) do
if tonumber(PeerID) == Y["OwnerID"] then
if Y["MainBody"] ~= nil then
for _,A in pairs(FilteredServerPlayers()) do
PvpViewPopup(Y["GroupID"],A.id)
TrackVehiclesPopup(Y["GroupID"],A.id)
end
end
for X,_ in pairs(Y["Parts"]) do
server.setVehicleInvulnerable(tonumber(X),not State)
SetVehicleToolTip(X,Y["GroupID"],PeerID)
end
end
end
end
function ChangeAntiSteal(PeerID,State)
NoSave["Player"][PeerID]["AntiSteal"]=State
for _,Y in pairs(g_savedata["Vehicles"]) do
if tonumber(PeerID) == Y["OwnerID"] then
for X,_ in pairs(Y["Parts"]) do
server.setVehicleEditable(tonumber(X),not State)
end
end
end
end
function CountItems(Table)
local Count=0
for _,__ in pairs(Table) do
Count=Count + 1
end
return Count
end
function CheckVehicleDespawns()
for X,Y in pairs(g_savedata["Vehicles"]) do
if CountItems(Y["Parts"]) == 0 then
onGroupDespawn(math.floor(Y["GroupID"]),Y["OwnerID"])
g_savedata["Vehicles"][X]=nil
for _,A in pairs(FilteredServerPlayers()) do
PvpViewPopup(Y["GroupID"],A.id)
TrackVehiclesPopup(Y["GroupID"],A.id)
end
end
end
end
function SplitOnNewLine(String)
local Output={}
for X in String:gmatch('[^\n]+') do
table.insert(Output,X)
end
return Output
end
function CheckVehiclesExist()
for _,X in pairs(g_savedata["Vehicles"]) do
for Y,_ in pairs(X["Parts"]) do
local _,Found=server.getVehicleData(Y)
if Found == false then
g_savedata["Vehicles"][X["GroupID"]]["Parts"][Y]=nil
end
end
end
end
function onCreate()
math.randomseed(server.getTimeMillisec())
--ServerConfig["ServerData"][ServerConfig["ServerDataName"]]["BannedWords"]=
table.sort(ServerConfig["ServerData"][ServerConfig["ServerDataName"]]["BannedWords"],function(X,Y) return string.len(X) > string.len(Y) end)
if g_savedata["PlayerData"] == nil then
g_savedata["PlayerData"]={}
end
if g_savedata["Vehicles"] == nil then
g_savedata["Vehicles"]={}
end
if g_savedata["Items"] == nil then
g_savedata["Items"]={}
end
if g_savedata["Stats"] == nil then
g_savedata["Stats"]={}
end
if g_savedata["NonCorrectedSeconds"] == nil then
g_savedata["NonCorrectedSeconds"]=0
end
if g_savedata["Seconds"] == nil then
g_savedata["Seconds"]=0
end
NoSave["AntiLagData"]["LastAbove"]=g_savedata["Seconds"] + 30
LastAnnounceTime=g_savedata["Seconds"]
LastTimeUpdate=g_savedata["Seconds"]
ServerStartTime=g_savedata["Seconds"]
ValidateSettings(ServerConfig["ResetSettings"])
for _,Y in pairs(server.getPlayers()) do
ValidatePlayerData(Y.id)
local PlayerSteamID=GetSteamID(Y.id)
local BanStatus=CheckBannedStatus(PlayerSteamID)
if BanStatus ~= false and GetPerms(Y.id) < 10000 then
SetupBannedPlayer(PlayerSteamID,Y.id,BanStatus)
end
end
for X,Y in pairs(g_savedata["Items"]) do
if NoSave["Player"][Y] == nil then
server.despawnObject(X,true)
g_savedata["Items"][X]=nil
end
end
CheckVehiclesExist()
CheckVehicleDespawns()
if g_savedata["Settings"]["RemoveBodysOnLeave"] then
server.setGameSetting("despawn_on_leave", true)
else
server.setGameSetting("despawn_on_leave", false)
end
for _,X in pairs(g_savedata["Vehicles"]) do
for _,A in pairs(FilteredServerPlayers()) do
PvpViewPopup(X["GroupID"],A.id)
TrackVehiclesPopup(X["GroupID"],A.id)
end
for Y,_ in pairs(X["Parts"]) do
server.setVehicleEditable(Y, false)
if NoSave["Player"][X["OwnerID"]] ~= nil then
if NoSave["Player"][X["OwnerID"]]["Pvp"] == false then
server.setVehicleInvulnerable(tonumber(Y),true)
end
if g_savedata["Settings"]["VehicleTooltips"] == true then
SetVehicleToolTip(tonumber(Y),X["GroupID"],X["OwnerID"])
else
server.setVehicleTooltip(tonumber(Y),"")
end
elseif GetSetting("ClearVehiclesOnLeave") then
server.despawnVehicleGroup(X["GroupID"],true)
end
end
end
local Zones = server.getZones()
for _,X in pairs(Zones) do
local ZoneData=SplitOnNewLine(X["tags_full"])
if ZoneData[2] ~= "" then
TpList[tostring(ZoneData[1])]={ZoneData[2],X["transform"]}
end
end
Announce("[Server]","Reloaded Scripts")
ScriptReloaded=true
end
function SetVehicleToolTip(VehicleID,GroupID,PeerID)
local Name = FixBlankPlayer(server.getPlayerName(PeerID),PeerID)
server.setVehicleTooltip(VehicleID,"Owner(" .. tostring(math.floor(PeerID)) .."):" .. Name .. "\nVehicle: #" .. math.floor(GroupID) .. "\nPart: #" ..tostring(tonumber(VehicleID) + 1000) .. "\nPvp: " .. tostring(NoSave["Player"][PeerID]["Pvp"]))
end
function ComputeTPS()
local CurrentTPS=(1000 / (server.getTimeMillisec() - LastMS)) * 5
for X,Y in pairs(TPSList) do
TPSList[X]=TPSList[X + 1]
end
TPSList[ServerConfig["TpsHistoryLength"]]=CurrentTPS
TPS=0
for X =1,ServerConfig["TpsHistoryLength"],1 do
TPS=TPS + (TPSList[X] * (TPSDivisor * X))
end
TPS=math.floor(TPS * 10) / 10
LastMS=server.getTimeMillisec()
end
function TrainString(Text,Chars)
if #Text > Chars then
return string.sub(Text,1,Chars-3) .. "..."
else
return Text
end
end
function UpdatePlayerUI(PlayerData,UptimeString)
local VehicleList=""
for _,A in pairs(g_savedata["Vehicles"]) do
if tonumber(A["OwnerID"]) == tonumber(PlayerData.id) then
VehicleList=VehicleList .. A["Name"] .. " #" .. math.floor(A["GroupID"]) .. "\n"
end
end
if VehicleList == "" then
VehicleList="[No Spawned Vehicles]\n"
end
local Playtime=FormatTime(math.floor(g_savedata["PlayerData"][tostring(PlayerData["steam_id"])]["Playtime"]))
local PlaytimeString="[" .. tostring(Playtime[4] * 24 + Playtime[3]) .. "h," .. tostring(Playtime[2]) .. "m," .. tostring(Playtime[1]) .. "s]"
local PvpString="[Pvp On]"
if NoSave["Player"][PlayerData.id]["Pvp"] == false and (GetSetting("AllowPvpPrevent") or GetPerms(PlayerData.id) >= PermMod) then
PvpString="[Pvp Off]"
end
local AntiStealString="[Antisteal On]"
if NoSave["Player"][PlayerData.id]["AntiSteal"] == false then
AntiStealString="[Antisteal Off]"
end
local PlayerPos= server.getPlayerPos(PlayerData.id)
local PlayerX,PlayerY,PlayerZ = matrix.position(PlayerPos)
local PvpEnabledPlayers="[Pvp Players]\n"
local AnyPvp=false
for _,A in pairs(NoSave["Player"]) do
if A["Pvp"] then
AnyPvp=true
PvpEnabledPlayers=PvpEnabledPlayers .. TrainString(FixBlankPlayer(server.getPlayerName(A["PeerID"]),A["PeerID"]),15) .. "\n"
end
end
if AnyPvp == false then
PvpEnabledPlayers=PvpEnabledPlayers .. "No Players\n"
end
PvpEnabledPlayers=PvpEnabledPlayers .. "\n"
local UIBuilder="-INFO-\nTPS: " .. TPS .. "\nVersion: " .. ServerConfig["Version"].."\nUptime:\n" .. UptimeString .. "\n\nPlaytime:\n" .. PlaytimeString .. "\n\n" .. PvpString .. "\n" .. AntiStealString .. "\n\n" .. PvpEnabledPlayers .. VehicleList .. "\nM/S: " .. tostring(NoSave["Player"][PlayerData.id]["Speed"]) .. "\nAlt:" .. (math.floor(PlayerY * 10) / 10) .. "m"
server.setPopupScreen(PlayerData.id, 1, "", true,UIBuilder, -0.9, 0.5)
end
function ComputePlayerSpeed(PeerID)
local PlayerPos=server.getPlayerPos(PeerID)
local CurrentSpeed=matrix.distance(NoSave["Player"][PeerID]["LastPosition"],PlayerPos) * 12
NoSave["Player"][PeerID]["LastPosition"]=PlayerPos
for X,Y in pairs(NoSave["Player"][PeerID]["Speeds"]) do
NoSave["Player"][PeerID]["Speeds"][X]=NoSave["Player"][PeerID]["Speeds"][X + 1]
end
NoSave["Player"][PeerID]["Speeds"][ServerConfig["SpeedHistoryLength"]]=CurrentSpeed
local Speed=0
for X =1,ServerConfig["SpeedHistoryLength"],1 do
Speed=Speed + (NoSave["Player"][PeerID]["Speeds"][X] * (SpeedDivisor * X))
end
NoSave["Player"][PeerID]["Speed"]=math.floor(Speed * 10) / 10
end
function ConvertToBase64(Number,Digits)
local DigitList={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9","+","/"}
local CheckValue=(64 ^ Digits) - 1
if Number > CheckValue then
Number=CheckValue
end
local Multiplyer=64 ^ (Digits - 1)
local Output=""
for X=1,Digits do
local Value=math.floor(Number / Multiplyer)
Number=Number % Multiplyer
Multiplyer=Multiplyer / 64
Output=Output .. DigitList[Value + 1]
end
return Output
end
function onButtonPress(VehicleID, PeerID, ButtonNumber, Pressed)
for _,X in pairs(g_savedata["Vehicles"]) do
if X["Parts"][VehicleID] ~= nil then
if NoSave["Player"][X["OwnerID"]] ~= nil then
for _,Y in pairs(NoSave["Player"][X["OwnerID"]]["BlackListedPlayers"]) do
if Y["SteamID"] == GetSteamID(PeerID) then
RunEjectBlacklisted(PeerID,X["OwnerID"])
return
end
end
end
end
end
end
function RunEjectBlacklisted(PeerID,OwnerID)
if TpList[tostring(GetSetting("EjectTpLocation"))] ~= nil then
server.setPlayerPos(PeerID,TpList[tostring(GetSetting("EjectTpLocation"))][2])
else
server.setPlayerPos(PeerID,matrix.translation(0,0,0))
end
server.notify(PeerID,"Blacklisted","You are blacklisted from player with ID " .. math.floor(OwnerID) .. "'s vehicles",6)
NoSave["Player"][tonumber(PeerID)]["Seat"]={VehicleID=-1,GroupID=-1,X=0,Y=0,Z=0}
end
function onPlayerSit(PeerID, VehicleID, SeatName)
for _,X in pairs(g_savedata["Vehicles"]) do
if X["Parts"][VehicleID] ~= nil then
if NoSave["Player"][X["OwnerID"]] ~= nil then
for _,Y in pairs(NoSave["Player"][X["OwnerID"]]["BlackListedPlayers"]) do
if Y["SteamID"] == GetSteamID(PeerID) then
RunEjectBlacklisted(PeerID,X["OwnerID"])
return
end
end
end
end
end
end
function RestartServer()
SendHttp({"TypeRestart"})
end
function onTick()
Ticks=Ticks + 1
if ScriptReloaded then
--AnnounceAbovePerms("[Ticks]", tostring(Ticks),PermMod,-1)
for _,X in pairs(FilteredServerPlayers()) do
local ObjectID = server.getPlayerCharacterID(X.id)
if NoSave["Player"][X.id]["Pvp"] == false and (GetSetting("AllowPvpPrevent") or GetPerms(X.id) >= PermMod) then
server.reviveCharacter(ObjectID)
server.setCharacterData(ObjectID, 100000000, false, true)
end
if NoSave["Player"][X.id]["Freeze"]["State"] then
server.setPlayerPos(X.id,NoSave["Player"][X.id]["Freeze"]["Pos"])
else
if NoSave["Player"][X.id]["Follow"]["State"] == true then
if NoSave["Player"][NoSave["Player"][X.id]["Follow"]["Followed"]] ~= nil then
local FollowedPos=server.getPlayerPos(NoSave["Player"][X.id]["Follow"]["Followed"])
local FollowedX,FollowedY,FollowedZ= matrix.position(FollowedPos)
server.setPlayerPos(X.id,matrix.translation(FollowedX,FollowedY + NoSave["Player"][X.id]["Follow"]["Height"],FollowedZ))
end
end
end
end
if #NoSave["SeatQueue"] > 0 then
for X,Y in pairs(NoSave["SeatQueue"]) do
local Simulating, Found = server.getVehicleSimulating(Y["VehicleID"])
if Found == false then
table.remove(NoSave["SeatQueue"],X)
server.notify(Y["PeerID"], "Invalid ID", "Please enter a valid vehicle ID", 6)
break
end
if Simulating == true then
local ObjectID=server.getPlayerCharacterID(Y["PeerID"])
server.setSeated(ObjectID, Y["VehicleID"], Y["X"], Y["Y"], Y["Z"])
ParseCommandGotoOutput(Y["PeerID"],Y["Type"],Y["GroupID"])
table.remove(NoSave["SeatQueue"],X)
break
end
end
end
if #NoSave["VehicleTPQueue"] > 0 then
for X,Y in pairs(NoSave["VehicleTPQueue"]) do
if Y["Type"] == "Group" then
server.setGroupPos(Y["ID"], Y["TargetPos"])
elseif Y["Type"] == "Vehicle" then
server.setVehiclePos(Y["ID"], Y["TargetPos"])
elseif Y["Type"] == "VehicleSafe" then
server.setVehiclePosSafe(Y["ID"], Y["TargetPos"])
elseif Y["Type"] == "MoveVehicle" then
server.moveVehicle(Y["ID"],Y["TargetPos"])
end
ReseatPlayers(Y["SeatedPlayers"], Y["TargetPos"])
table.remove(NoSave["VehicleTPQueue"],X)
break
end
end
if #NoSave["ChatMessageClearQueue"] > 0 then
for X,Y in pairs(NoSave["ChatMessageClearQueue"]) do
SendMessageHistory()
table.remove(NoSave["ChatMessageClearQueue"],X)
break
end
end
if Ticks % 5 == 0 then
TimeDifference=TimeDifference+ (server.getTimeMillisec() - LastMS)
if LastTimeUpdate < math.floor(g_savedata["Seconds"] + (TimeDifference / 1000)) then
g_savedata["Seconds"]=math.floor(g_savedata["Seconds"] + (TimeDifference / 1000))
for _,X in pairs(FilteredServerPlayers()) do
if g_savedata["PlayerData"][tostring(X["steam_id"])] ~= nil then
g_savedata["PlayerData"][tostring(X["steam_id"])]["Playtime"]=math.floor(g_savedata["PlayerData"][tostring(X["steam_id"])]["Playtime"] + (TimeDifference / 1000))
g_savedata["PlayerData"][tostring(X["steam_id"])]["LastJoin"]=g_savedata["Seconds"]
end
end
LastTimeUpdate=g_savedata["Seconds"]
TimeDifference=0
end
for _,X in pairs(FilteredServerPlayers()) do
ComputePlayerSpeed(X.id)
if NoSave["Player"][tonumber(X.id)]["DisableInv"] == true then
local PlayerObjectID=server.getPlayerCharacterID(X.id)
for T=1, 10 do
server.setCharacterItem(PlayerObjectID,T,0,false,0,0)
end
end
end
ComputeTPS()
if GetSetting("AntiRadiation") == true then
server.clearRadiation()
end
if GetSetting("AntiOilSpill") == true then
server.clearOilSpill()
end
if Ticks % 10 == 0 then
g_savedata["NonCorrectedSeconds"]=g_savedata["NonCorrectedSeconds"] + 0.15625
local Uptime=FormatTime(math.floor(g_savedata["Seconds"] - ServerStartTime))
local UptimeString="[" .. tostring(Uptime[4] * 24 + Uptime[3]) .. "h," .. tostring(Uptime[2]) .. "m," .. tostring(Uptime[1]) .. "s]"
for _,Y in pairs(FilteredServerPlayers()) do
if NoSave["Player"][Y.id]["BanView"] then
server.removePopup(Y.id,1)
BannedPlayerUI(Y.id)
server.setPlayerPos(Y.id,matrix.translation(69.420,69.420,69.420))
else
if GetSetting("UIEnabled") and NoSave["Player"][Y.id]["UI"] then
UpdatePlayerUI(Y,UptimeString)
else
server.removePopup(Y.id,1)
server.removePopup(Y.id,3)
end
end
end
for Y,X in pairs(g_savedata["Vehicles"]) do
for _,A in pairs(FilteredServerPlayers()) do
if NoSave["Player"][A.id]["PvpView"] == true then
PvpViewPopup(X['GroupID'],A.id)
end
if NoSave["Player"][A.id]["TrackVehicles"]["State"] == true then
TrackVehiclesPopup(X['GroupID'],A.id)
end
end
end
if Ticks % 300 == 0 then
for _,Y in pairs(FilteredServerPlayers()) do
UpdatePlayerPermissions(Y.id)
end
end
if Ticks % 30 == 0 then
local ServerConfigData=GetServerConfigData()