-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathScoreboard.ttslua
More file actions
1627 lines (1394 loc) · 65.1 KB
/
Scoreboard.ttslua
File metadata and controls
1627 lines (1394 loc) · 65.1 KB
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
--[[
SH Scoreboard
Made by Sionar
--]]
------------------Constants
VERSION = '1.7.2'
DEBUG = false
COLOR_TABLE = {'White', 'Red', 'Orange', 'Yellow', 'Green', 'Blue', 'Purple', 'Pink', 'Teal', 'Brown'}
BUTT_W = 1
BUTT_H = 1
BUTT_B_COLOR = {0,0,0,1}
COL_S = -1.5
ROW_S = -1.6
COL_W = 0.5
ROW_W = 0.25
COL = {COL_S + 0 * COL_W - 0.1, COL_S + 1 * COL_W, COL_S + 2 * COL_W, COL_S + 3 * COL_W, COL_S + 4 * COL_W, COL_S + 5 * COL_W, COL_S + 6 * COL_W}
ROW = {ROW_S + 0 * COL_W, ROW_S + 1 * ROW_W, ROW_S + 2 * ROW_W, ROW_S + 3 * ROW_W, ROW_S + 4 * ROW_W, ROW_S + 5 * ROW_W, ROW_S + 6 * ROW_W, ROW_S + 7 * ROW_W, ROW_S + 8 * ROW_W, ROW_S + 9 * ROW_W, ROW_S + 10 * ROW_W}
START_POS = {x = 100, y = 1.1, z = 8}
------------------Variables
db = {}
saveStorage = {}
winStorage = {}
name = {}
gamesPlayed = {}
libWR = {}
fasWR = {}
hitWR = {}
fhWR = {}
totWR = {}
gnum = {}
gwr = {}
lrat = {}
frat = {}
namesDisp = {}
gamesDisp = {}
ratesDisp = {}
passHash = ''
recordCheck = false
startTime = 0
minGames = 10
fWins = 0
lWins = 0
state = 0
saveNames = {'Name 1', 'Name 2', 'Name 3', 'Name 4'}
roles = Global.getTable('roles')
sessionPlayers = {}
------------------Events
function onLoad(saveString)
if not (saveString == '') then
local save = JSON.decode(saveString)
passHash = save['pH']
deserialize(save['dbStr'])
fWins = save['fw']
lWins = save['lw']
saveNames = save['sn']
saveStorage = save['dbs'] or saveStorage
sessionPlayers = save['sp'] or {}
end
roles = Global.getTable('roles')
recordCheck = false
startTime = os.time()
refreshStart()
moveBoard()
startLuaCoroutine(self, 'checkStarted')
self.setDescription('v ' .. VERSION .. '\nMade by Sionar')
end
function onSave()
local save = {}
save['pH'] = passHash
save['dbStr'] = serialize()
save['fw'] = fWins
save['lw'] = lWins
save['sn'] = saveNames
save['dbs'] = saveStorage
save['sp'] = sessionPlayers
local saveString = JSON.encode(save)
return saveString
end
function onChat(message, player)
local args = {} -- The arguments following a command
local command
for i in string.gmatch(message, "%S+") do
args[#args + 1] = i
end
if args[1] ~= nil then
command = string.lower(args[1])
end
if command == '!lu' then
if args[2] == nil then
player.broadcast('Please enter a name.', {1,0,0})
return false
end
local key = findPlayer(args[2])
if key == nil then
player.broadcast('Player not found.', {1,0,0})
else
lookupMenu()
displayPlayerStats(key)
end
return false
elseif command == '!s1' then
refreshStart()
return false
elseif command == '!s2' then
miscMenu()
return false
elseif command == '!s3' then
overStart()
return false
elseif command == '!s4' then
libStart()
return false
elseif command == '!s5' then
fasStart()
return false
elseif command == '!rl' then
if player.admin then
recLFunc()
end
return false
elseif command == '!rf' then
if player.admin then
recFFunc()
end
return false
elseif command == '!up' then
updateFunc()
return false
end
end
function checkStarted()
sleep(0.1)
Timer.destroy(self.getGUID())
Timer.create({
identifier = self.getGUID(),
function_name = 'checkStartedTimer',
delay = 5,
repetitions = 1,
})
return 1
end
function checkStartedTimer()
local started = Global.getVar('started')
if started then
updateFunc()
Timer.destroy(self.getGUID())
else
startLuaCoroutine(self, 'checkStarted')
end
end
function onDestroy()
Timer.destroy(self.getGUID())
end
function moveBoard()
local global_name = Global.getVar('MOD_NAME')
if global_name == 'Secret Hitler: CE' then
local tab = getAllObjects()
local foundTab = {}
for _, v in pairs(tab) do
if string.match(v.getName(), "Scoreboard") then
table.insert(foundTab,1,v)
end
end
self.setPositionSmooth({START_POS['x'] + (#foundTab-1) * 30, START_POS['y'], START_POS['z']})
self.setLock(true)
end
end
------------------Main Functions
function nullFunc() end
function refreshStart()
for i = 1, 10 do
if Player[COLOR_TABLE[i]].seated == false then
gamesPlayed[i] = ""
libWR[i] = ""
fasWR[i] = ""
hitWR[i] = ""
fhWR[i] = ""
totWR[i] = ""
else
if db[Player[COLOR_TABLE[i]].steam_id] == nil then
db[Player[COLOR_TABLE[i]].steam_id] = {lw = 0, fw = 0, hw = 0, lg = 0, fg = 0, hg = 0, gw = 0, gn = 0,
sn = Player[COLOR_TABLE[i]].steam_name, fr = 1000, lr = 1000}
end
local lw = db[Player[COLOR_TABLE[i]].steam_id].lw
local fw = db[Player[COLOR_TABLE[i]].steam_id].fw
local hw = db[Player[COLOR_TABLE[i]].steam_id].hw
local lg = db[Player[COLOR_TABLE[i]].steam_id].lg
local fg = db[Player[COLOR_TABLE[i]].steam_id].fg
local hg = db[Player[COLOR_TABLE[i]].steam_id].hg
if lg+fg+hg == 0 then
gamesPlayed[i] = 0
libWR[i] = "0%"
fasWR[i] = "0%"
hitWR[i] = "0%"
fhWR[i] = "0%"
totWR[i] = "0%"
else
gamesPlayed[i] = lg + fg + hg
libWR[i] = round(lw/lg * 100) .. "%"
fasWR[i] = round(fw/fg * 100) .. "%"
hitWR[i] = round(hw/hg * 100) .. "%"
fhWR[i] = round((fw+hw)/(fg+hg) * 100) .. "%"
totWR[i] = round((fw+hw+lw)/(fg+hg+lg) * 100) .. "%"
end
end
end
mainMenu()
end
function updateStart(clickedObject, playerColor)
if Player[playerColor].admin then
updateFunc()
else
broadcastToColor("Only promoted players can update the seated players.", playerColor, {1,0,0})
end
end
function updateFunc()
local entry = {}
sessionPlayers = {}
roles = Global.getTable('roles')
local players = Global.getTable('players')
if players ~= nil then
for k,v in pairs(players) do
entry = {id = Player[v].steam_id, role = roles[v]}
table.insert(sessionPlayers,entry)
end
end
broadcastToAll("Seated players updated.", {0,0,1})
refreshStart()
end
function refreshMisc()
refreshStart()
for i = 1,10 do
if Player[COLOR_TABLE[i]].seated == false then
gnum[i] = ""
gwr[i] = ""
lrat[i] = ""
frat[i] = ""
else
if db[Player[COLOR_TABLE[i]].steam_id].gn == nil then
db[Player[COLOR_TABLE[i]].steam_id].gn = 0
db[Player[COLOR_TABLE[i]].steam_id].gw = 0
end
gnum[i] = db[Player[COLOR_TABLE[i]].steam_id].gn
gwr[i] = round(db[Player[COLOR_TABLE[i]].steam_id].gw/db[Player[COLOR_TABLE[i]].steam_id].gn * 100) .. "%"
lrat[i] = db[Player[COLOR_TABLE[i]].steam_id].lr
frat[i] = db[Player[COLOR_TABLE[i]].steam_id].fr
end
end
miscMenu()
end
function recLButtonFunc(clickedObject, playerColor)
if Player[playerColor].admin then
recLFunc()
else
broadcastToColor("Only promoted players can record the game.", playerColor, {1,0,0})
end
end
function recLFunc()
if checkValid() then
for k,v in pairs(sessionPlayers) do
if v.role == 'liberal' then
db[v.id].lw = db[v.id].lw + 1
db[v.id].lg = db[v.id].lg + 1
elseif v.role == 'fascist' then
db[v.id].fg = db[v.id].fg + 1
else
db[v.id].hg = db[v.id].hg + 1
end
end
lWins = lWins + 1
broadcastToAll("Liberal victory recorded.", {0,0,1})
updateRatings('lib')
onSave()
refreshStart()
end
end
function recFButtonFunc(clickedObject, playerColor)
if Player[playerColor].admin then
recFFunc()
else
broadcastToColor("Only promoted players can record the game.", playerColor, {1,0,0})
end
end
function recFFunc()
if checkValid() then
for k,v in pairs(sessionPlayers) do
if v.role == 'liberal' then
db[v.id].lg = db[v.id].lg + 1
elseif v.role == 'fascist' then
db[v.id].fw = db[v.id].fw + 1
db[v.id].fg = db[v.id].fg + 1
else
db[v.id].hw = db[v.id].hw + 1
db[v.id].hg = db[v.id].hg + 1
end
end
fWins = fWins + 1
broadcastToAll("Fascist victory recorded.", {1,0,0})
updateRatings('fas')
onSave()
refreshStart()
end
end
function updateRatings(winner)
local libTeam = {}
local fasTeam = {}
local libShare = {}
local fasShare = {}
local tLib, tFas = 0, 0
local aLib, aFas, rLib, rFas, eLib, eFas, sLib, sFas
for k,v in pairs(sessionPlayers) do
if v.role == 'liberal' then
table.insert(libTeam, v.id)
else
table.insert(fasTeam, v.id)
end
end
for k,v in pairs(libTeam) do
tLib = tLib + db[v].lr
end
for k,v in pairs(libTeam) do
libShare[v] = db[v].lr / tLib
end
for k,v in pairs(fasTeam) do
tFas = tFas + db[v].fr
end
for k,v in pairs(fasTeam) do
fasShare[v] = db[v].fr / tFas
end
aLib = tLib/#libTeam
aFas = tFas/#fasTeam
rLib = math.pow(10,(aLib/400))
rFas = math.pow(10,(aFas/400))
eLib = rLib / (rLib + rFas)
eFas = 1 - eLib
if winner == 'lib' then
sLib = 1
sFas = 0
else
sLib = 0
sFas = 1
end
tLib = tLib + 200 * (sLib - eLib)
tFas = tFas + 200 * (sFas - eFas)
for k,v in pairs(libTeam) do
db[v].lr = round(tLib * libShare[v])
end
for k,v in pairs(fasTeam) do
db[v].fr = round(tFas * fasShare[v])
end
end
function checkValid()
local started = Global.getVar('started')
local players = getSeatedPlayers()
local currTime = os.time()
if not started then
broadcastToAll("Error recording game: Game not started.", {1,0,0})
return false
elseif recordCheck then
broadcastToAll("Error recording game: Game already recorded for this session.", {1,0,0})
return false
elseif #sessionPlayers < 5 then
broadcastToAll("Error recording game: Not enough players seated", {1,0,0})
return false
elseif currTime - startTime < 120 then
broadcastToAll("Error recording game: Please wait a couple of minutes before submitting.", {1,0,0})
return false
else
recordCheck = true
return true
end
end
function recGamble(params)
local player = params[1]
local result = params[2]
if db[Player[player].steam_id].gn == nil then
db[Player[player].steam_id].gn = 0
db[Player[player].steam_id].gw = 0
end
db[Player[player].steam_id].gn = db[Player[player].steam_id].gn + 1
if result == 'w' then
db[Player[player].steam_id].gw = db[Player[player].steam_id].gw + 1
end
if state == 1 then
refreshMisc()
end
end
function resFunc(clickedButton, playerColor)
db = {}
lWins = 0
fWins = 0
adminMenu(clickedButton, playerColor)
end
function storePass(clickedButton, playerColor)
if Player[playerColor].host then
local tab = self.getInputs()
local password = tab[1].value
if password == "" then
broadcastToColor("Please enter a password.", playerColor, {1,0,0})
return
end
passHash = hash256(password)
broadcastToColor("Password stored.", playerColor, {0,0,1})
adminMenu(clickedObject, playerColor)
end
end
function clearPass(clickedButton, playerColor)
if Player[playerColor].host then
passHash = ''
broadcastToColor("Password cleared.", playerColor, {0,0,1})
adminMenu(clickedObject, playerColor)
else
broadcastToColor("Only the host can clear the password for the scoreboard.", playerColor, {1,0,0})
end
end
function checkPass(clickedButton, playerColor)
if Player[playerColor].admin then
if passHash == '' then
broadcastToColor("Please set a password first.", playerColor, {1,0,0})
return
end
local tab = self.getInputs()
local password = tab[1].value
passCheck = hash256(password)
if passHash == passCheck then
broadcastToColor("Success. Database reset.", playerColor, {0,0,1})
resFunc(clickedButton, playerColor)
else
broadcastToColor("Incorrect password.", playerColor, {1,0,0})
end
else
broadcastToColor("Only promoted players can use the admin functions.", playerColor, {1,0,0})
end
end
function saveDB(clickedButton,playerColor,index)
if Player[playerColor].admin then
local save = {}
save['dbStr'] = serialize()
save['fw'] = fWins
save['lw'] = lWins
saveStorage[index] = JSON.encode(save)
local tab = self.getInputs()
saveNames[index] = tab[index].value
broadcastString = "Data saved to slot \"" .. tab[index].value .. "\""
broadcastToColor(broadcastString, playerColor, {0,0,1})
saveloadMenu(clickedButton, playerColor)
onSave()
else
broadcastToColor("Only promoted players can use the admin functions.", playerColor, {1,0,0})
end
end
function loadDB(clickedButton,playerColor,index)
if Player[playerColor].admin then
if saveStorage[index] == nil then
db = {}
fWins = 0
lWins = 0
else
local save = JSON.decode(saveStorage[index])
local dbStr = save['dbStr']
fWins = save['fw']
lWins = save['lw']
deserialize(dbStr)
end
local tab = self.getInputs()
broadcastString = "Data loaded from slot \"" .. tab[index].value .. "\""
broadcastToColor(broadcastString, playerColor, {0,0,1})
refreshStart()
else
broadcastToColor("Only promoted players can use the admin functions.", playerColor, {1,0,0})
end
end
for k = 1,4 do
_G['saveDB' .. k] = function(obj, col)
saveDB(obj, col, k)
end
end
for k = 1,4 do
_G['loadDB' .. k] = function(obj, col)
loadDB(obj, col, k)
end
end
function importFunc(clickedButton,playerColor)
if Player[playerColor].admin then
local tab = getAllObjects()
local oldBoard
local oldDB
local foundTab = {}
for _, v in pairs(tab) do
if string.match(v.getName(), "Scoreboard") then
table.insert(foundTab,1,v)
end
end
if #foundTab == 1 then
broadcastToColor("ERROR: Only one scoreboard found.", playerColor, {1,0,0})
elseif #foundTab > 2 then
broadcastToColor("ERROR: Too many scoreboards found.", playerColor, {1,0,0})
else
for _, v in pairs(foundTab) do
if v.getGUID() ~= self.getGUID() then
oldBoard = v
break
end
end
local dbCopy = oldBoard.getTable('db')
db = {}
for v in pairs(dbCopy) do
if dbCopy[v].fg + dbCopy[v].lg + dbCopy[v].hg > 4 then
local entry = {}
entry.sn = dbCopy[v].name or dbCopy[v].sn
entry.fg = dbCopy[v].fgp or dbCopy[v].fg
entry.hg = dbCopy[v].hgp or dbCopy[v].hg
entry.lg = dbCopy[v].lgp or dbCopy[v].lg
entry.fw = dbCopy[v].fw
entry.hw = dbCopy[v].hw
entry.lw = dbCopy[v].lw
entry.gw = dbCopy[v].gw or dbCopy[v].gamw
entry.gn = dbCopy[v].gn or dbCopy[v].gamn
entry.fr = dbCopy[v].fr or 1000
entry.lr = dbCopy[v].lr or 1000
db[v] = entry
end
end
fWins = oldBoard.getVar('fWins')
lWins = oldBoard.getVar('lWins')
local hitW = 0
local hitG = 0
for v in pairs(db) do
hitW = hitW + db[v].hw
hitG = hitG + db[v].hg or db[v].hgp
end
if hitG > fWins+lWins then
fWins = hitW
lWins = hitG - hitW
end
broadcastToColor("SUCCESS: The old records have been migrated to this board.", playerColor, {0,0,1})
getSteamNames()
end
startLuaCoroutine(self, 'refreshFunc')
onSave()
else
broadcastToColor("Only promoted players can use the admin functions.", playerColor, {1,0,0})
end
end
function getSteamNames()
local url
for v in pairs(db) do
if db[v].sn == nil then
url = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=E05421C6A86CAABADE2F700F492FFA4A&steamids=' .. v
WebRequest.get(url, self, 'getSteamNamesCB')
end
end
end
function getSteamNamesCB(req)
if req.is_done and not req.is_error then
local response = req.text
local id = response:match('id": "(.-)",')
local name = response:match('name": "(.-)",')
db[id].sn = name
local j = 0
for i = 1, 10000 do
j = j + 1
end
end
end
function overLeader()
local db_copy = {}
for v in pairs(db) do
local tempEntry = {}
tempEntry.sn = db[v].sn or db[v].name
tempEntry.fg = db[v].fg
tempEntry.hg = db[v].hg
tempEntry.lg = db[v].lg
tempEntry.fw = db[v].fw
tempEntry.hw = db[v].hw
tempEntry.lw = db[v].lw
table.insert(db_copy, tempEntry)
end
local tab = self.getInputs()
if tab == nil then
minGames = 10
else
minGames = tonumber(tab[1].value)
end
if minGames == 0 or minGames == nil then
minGames = 1
end
for v in pairs(db_copy) do
if db_copy[v].fg + db_copy[v].hg + db_copy[v].lg < minGames then
db_copy[v].owr = 0
else
db_copy[v].owr = (db_copy[v].fw + db_copy[v].hw + db_copy[v].lw) / (db_copy[v].fg + db_copy[v].hg + db_copy[v].lg)
end
end
table.sort(db_copy, compO)
local endpoint = #db_copy
if endpoint > 10 then
endpoint = 10
end
for i=1,endpoint do
if db_copy[i].fg + db_copy[i].hg + db_copy[i].lg < minGames then
namesDisp[i] = ""
gamesDisp[i] = ""
ratesDisp[i] = ""
else
namesDisp[i] = db_copy[i].sn
gamesDisp[i] = db_copy[i].fg + db_copy[i].hg + db_copy[i].lg
ratesDisp[i] = round(db_copy[i].owr * 100) .. "%"
end
end
overMenu()
end
function libLeader()
local db_copy = {}
for v in pairs(db) do
local tempEntry = {}
tempEntry.sn = db[v].sn or db[v].name
tempEntry.lg = db[v].lg
tempEntry.lw = db[v].lw
table.insert(db_copy, tempEntry)
end
local tab = self.getInputs()
if tab == nil then
minGames = 10
else
minGames = tonumber(tab[1].value)
end
if minGames == 0 or minGames == nil then
minGames = 1
end
for v in pairs(db_copy) do
if tonumber(db_copy[v].lg) < minGames then
db_copy[v].lwr = 0
else
db_copy[v].lwr = (db_copy[v].lw) / (db_copy[v].lg)
end
end
table.sort(db_copy, compL)
local endpoint = #db_copy
if endpoint > 10 then
endpoint = 10
end
for i=1,endpoint do
if tonumber(db_copy[i].lg) < minGames then
namesDisp[i] = ""
gamesDisp[i] = ""
ratesDisp[i] = ""
else
namesDisp[i] = db_copy[i].sn
gamesDisp[i] = db_copy[i].lg
ratesDisp[i] = round(db_copy[i].lwr * 100) .. "%"
end
end
libMenu()
end
function fasLeader()
local db_copy = {}
for v in pairs(db) do
local tempEntry = {}
tempEntry.sn = db[v].name or db[v].sn
tempEntry.fg = db[v].fg
tempEntry.hg = db[v].hg
tempEntry.fw = db[v].fw
tempEntry.hw = db[v].hw
table.insert(db_copy, tempEntry)
end
local tab = self.getInputs()
if tab == nil then
minGames = 10
else
minGames = tonumber(tab[1].value)
end
if minGames == 0 or minGames == nil then
minGames = 1
end
for v in pairs(db_copy) do
if db_copy[v].fg + db_copy[v].hg < minGames then
db_copy[v].fwr = 0
else
db_copy[v].fwr = (db_copy[v].fw + db_copy[v].hw) / (db_copy[v].fg + db_copy[v].hg)
end
end
table.sort(db_copy, compF)
local endpoint = #db_copy
if endpoint > 10 then
endpoint = 10
end
for i=1,endpoint do
if db_copy[i].fg + db_copy[i].hg < minGames then
namesDisp[i] = ""
gamesDisp[i] = ""
ratesDisp[i] = ""
else
namesDisp[i] = db_copy[i].sn
gamesDisp[i] = db_copy[i].fg + db_copy[i].hg
ratesDisp[i] = round(db_copy[i].fwr * 100) .. "%"
end
end
fasMenu()
end
function compF(a,b)
return a.fwr > b.fwr
end
function compL(a,b)
return a.lwr > b.lwr
end
function compO(a,b)
return a.owr > b.owr
end
function round(n)
return n % 1 >= 0.5 and math.ceil(n) or math.floor(n)
end
function sleep(numSeconds)
local t0 = os.clock()
while os.clock() - t0 <= numSeconds do
coroutine.yield(0)
end
end
function serialize()
local dbStr = ''
local delim = '«█'
for v in pairs(db) do
dbStr = dbStr .. v .. delim
dbStr = dbStr .. db[v].sn .. delim
dbStr = dbStr .. db[v].fg .. delim
dbStr = dbStr .. db[v].hg .. delim
dbStr = dbStr .. db[v].lg .. delim
dbStr = dbStr .. db[v].fw .. delim
dbStr = dbStr .. db[v].hw .. delim
dbStr = dbStr .. db[v].lw .. delim
dbStr = dbStr .. db[v].gn .. delim
dbStr = dbStr .. db[v].gw .. delim
dbStr = dbStr .. db[v].lr .. delim
dbStr = dbStr .. db[v].fr .. delim
end
debug_print(dbStr)
return dbStr
end
function deserialize(str)
local mod = 0
local v
db = {}
for word in string.gmatch(str, '([^«█]+)') do
if mod == 12 then
mod = 0
end
if mod == 0 then
v = word
db[v] = {}
elseif mod == 1 then
db[v].sn = word
elseif mod == 2 then
db[v].fg = word
elseif mod == 3 then
db[v].hg = word
elseif mod == 4 then
db[v].lg = word
elseif mod == 5 then
db[v].fw = word
elseif mod == 6 then
db[v].hw = word
elseif mod == 7 then
db[v].lw = word
elseif mod == 8 then
db[v].gn = word
elseif mod == 9 then
db[v].gw = word
elseif mod == 10 then
db[v].lr = word
elseif mod == 11 then
db[v].fr = word
end
mod = mod + 1
end
end
function debug_print(string)
if DEBUG then
print(string)
end
end
------------------User Interface
function mainMenu()
self.clearButtons()
self.clearInputs()
state = 0
local buttonParam = {click_function = 'nullFunc', label = "Name", color = BUTT_B_COLOR, font_color = stringColorToRGB('White'), function_owner = self,
position = {COL[1],0.1,ROW[1]}, rotation = {0,0,0}, width = BUTT_W, height = BUTT_H, font_size = 80}
self.createButton(buttonParam)
local buttonParam = {click_function = 'nullFunc', label = "Games\nPlayed", color = BUTT_B_COLOR, font_color = stringColorToRGB('White'), function_owner = self,
position = {COL[2],0.1,ROW[1]}, rotation = {0,0,0}, width = BUTT_W, height = BUTT_H, font_size = 50}
self.createButton(buttonParam)
local buttonParam = {click_function = 'nullFunc', label = "Fas\nWinrate", color = BUTT_B_COLOR, font_color = stringColorToRGB('White'), function_owner = self,
position = {COL[3],0.1,ROW[1]}, rotation = {0,0,0}, width = BUTT_W, height = BUTT_H, font_size = 50}
self.createButton(buttonParam)
local buttonParam = {click_function = 'nullFunc', label = "Hitler\nWinrate", color = BUTT_B_COLOR, font_color = stringColorToRGB('White'), function_owner = self,
position = {COL[4],0.1,ROW[1]}, rotation = {0,0,0}, width = BUTT_W, height = BUTT_H, font_size = 50}
self.createButton(buttonParam)
local buttonParam = {click_function = 'nullFunc', label = "F+H\nWinrate", color = BUTT_B_COLOR, font_color = stringColorToRGB('White'), function_owner = self,
position = {COL[5],0.1,ROW[1]}, rotation = {0,0,0}, width = BUTT_W, height = BUTT_H, font_size = 50}
self.createButton(buttonParam)
local buttonParam = {click_function = 'nullFunc', label = "Lib\nWinrate", color = BUTT_B_COLOR, font_color = stringColorToRGB('White'), function_owner = self,
position = {COL[6],0.1,ROW[1]}, rotation = {0,0,0}, width = BUTT_W, height = BUTT_H, font_size = 50}
self.createButton(buttonParam)
local buttonParam = {click_function = 'nullFunc', label = "Total\nWinrate", color = BUTT_B_COLOR, font_color = stringColorToRGB('White'), function_owner = self,
position = {COL[7],0.1,ROW[1]}, rotation = {0,0,0}, width = BUTT_W, height = BUTT_H, font_size = 50}
self.createButton(buttonParam)
local buttonParam = {click_function = 'updateStart', label = "Update\nPlayers", color = {1,1,1,1}, font_color = stringColorToRGB('Black'), function_owner = self,
position = {-1.6,0.1,1.4}, rotation = {0,0,0}, width = 250, height = 200, font_size = 50, tooltip = '!up'}
self.createButton(buttonParam)
local buttonParam = {click_function = 'refreshMisc', label = "Misc\nStats", color = {1,1,1,1}, font_color = stringColorToRGB('Black'), function_owner = self,
position = {-0.96,0.1,1.4}, rotation = {0,0,0}, width = 250, height = 200, font_size = 50, tooltip = 'Type !s2 in chat to open up this page'}
self.createButton(buttonParam)
local buttonParam = {click_function = 'recLButtonFunc', label = "Record\nLib Win", color = {0,0,1,1}, font_color = stringColorToRGB('White'), function_owner = self,
position = {0.32,0.1,1.4}, rotation = {0,0,0}, width = 250, height = 200, font_size = 50, tooltip = '!rl'}
self.createButton(buttonParam)
local buttonParam = {click_function = 'recFButtonFunc', label = "Record\nFas Win", color = {1,0,0,1}, font_color = stringColorToRGB('White'), function_owner = self,
position = {0.96,0.1,1.4}, rotation = {0,0,0}, width = 250, height = 200, font_size = 50, tooltip = '!rf'}
self.createButton(buttonParam)
local buttonParam = {click_function = 'adminMenu', label = "Admin", color = {1,1,1,1}, font_color = stringColorToRGB('Black'), function_owner = self,
position = {1.6,0.1,1.4}, rotation = {0,0,0}, width = 250, height = 200, font_size = 50}
self.createButton(buttonParam)
local name_size
for i = 1,10 do
if Player[COLOR_TABLE[i]].steam_name ~= nil and string.len(Player[COLOR_TABLE[i]].steam_name) > 10 then
name_size = 30
else
name_size = 50
end
local buttonParam = {click_function = 'nullFunc', label = Player[COLOR_TABLE[i]].steam_name, color = BUTT_B_COLOR, font_color = stringColorToRGB(COLOR_TABLE[i]), function_owner = self,
position = {COL[1],0.1,ROW[i+1]}, rotation = {0,0,0}, width = BUTT_W, height = BUTT_H, font_size = name_size}
self.createButton(buttonParam)
local buttonParam = {click_function = 'nullFunc', label = gamesPlayed[i], color = BUTT_B_COLOR, font_color = stringColorToRGB(COLOR_TABLE[i]), function_owner = self,
position = {COL[2],0.1,ROW[i+1]}, rotation = {0,0,0}, width = BUTT_W, height = BUTT_H, font_size = 50}
self.createButton(buttonParam)
local buttonParam = {click_function = 'nullFunc', label = fasWR[i], color = BUTT_B_COLOR, font_color = stringColorToRGB(COLOR_TABLE[i]), function_owner = self,
position = {COL[3],0.1,ROW[i+1]}, rotation = {0,0,0}, width = BUTT_W, height = BUTT_H, font_size = 50}
self.createButton(buttonParam)
local buttonParam = {click_function = 'nullFunc', label = hitWR[i], color = BUTT_B_COLOR, font_color = stringColorToRGB(COLOR_TABLE[i]), function_owner = self,
position = {COL[4],0.1,ROW[i+1]}, rotation = {0,0,0}, width = BUTT_W, height = BUTT_H, font_size = 50}
self.createButton(buttonParam)
local buttonParam = {click_function = 'nullFunc', label = fhWR[i], color = BUTT_B_COLOR, font_color = stringColorToRGB(COLOR_TABLE[i]), function_owner = self,
position = {COL[5],0.1,ROW[i+1]}, rotation = {0,0,0}, width = BUTT_W, height = BUTT_H, font_size = 50}
self.createButton(buttonParam)
local buttonParam = {click_function = 'nullFunc', label = libWR[i], color = BUTT_B_COLOR, font_color = stringColorToRGB(COLOR_TABLE[i]), function_owner = self,
position = {COL[6],0.1,ROW[i+1]}, rotation = {0,0,0}, width = BUTT_W, height = BUTT_H, font_size = 50}
self.createButton(buttonParam)
local buttonParam = {click_function = 'nullFunc', label = totWR[i], color = BUTT_B_COLOR, font_color = stringColorToRGB(COLOR_TABLE[i]), function_owner = self,
position = {COL[7],0.1,ROW[i+1]}, rotation = {0,0,0}, width = BUTT_W, height = BUTT_H, font_size = 50}
self.createButton(buttonParam)
end
end
function miscMenu()
startLuaCoroutine(self, 'refreshFunc')
self.clearButtons()
self.clearInputs()
state = 1
local name_size
namesDisp = {}
gamesDisp = {}
ratesDisp = {}
local buttonParam = {click_function = 'nullFunc', label = "Name", color = BUTT_B_COLOR, font_color = stringColorToRGB('White'), function_owner = self,
position = {COL[1],0.1,ROW[1]}, rotation = {0,0,0}, width = BUTT_W, height = BUTT_H, font_size = 80}
self.createButton(buttonParam)
local buttonParam = {click_function = 'nullFunc', label = "Liberal\nRating", color = BUTT_B_COLOR, font_color = stringColorToRGB('White'), function_owner = self,
position = {COL[2],0.1,ROW[1]}, rotation = {0,0,0}, width = BUTT_W, height = BUTT_H, font_size = 50}
self.createButton(buttonParam)
local buttonParam = {click_function = 'nullFunc', label = "Fascist\nRating", color = BUTT_B_COLOR, font_color = stringColorToRGB('White'), function_owner = self,
position = {COL[3],0.1,ROW[1]}, rotation = {0,0,0}, width = BUTT_W, height = BUTT_H, font_size = 50}
self.createButton(buttonParam)
local buttonParam = {click_function = 'nullFunc', label = "Gamble\nAttempts", color = BUTT_B_COLOR, font_color = stringColorToRGB('White'), function_owner = self,
position = {COL[4],0.1,ROW[1]}, rotation = {0,0,0}, width = BUTT_W, height = BUTT_H, font_size = 50}
self.createButton(buttonParam)
local buttonParam = {click_function = 'nullFunc', label = "Gamble\nSuccess", color = BUTT_B_COLOR, font_color = stringColorToRGB('White'), function_owner = self,
position = {COL[5],0.1,ROW[1]}, rotation = {0,0,0}, width = BUTT_W, height = BUTT_H, font_size = 50}
self.createButton(buttonParam)
local buttonParam = {click_function = 'nullFunc', label = "Total Games\nRecorded", color = BUTT_B_COLOR, font_color = stringColorToRGB('Green'), function_owner = self,
position = {COL[7],0.1,ROW[1]}, rotation = {0,0,0}, width = BUTT_W, height = BUTT_H, font_size = 50}
self.createButton(buttonParam)
local buttonParam = {click_function = 'nullFunc', label = lWins+fWins, color = BUTT_B_COLOR, font_color = stringColorToRGB('Green'), function_owner = self,
position = {COL[7],0.1,ROW[2]}, rotation = {0,0,0}, width = BUTT_W, height = BUTT_H, font_size = 100}
self.createButton(buttonParam)
local buttonParam = {click_function = 'nullFunc', label = "Fascist\nWinrate", color = BUTT_B_COLOR, font_color = stringColorToRGB('Green'), function_owner = self,
position = {COL[7],0.1,ROW[4]}, rotation = {0,0,0}, width = BUTT_W, height = BUTT_H, font_size = 50}
self.createButton(buttonParam)
local buttonParam = {click_function = 'nullFunc', label = round(fWins/(lWins+fWins)*100).."%", color = BUTT_B_COLOR, font_color = stringColorToRGB('Green'), function_owner = self,
position = {COL[7],0.1,ROW[5]}, rotation = {0,0,0}, width = BUTT_W, height = BUTT_H, font_size = 100}
self.createButton(buttonParam)
for i = 1,10 do
if Player[COLOR_TABLE[i]].steam_name ~= nil and string.len(Player[COLOR_TABLE[i]].steam_name) > 10 then
name_size = 30
else