-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFFAPI.lua
More file actions
989 lines (883 loc) · 38.1 KB
/
FFAPI.lua
File metadata and controls
989 lines (883 loc) · 38.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
--[[
This module handles collecting all of the actual game data and exposing it for use in other scripts.
This file contains the following features:
* Advanced data collection for every play
* Bindable Events for almost all possible events in the game
* Old and Current Values for almost any value exposed by the game
* A list of each team's drives, and each play in that drive
* Player Stats Collection (everything returned by the normal stats menu)
Created by Supermrk (@supermrk)
]]
local Services = {
Storage = game:GetService("ReplicatedStorage"),
HTTP = game:GetService("HttpService"),
Players = game:GetService("Players")
}
-----------------------------------------------------------------------
-- Script API Declarations
-----------------------------------------------------------------------
local request = request or (syn and syn.request) or (http and http.request) or http_request
-----------------------------------------------------------------------
-- Final
-----------------------------------------------------------------------
local FFValues = Services["Storage"].Values
local LocalPlayer = Services["Players"].LocalPlayer
-----------------------------------------------------------------------
-- Static
-----------------------------------------------------------------------
local module = {
Settings = {
GameID = nil,
AwayTeam = {Abbreviation = "VOID",Name = "NONE",City = "NONE"},
AwayRank = 0,
HomeTeam = {Abbreviation = "VOID",Name = "NONE",City = "NONE"},
HomeRank = 0,
LastPlayID = 0,
LastDriveID = 1,
SwitchedPossession = false
},
Values = {
AwayScore = FFValues.AwayScore.Value,
AwayInfo = {
DRIVE = 1,
DRIVE_PLAYS = {},
PASS = 0,
RUSH = 0,
TOP = 0,
TURN = 0,
TURN_ON_DOWNS = 0,
WIN = 50
},
HomeScore = FFValues.HomeScore.Value,
HomeInfo = {
DRIVE = 1,
DRIVE_PLAYS = {},
PASS = 0,
RUSH = 0,
TOP = 0,
TURN = 0,
TURN_ON_DOWNS = 0,
WIN = 50
},
CurrentDrive = {
PLAYS = 0,
TOP = 0,
YARDS = 0
},
PlayerStats = {},
AwayTimeouts = FFValues.AwayTos.Value,
HomeTimeouts = FFValues.HomeTos.Value,
PlayClock = FFValues.Playclock.Value,
Quarter = FFValues.Quarter.Value,
Clock = FFValues.TimerTag.Value,
Status = FFValues.StatusTag.Value,
Possession = true -- True == Home
},
OldValues = {
AwayScore = FFValues.AwayScore.Value,
AwayScoredReason = 5,
HomeScore = FFValues.HomeScore.Value,
HomeScoredReason = 5,
AwayTimeouts = FFValues.AwayTos.Value,
HomeTimeouts = FFValues.HomeTos.Value,
PlayClock = FFValues.Playclock.Value,
Quarter = FFValues.Quarter.Value,
Clock = FFValues.TimerTag.Value,
Status = FFValues.StatusTag.Value,
Possession = true
},
Events = {
AwayScored = Instance.new("BindableEvent"),
HomeScored = Instance.new("BindableEvent"),
AwayTimeoutChange = Instance.new("BindableEvent"),
HomeTimeoutChange = Instance.new("BindableEvent"),
PlayClockTick = Instance.new("BindableEvent"),
QuarterChange = Instance.new("BindableEvent"),
ClockTick = Instance.new("BindableEvent"),
StatusChange = Instance.new("BindableEvent"),
Safety = Instance.new("BindableEvent"),
Touchdown = Instance.new("BindableEvent"),
FieldGoal = Instance.new("BindableEvent"),
ExtraPoint = Instance.new("BindableEvent"),
TwoPoint = Instance.new("BindableEvent"),
KickMissed = Instance.new("BindableEvent"),
BallThrown = Instance.new("BindableEvent"),
BallCaught = Instance.new("BindableEvent"),
PrePlayEvent = Instance.new("BindableEvent"),
InPlayEvent = Instance.new("BindableEvent"),
AfterPlayEvent = Instance.new("BindableEvent"),
PlayFinishedEvent = Instance.new("BindableEvent"),
PlayerStatsUpdated = Instance.new("BindableEvent"),
GameEndEvent = Instance.new("BindableEvent")
},
LastEvents = {
AwayScored = tick(),
HomeScored = tick(),
AwayTimeoutChange = tick(),
HomeTimeoutChange = tick(),
PlayClockTick = tick(),
QuarterChange = tick(),
ClockTick = tick(),
StatusChange = tick(),
Safety = tick(),
Touchdown = tick(),
FieldGoal = tick(),
ExtraPoint = tick(),
TwoPoint = tick(),
KickMissed = tick(),
BallThrown = tick(),
BallCaught = tick(),
PrePlayEvent = tick(),
InPlayEvent = tick(),
AfterPlayEvent = tick(),
PlayFinishedEvent = tick(),
PlayerStatsUpdated = tick(),
GameEndEvent = tick()
},
Enums = {
ScoreType = {
EXTRA_POINT = 0,
TWO_POINT = 1,
SAFETY = 2,
FIELD_GOAL = 3,
TOUCHDOWN = 4,
OTHER = 5
},
Location = {
LEFT = "LEFT",
MIDDLE = "MIDDLE",
RIGHT = "RIGHT"
},
PassResult = {
COMPLETE = "complete",
INCOMPLETE = "incomplete",
INTERCEPTION = "interception"
},
FieldGoalResult = {
COMPLETE = "good",
INCOMPLETE = "no good"
}
}
}
local CURRENT_PLAY_INFO = {
play_id = module.Settings.LastPlayID+1,
play_start_time = 0,
play_end_time = 0,
game_id = module.Settings.GameID,
home_team = module.Settings.HomeTeam.Abbreviation,
away_team = module.Settings.AwayTeam.Abbreviation,
pos_team = "",
pos_win = 50,
side_of_field = "",
yardline_100 = 0,
clock = FFValues.TimerTag.Value,
quarter = FFValues.Quarter.Value,
drive = 0,
down = 0,
yards_to_go = 0,
desc = "",
play_maker_id = 0,
yards_gained = 0,
kickoff = false,
touchback = false,
turnover = false,
fumble = false,
safety = false,
qb = 3292436585,
qb_run = false,
qb_pass = false,
pass_location = "",
pass_result = "",
run_location = "",
field_goal_result = "",
kick_distance = 0,
extra_point_result = "",
two_point_conv_result = "",
home_timeouts_remaining_before = FFValues.HomeTos.Value,
away_timeouts_remaining_before = FFValues.AwayTos.Value,
home_timeouts_remaining_after = 0,
away_timeouts_remaining_after = 0,
timeout = false,
timeout_team = "",
td_team = "",
home_before_score = FFValues.HomeScore.Value,
away_before_score = FFValues.AwayScore.Value,
home_after_score = 0,
away_after_score = 0,
first_down = false
}
-----------------------------------------------------------------------
-- Functions
-----------------------------------------------------------------------
function GetUserIDFromName(name : string)
for i,v in ipairs(Services["Players"]:GetPlayers()) do
if (v.Name == name) then
return v.UserId
end
end
end
function FormatClock(seconds : number)
local minutes = (seconds - seconds%60)/60
seconds = seconds-minutes*60
local zero = ""
if (seconds < 10) then
zero = "0"
end
return minutes .. ":" .. zero .. seconds
end
function GetWinPercentage(team : string)
local data
local isHome = FFValues.PossessionTag.Value == FFValues.Home.Value.Name
local yardsToGo = string.split(FFValues.StatusTag.Value, " & ")
local fieldPos = FFValues.YardTag.Value
local field = "team"
if (FFValues.ArrowUp.Value) then
fieldPos = fieldPos+50
field = "opp"
end
if (yardsToGo[2] and tonumber(yardsToGo[2])) then
yardsToGo = tonumber(yardsToGo[2])
else
yardsToGo = 1
end
local seconds = FFValues.TimerTag.Value
local minutes = (seconds - seconds%60)/60
seconds = seconds - minutes*60
if (isHome) then
local vegasLine = (module.Settings.HomeRank-module.Settings.AwayRank)/4
data = request({
Url = "https://www.pro-football-reference.com/boxscores/win_prob.cgi?request=1&score_differential=" .. FFValues.HomeScore.Value - FFValues.AwayScore.Value .. "&vegas_line=" .. vegasLine .. "&quarter=" .. FFValues.Quarter.Value .."&minutes=" .. minutes .. "&seconds=" .. seconds .. "&field=" .. field .. "&yds_from_goal=" .. fieldPos .."&yds_to_go=" .. yardsToGo,
})
else
local vegasLine = (module.Settings.AwayRank-module.Settings.HomeRank)/4
data = request({
Url = "https://www.pro-football-reference.com/boxscores/win_prob.cgi?request=1&score_differential=" .. FFValues.AwayScore.Value - FFValues.HomeScore.Value .. "&vegas_line=" .. vegasLine .. "&quarter=" .. FFValues.Quarter.Value .."&minutes=" .. minutes .. "&seconds=" .. seconds .. "&field=" .. field .. "&yds_from_goal=" .. fieldPos .."&yds_to_go=" .. yardsToGo
})
end
local win = module.Values.AwayInfo.WIN
if (isHome) then
win = module.Values.HomeInfo.WIN
end
if (data) then
pcall(function()
local split1 = string.split(data.Body, "<h3>Win Probability: ")[2]
local split2 = string.split(split1, "%</h3>")[1]
local split3 = string.split(split2,".")[1]
if (tonumber(split3)) then
win = tonumber(split3)
end
end)
end
local requestingHomeTeam = team == module.Settings.HomeTeam.Abbreviation
if (requestingHomeTeam) then
if (isHome) then
return win
else
return 100-win
end
else
if (isHome) then
return 100-win
else
return win
end
end
end
-----------------------------------------------------------------------
-- Listeners
-----------------------------------------------------------------------
Services["Storage"].Remotes.CharacterSoundEvent.OnClientEvent:Connect(function(category, categoryType, ...)
local args = {...}
if (category == "GuiScript") then
if not (categoryType == "Banner" or categoryType == "msg") then
return
end
else
return
end
if (categoryType == "msg") then
local message = args[1]
if (string.match(message, "yard gain")) then
local split = string.split(message, " yard gain")
if (tonumber(split[1])) then
CURRENT_PLAY_INFO.yards_gained = tonumber(split[1])
if (CURRENT_PLAY_INFO.qb_pass) then
CURRENT_PLAY_INFO.pass_length = tonumber(split[1])
CURRENT_PLAY_INFO.pass_result = module.Enums.PassResult.COMPLETE
end
end
elseif (string.match(message, "Yard Touchdown!")) then
local split = string.split(message, " Yard Touchdown!")
if (tonumber(split[1])) then
CURRENT_PLAY_INFO.yards_gained = tonumber(split[1])
if (CURRENT_PLAY_INFO.qb_pass) then
CURRENT_PLAY_INFO.pass_length = tonumber(split[1])
CURRENT_PLAY_INFO.pass_result = module.Enums.PassResult.COMPLETE
end
end
elseif (string.match(message, "yard loss")) then
local split = string.split(message, " yard loss")
if (tonumber(split[1])) then
CURRENT_PLAY_INFO.yards_gained = tonumber(split[1]) * -1
end
elseif (message == "INTERCEPTION") then
CURRENT_PLAY_INFO.pass_result = module.Enums.PassResult.INTERCEPTION
elseif (message == "Touchback") then
CURRENT_PLAY_INFO.touchback = true
elseif (message == "Turnover on downs") then
wait(0.5)
if (FFValues.PossessionTag.Value == FFValues.Away.Value.Name) then
module.Values.AwayInfo.TURN_ON_DOWNS = module.Values.AwayInfo.TURN_ON_DOWNS+1
else
module.Values.HomeInfo.TURN_ON_DOWNS = module.Values.HomeInfo.TURN_ON_DOWNS+1
end
elseif (message == "Incomplete") then
CURRENT_PLAY_INFO.pass_result = module.Enums.PassResult.INCOMPLETE
if (FFValues.Ball.Value) then
if (FFValues.Ball.Value.Position.X > 32) then
CURRENT_PLAY_INFO.pass_location = module.Enums.Location.LEFT
elseif (FFValues.Ball.Value.Position.X < -32) then
CURRENT_PLAY_INFO.pass_location = module.Enums.Location.RIGHT
else
CURRENT_PLAY_INFO.pass_location = module.Enums.Location.MIDDLE
end
end
elseif (message == "FUMBLE") then
CURRENT_PLAY_INFO.fumble = true
elseif (string.find(message,"have won!")) then
if (module.Values.AwayScore > module.Values.HomeScore) then
module.Events.GameEndEvent:Fire(false)
else
module.Events.GameEndEvent:Fire(true)
end
module.LastEvents.GameEndEvent = tick()
end
return
end
local team = args[2]
local text = args[1]
if (text == "T O U C H D O W N") then
if (team.Name == FFValues.Away.Value.Name) then
module.Events.Touchdown:Fire(false)
module.LastEvents.Touchdown = tick()
CURRENT_PLAY_INFO.td_team = module.Settings.AwayTeam.Abbreviation
else
module.Events.Touchdown:Fire(true)
module.LastEvents.Touchdown = tick()
CURRENT_PLAY_INFO.td_team = module.Settings.HomeTeam.Abbreviation
end
elseif (text == "S A F E T Y") then
if (team.Name == FFValues.Away.Value.Name) then
module.Events.Safety:Fire(false)
module.LastEvents.Safety = tick()
else
module.Events.Safety:Fire(true)
module.LastEvents.Safety = tick()
end
CURRENT_PLAY_INFO.safety = true
elseif (text == "I T ' S G O O D !") then
local type = 1
if (FFValues.Kicker.Value) then
local userId = GetUserIDFromName(FFValues.Kicker.Value.Name)
if (userId) then
CURRENT_PLAY_INFO.play_maker_id = userId
end
end
wait(0.25)
if (team.Name == FFValues.Away.Value.Name) then
if (module.Values.AwayScore - module.OldValues.AwayScore == 1) then
module.Events.ExtraPoint:Fire(false)
module.LastEvents.ExtraPoint = tick()
else
module.Events.FieldGoal:Fire(false)
module.LastEvents.FieldGoal = tick()
type = 3
end
else
if (module.Values.HomeScore - module.OldValues.HomeScore == 1) then
module.Events.ExtraPoint:Fire(true)
module.LastEvents.ExtraPoint = tick()
else
module.Events.FieldGoal:Fire(true)
module.LastEvents.FieldGoal = tick()
type = 3
end
end
if (type == 3) then
CURRENT_PLAY_INFO.field_goal_result = module.Enums.FieldGoalResult.COMPLETE
else
CURRENT_PLAY_INFO.extra_point_result = module.Enums.FieldGoalResult.INCOMPLETE
end
elseif (text == "2 - P T G O O D") then
if (team.Name == FFValues.Away.Value.Name) then
module.Events.TwoPoint:Fire(false)
module.LastEvents.TwoPoint = tick()
else
module.Events.TwoPoint:Fire(true)
module.LastEvents.TwoPoint = tick()
end
CURRENT_PLAY_INFO.two_point_conv_result = module.Enums.FieldGoalResult.COMPLETE
elseif (text == "N O G O O D") then
if (FFValues.Kicker.Value) then
local userId = GetUserIDFromName(FFValues.Kicker.Value.Name)
if (userId) then
CURRENT_PLAY_INFO.play_maker_id = userId
end
end
if (team.Name == FFValues.Away.Value.Name) then
module.Events.KickMissed:Fire(false)
module.LastEvents.KickMissed = tick()
else
module.Events.KickMissed:Fire(true)
module.LastEvents.KickMissed = tick()
end
end
end)
FFValues.Status.Changed:Connect(function(value)
if (value == "PrePlay") then
module.Events.PrePlayEvent:Fire()
module.LastEvents.PrePlayEvent = tick()
print("[FF-API] PrePlay is starting.")
CURRENT_PLAY_INFO = {
play_id = module.Settings.LastPlayID+1,
play_start_time = 0,
play_end_time = 0,
game_id = module.Settings.GameID,
home_team = module.Settings.HomeTeam.Abbreviation,
away_team = module.Settings.AwayTeam.Abbreviation,
pos_team = "",
pos_win = 50,
side_of_field = "",
yardline_100 = 0,
clock = FFValues.TimerTag.Value,
quarter = FFValues.Quarter.Value,
drive = 0,
down = 0,
yards_to_go = 0,
desc = "", --
play_maker_id = 0,
yards_gained = 0,
kickoff = false,
touchback = false,
turnover = false,
fumble = false,
safety = false,
qb = 3292436585,
qb_run = false,
qb_pass = false,
pass_location = "",
pass_result = "",
run_location = "",
field_goal_result = "",
kick_distance = 0,
extra_point_result = "",
two_point_conv_result = "",
home_timeouts_remaining_before = FFValues.HomeTos.Value,
away_timeouts_remaining_before = FFValues.AwayTos.Value,
home_timeouts_remaining_after = 0,
away_timeouts_remaining_after = 0,
timeout = false,
timeout_team = "",
td_team = "",
home_before_score = FFValues.HomeScore.Value,
away_before_score = FFValues.AwayScore.Value,
home_after_score = 0,
away_after_score = 0,
first_down = false
}
if (FFValues.PossessionTag.Value == FFValues.Away.Value.Name) then
CURRENT_PLAY_INFO.pos_team = module.Settings.AwayTeam.Abbreviation
CURRENT_PLAY_INFO.pos_win = module.Values.AwayInfo.WIN
CURRENT_PLAY_INFO.drive = module.Settings.LastDriveID
if (FFValues.ArrowUp.Value) then
CURRENT_PLAY_INFO.side_of_field = module.Settings.AwayTeam.Abbreviation
CURRENT_PLAY_INFO.yardline_100 = FFValues.YardTag.Value
else
CURRENT_PLAY_INFO.side_of_field = module.Settings.HomeTeam.Abbreviation
CURRENT_PLAY_INFO.yardline_100 = FFValues.YardTag.Value+50
end
else
CURRENT_PLAY_INFO.pos_team = module.Settings.HomeTeam.Abbreviation
CURRENT_PLAY_INFO.pos_win = module.Values.HomeInfo.WIN
CURRENT_PLAY_INFO.drive = module.Settings.LastDriveID
if (FFValues.ArrowUp.Value) then
CURRENT_PLAY_INFO.side_of_field = module.Settings.HomeTeam.Abbreviation
CURRENT_PLAY_INFO.yardline_100 = FFValues.YardTag.Value
else
CURRENT_PLAY_INFO.side_of_field = module.Settings.AwayTeam.Abbreviation
CURRENT_PLAY_INFO.yardline_100 = FFValues.YardTag.Value+50
end
end
module.Settings.LastPlayID = module.Settings.LastPlayID+1
local status = string.split(FFValues.StatusTag.Value, " & ")
if (status[1] and status[2]) then
status[1] = string.sub(status[1],1,1)
if (tonumber(status[1])) then
CURRENT_PLAY_INFO.down = tonumber(status[1])
end
if (tonumber(status[2])) then
CURRENT_PLAY_INFO.yards_to_go = tonumber(status[2])
else
CURRENT_PLAY_INFO.yards_to_go = 1
end
end
if (FFValues.PlayType.Value == "fieldgoal") then
CURRENT_PLAY_INFO.kick_distance = FFValues.YardTag.Value+17
if (FFValues.StatusTag.Value == "PAT") then
CURRENT_PLAY_INFO.extra_point_result = module.Enums.FieldGoalResult.INCOMPLETE
else
CURRENT_PLAY_INFO.field_goal_result = module.Enums.FieldGoalResult.INCOMPLETE
end
elseif (FFValues.PlayType.Value == "kickoff") then
CURRENT_PLAY_INFO.kickoff = true
elseif (FFValues.PlayType.Value == "normal" and FFValues.StatusTag.Value == "PAT") then
CURRENT_PLAY_INFO.two_point_conv_result = module.Enums.FieldGoalResult.INCOMPLETE
end
local awayWinPercentage = GetWinPercentage(module.Settings.AwayTeam.Abbreviation)
module.Values.AwayInfo.WIN = awayWinPercentage
module.Values.HomeInfo.WIN = 100-awayWinPercentage
elseif (value == "InPlay") then
module.Events.InPlayEvent:Fire()
module.LastEvents.InPlayEvent = tick()
print("[FF-API] The play is now ongoing.")
CURRENT_PLAY_INFO.play_start_time = tick()
if (FFValues.Carrier.Value) then
local player = Services["Players"]:GetUserIdFromNameAsync(FFValues.Carrier.Value.Name)
CURRENT_PLAY_INFO.qb = player
end
if (module.Settings.SwitchedPossession) then
module.Settings.LastDriveID = module.Settings.LastDriveID+1
if (FFValues.PossessionTag.Value == FFValues.Away.Value.Name) then
module.Values.AwayInfo.DRIVE = module.Values.AwayInfo.DRIVE+1
CURRENT_PLAY_INFO.drive = module.Settings.LastDriveID
else
module.Values.HomeInfo.DRIVE = module.Values.HomeInfo.DRIVE+1
CURRENT_PLAY_INFO.drive = module.Settings.LastDriveID
end
module.Values.CurrentDrive.PLAYS = 0
module.Values.CurrentDrive.TOP = 0
module.Values.CurrentDrive.YARDS = 0
module.Settings.SwitchedPossession = false
end
elseif (value == "DeadPlay") then
module.Events.AfterPlayEvent:Fire()
module.LastEvents.AfterPlayEvent = tick()
print("[FF-API] The play has stopped.")
CURRENT_PLAY_INFO.play_end_time = tick()
wait(2.5)
local newPossessionTeam
if (FFValues.PossessionTag.Value == FFValues.Away.Value.Name) then
newPossessionTeam = module.Settings.AwayTeam.Abbreviation
else
newPossessionTeam = module.Settings.HomeTeam.Abbreviation
end
if not (CURRENT_PLAY_INFO.pos_team == newPossessionTeam) then
CURRENT_PLAY_INFO.turnover = true
module.Settings.SwitchedPossession = true
end
if (CURRENT_PLAY_INFO.yards_gained > CURRENT_PLAY_INFO.yards_to_go) then
CURRENT_PLAY_INFO.first_down = true
end
CURRENT_PLAY_INFO.home_timeouts_remaining_after = FFValues.HomeTos.Value
CURRENT_PLAY_INFO.away_timeouts_remaining_after = FFValues.AwayTos.Value
CURRENT_PLAY_INFO.home_after_score = FFValues.HomeScore.Value
CURRENT_PLAY_INFO.away_after_score = FFValues.AwayScore.Value
if (CURRENT_PLAY_INFO.pos_team == module.Settings.AwayTeam.Abbreviation) then
if not (module.Values.AwayInfo.DRIVE_PLAYS[module.Settings.LastDriveID]) then
module.Values.AwayInfo.DRIVE_PLAYS[module.Settings.LastDriveID] = {}
end
module.Values.AwayInfo.DRIVE_PLAYS[module.Settings.LastDriveID][module.Settings.LastPlayID] = CURRENT_PLAY_INFO
else
if not (module.Values.HomeInfo.DRIVE_PLAYS[module.Settings.LastDriveID]) then
module.Values.HomeInfo.DRIVE_PLAYS[module.Settings.LastDriveID] = {}
end
module.Values.HomeInfo.DRIVE_PLAYS[module.Settings.LastDriveID][module.Settings.LastPlayID] = CURRENT_PLAY_INFO
end
if (CURRENT_PLAY_INFO.qb_pass) then
local qb = Services["Players"]:GetNameFromUserIdAsync(CURRENT_PLAY_INFO.qb)
local wr = Services["Players"]:GetNameFromUserIdAsync(CURRENT_PLAY_INFO.play_maker_id)
if not (qb) then
qb = "Unknown"
end
if not (wr) then
wr = "Unknown"
end
local passLength = ""
if (CURRENT_PLAY_INFO.yards_gained >= 30) then
passLength = "deep "
elseif (CURRENT_PLAY_INFO.yards_gained <= 10) then
passLength = "short "
end
if (CURRENT_PLAY_INFO.pass_result == module.Enums.PassResult.COMPLETE) then
CURRENT_PLAY_INFO.desc = "(" .. FormatClock(CURRENT_PLAY_INFO.clock) .. ") " .. qb .. " pass " .. passLength .. string.lower(CURRENT_PLAY_INFO.pass_location) .. " to " .. wr .. " for " .. CURRENT_PLAY_INFO.yards_gained .. " yards."
elseif (CURRENT_PLAY_INFO.pass_result == module.Enums.PassResult.INCOMPLETE) then
CURRENT_PLAY_INFO.desc = "(" .. FormatClock(CURRENT_PLAY_INFO.clock) .. ") " .. qb .. " pass incomplete " .. string.lower(CURRENT_PLAY_INFO.pass_location) .. "."
elseif (CURRENT_PLAY_INFO.pass_result == module.Enums.PassResult.INTERCEPTION) then
CURRENT_PLAY_INFO.desc = "(" .. FormatClock(CURRENT_PLAY_INFO.clock) .. ") " .. qb .. " pass " .. passLength .. string.lower(CURRENT_PLAY_INFO.pass_location) .. " INTERCEPTED by " .. wr .. "."
end
elseif (CURRENT_PLAY_INFO.qb_run) then
local succ,runner = pcall(function()
return Services["Players"]:GetNameFromUserIdAsync(CURRENT_PLAY_INFO.play_maker_id)
end)
if not (succ) then
runner = "Unknown"
end
CURRENT_PLAY_INFO.desc = "(" .. FormatClock(CURRENT_PLAY_INFO.clock) .. ") " .. runner .. (CURRENT_PLAY_INFO.yards_gained <= 0 and " run " or " run up the ") .. string.lower(CURRENT_PLAY_INFO.run_location) .. " for " .. (CURRENT_PLAY_INFO.yards_gained <= 0 and "a loss of " or "") .. math.abs(CURRENT_PLAY_INFO.yards_gained) .. " yards."
elseif not (CURRENT_PLAY_INFO.field_goal_result == "") then
local succ,kicker = pcall(function()
return Services["Players"]:GetNameFromUserIdAsync(CURRENT_PLAY_INFO.play_maker_id)
end)
if not (succ or kicker) then
kicker = "Unknown"
end
CURRENT_PLAY_INFO.desc = "(" .. FormatClock(CURRENT_PLAY_INFO.clock) .. ") " .. kicker .. " " .. CURRENT_PLAY_INFO.kick_distance .. " yards field goal is " .. string.upper(CURRENT_PLAY_INFO.field_goal_result) .. "."
elseif not (CURRENT_PLAY_INFO.extra_point_result == "") then
local succ, kicker = pcall(function()
return Services["Players"]:GetNameFromUserIdAsync(CURRENT_PLAY_INFO.play_maker_id)
end)
if not (succ) then
kicker = "Unknown"
end
CURRENT_PLAY_INFO.desc = "(" .. FormatClock(CURRENT_PLAY_INFO.clock) .. ") " .. kicker .. " extra point is " .. string.upper(CURRENT_PLAY_INFO.extra_point_result) .. "."
elseif (CURRENT_PLAY_INFO.kickoff) then
CURRENT_PLAY_INFO.desc = "(" .. FormatClock(CURRENT_PLAY_INFO.clock) .. ") " .. CURRENT_PLAY_INFO.pos_team .. " punts returned for " .. CURRENT_PLAY_INFO.yards_gained+25 .. " yards."
end
if (CURRENT_PLAY_INFO.pos_team == module.Settings.AwayTeam.Abbreviation) then
if (CURRENT_PLAY_INFO.away_after_score-CURRENT_PLAY_INFO.away_before_score == 6) then
CURRENT_PLAY_INFO.desc = CURRENT_PLAY_INFO.desc .. " TOUCHDOWN."
elseif (CURRENT_PLAY_INFO.home_after_score-CURRENT_PLAY_INFO.home_before_score == 6) then
CURRENT_PLAY_INFO.desc = CURRENT_PLAY_INFO.desc .. " OPPOSING TOUCHDOWN."
end
else
if (CURRENT_PLAY_INFO.home_after_score-CURRENT_PLAY_INFO.home_before_score == 6) then
CURRENT_PLAY_INFO.desc = CURRENT_PLAY_INFO.desc .. " TOUCHDOWN."
elseif (CURRENT_PLAY_INFO.away_after_score-CURRENT_PLAY_INFO.away_before_score == 6) then
CURRENT_PLAY_INFO.desc = CURRENT_PLAY_INFO.desc .. " OPPOSING TOUCHDOWN."
end
end
if not (CURRENT_PLAY_INFO.desc == "") then
if (CURRENT_PLAY_INFO.touchback) then
CURRENT_PLAY_INFO.desc = CURRENT_PLAY_INFO.desc .. " Touchback."
end
if (CURRENT_PLAY_INFO.timeout) then
CURRENT_PLAY_INFO.desc = CURRENT_PLAY_INFO.desc .. " Timeout called by " .. CURRENT_PLAY_INFO.timeout_team .. "."
end
if (CURRENT_PLAY_INFO.yards_gained < CURRENT_PLAY_INFO.yards_to_go and CURRENT_PLAY_INFO.down == 4 and not CURRENT_PLAY_INFO.kickoff) then
CURRENT_PLAY_INFO.desc = CURRENT_PLAY_INFO.desc .. " TURNOVER on downs."
elseif (CURRENT_PLAY_INFO.turnover) then
CURRENT_PLAY_INFO.desc = CURRENT_PLAY_INFO.desc .. " TURNOVER."
end
if (CURRENT_PLAY_INFO.fumble) then
local otherTeam = CURRENT_PLAY_INFO.pos_team
if (CURRENT_PLAY_INFO.turnover) then
if (module.Settings.AwayTeam.Abbreviation == otherTeam) then
otherTeam = module.Settings.HomeTeam.Abbreviation
else
otherTeam = module.Settings.AwayTeam.Abbreviation
end
end
CURRENT_PLAY_INFO.desc = CURRENT_PLAY_INFO.desc .. " FUMBLES (" .. CURRENT_PLAY_INFO.pos_team .. ")" .. " RECOVERED by " .. otherTeam .. ". Gain of " .. CURRENT_PLAY_INFO.yards_gained .. " yards."
end
if (CURRENT_PLAY_INFO.safety) then
CURRENT_PLAY_INFO.desc = CURRENT_PLAY_INFO.desc .. " SAFETY."
end
if not (CURRENT_PLAY_INFO.two_point_conv_result == "") then
CURRENT_PLAY_INFO.desc = "TWO-POINT CONVERSION ATTEMPT. " .. CURRENT_PLAY_INFO.desc .. " ATTEMPT " .. string.upper(CURRENT_PLAY_INFO.two_point_conv_result) .. "."
end
end
module.Events.PlayFinishedEvent:Fire(CURRENT_PLAY_INFO)
if not (CURRENT_PLAY_INFO.kickoff) then
module.Values.CurrentDrive.PLAYS = module.Values.CurrentDrive.PLAYS+1
module.Values.CurrentDrive.YARDS = module.Values.CurrentDrive.YARDS+CURRENT_PLAY_INFO.yards_gained
end
end
end)
FFValues.Throwable.Changed:Connect(function(value)
if not (value) then
wait(0.5)
if not (FFValues.Thrown.Value) then
CURRENT_PLAY_INFO.qb_run = true
if (FFValues.QB.Value) then
local userId = GetUserIDFromName(FFValues.QB.Value.Name)
if (userId) then
CURRENT_PLAY_INFO.play_maker_id = userId
end
if (FFValues.QB.Value.Character.PrimaryPart.Position.X > 32) then
CURRENT_PLAY_INFO.run_location = module.Enums.Location.LEFT
elseif (FFValues.QB.Value.Character.PrimaryPart.Position.X < -32) then
CURRENT_PLAY_INFO.run_location = module.Enums.Location.RIGHT
else
CURRENT_PLAY_INFO.run_location = module.Enums.Location.MIDDLE
end
end
end
end
end)
FFValues.Thrown.Changed:Connect(function(value)
if (value) then
module.Events.BallThrown:Fire()
module.LastEvents.BallThrown = tick()
CURRENT_PLAY_INFO.qb_pass = true
CURRENT_PLAY_INFO.pass_result = module.Enums.PassResult.INCOMPLETE
end
end)
FFValues.Carrier.Changed:Connect(function(value)
if not (FFValues.Status.Value == "InPlay" or FFValues.Thrown.Value or value ~= nil) then
return
end
if not (value) then
return
end
if not (value.UserId) then
return
end
local userId = value.UserId
module.Events.BallCaught:Fire(userId)
module.LastEvents.BallCaught = tick()
CURRENT_PLAY_INFO.play_maker_id = userId
if (value.Character.PrimaryPart.Position.X > 32) then
CURRENT_PLAY_INFO.pass_location = module.Enums.Location.LEFT
elseif (value.Character.PrimaryPart.Position.X < -32) then
CURRENT_PLAY_INFO.pass_location = module.Enums.Location.RIGHT
else
CURRENT_PLAY_INFO.pass_location = module.Enums.Location.MIDDLE
end
end)
FFValues.AwayScore.Changed:Connect(function(new)
local reason = module.Enums.ScoreType.OTHER
wait(0.5)
if (tick() - module.LastEvents.Safety < 1) then
reason = module.Enums.ScoreType.SAFETY
elseif (tick() - module.LastEvents.Touchdown < 1) then
reason = module.Enums.ScoreType.TOUCHDOWN
elseif (tick() - module.LastEvents.FieldGoal < 1) then
reason = module.Enums.ScoreType.FIELD_GOAL
elseif (tick() - module.LastEvents.ExtraPoint < 1) then
reason = module.Enums.ScoreType.EXTRA_POINT
elseif (tick() - module.LastEvents.TwoPoint < 1) then
reason = module.Enums.ScoreType.TWO_POINT
end
module.Events.AwayScored:Fire(new,module.Values.AwayScore, reason)
module.OldValues.AwayScore = module.Values.AwayScore
module.OldValues.AwayScoredReason = reason
module.Values.AwayScore = new
end)
FFValues.HomeScore.Changed:Connect(function(new)
local reason = module.Enums.ScoreType.OTHER
wait(0.5)
if (tick() - module.LastEvents.Safety < 1) then
reason = module.Enums.ScoreType.SAFETY
elseif (tick() - module.LastEvents.Touchdown < 1) then
reason = module.Enums.ScoreType.TOUCHDOWN
elseif (tick() - module.LastEvents.FieldGoal < 1) then
reason = module.Enums.ScoreType.FIELD_GOAL
elseif (tick() - module.LastEvents.ExtraPoint < 1) then
reason = module.Enums.ScoreType.EXTRA_POINT
elseif (tick() - module.LastEvents.TwoPoint < 1) then
reason = module.Enums.ScoreType.TWO_POINT
end
module.Events.HomeScored:Fire(new,module.Values.HomeScore, reason)
module.OldValues.HomeScore = module.Values.HomeScore
module.OldValues.HomeScoredReason = reason
module.Values.HomeScore = new
end)
FFValues.AwayTos.Changed:Connect(function(new)
module.Events.AwayTimeoutChange:Fire(new, module.Values.AwayTimeouts)
module.OldValues.AwayTimeouts = module.Values.AwayTimeouts
module.Values.AwayTimeouts = new
if (module.OldValues.AwayTimeouts - new == 1) then
CURRENT_PLAY_INFO.timeout = true
CURRENT_PLAY_INFO.timeout_team = module.Settings.AwayTeam.Abbreviation
end
end)
FFValues.HomeTos.Changed:Connect(function(new)
module.Events.HomeTimeoutChange:Fire(new, module.Values.HomeTimeouts)
module.OldValues.HomeTimeouts = module.Values.HomeTimeouts
module.Values.HomeTimeouts = new
if (module.OldValues.HomeTimeouts - new == 1) then
CURRENT_PLAY_INFO.timeout = true
CURRENT_PLAY_INFO.timeout_team = module.Settings.HomeTeam.Abbreviation
end
end)
FFValues.Playclock.Changed:Connect(function(new)
module.Events.PlayClockTick:Fire(new, module.Values.PlayClock)
module.OldValues.PlayClock = module.Values.PlayClock
module.Values.PlayClock = new
end)
FFValues.Quarter.Changed:Connect(function(new)
module.Events.QuarterChange:Fire(new, module.Values.Quarter)
module.OldValues.Quarter = module.Values.Quarter
module.Values.Quarter = new
end)
FFValues.TimerTag.Changed:Connect(function(new)
module.Events.ClockTick:Fire(new, module.Values.Clock)
module.OldValues.Clock = module.Values.Clock
module.Values.Clock = new
if (FFValues.PossessionTag.Value == FFValues.Away.Value.Name) then
module.Values.AwayInfo.TOP = module.Values.AwayInfo.TOP+1
else
module.Values.HomeInfo.TOP = module.Values.HomeInfo.TOP+1
end
module.Values.CurrentDrive.TOP = module.Values.CurrentDrive.TOP+1
end)
FFValues.StatusTag.Changed:Connect(function(new)
module.Events.StatusChange:Fire(new, module.Values.Status)
module.OldValues.Status = module.Values.Status
module.Values.Status = new
end)
FFValues.PossessionTag.Changed:Connect(function(new)
if (new == FFValues.Away.Value.Name) then
module.Values.Possession = false
else
module.Values.Possession = true
end
module.Values.CurrentDrive.PLAYS = 0
module.Values.CurrentDrive.TOP = 0
module.Values.CurrentDrive.YARDS = 0
end)
-----------------------------------------------------------------------
-- Stats Loop
-----------------------------------------------------------------------
task.spawn(function()
while(wait(10)) do
print("[FF-API] Collecting player stats.")
local playerStats = Services["Storage"].Remotes.StatsTransfer:InvokeServer("game","avg")
module.Values.PlayerStats = playerStats
module.Events.PlayerStatsUpdated:Fire(playerStats)
module.LastEvents.PlayerStatsUpdated = tick()
module.Values.HomeInfo.PASS = 0
module.Values.HomeInfo.RUSH = 0
module.Values.HomeInfo.TURN = 0
module.Values.AwayInfo.PASS = 0
module.Values.AwayInfo.RUSH = 0
module.Values.AwayInfo.TURN = 0
for _,player in ipairs(Services["Players"]:GetPlayers()) do
if not (playerStats[tostring(player.UserId)]) then
continue
end
local isHome = false
if not (player.Team) then
continue
end
if (player.Team.Name == FFValues.Home.Value.Name) then
isHome = true
end
local playersStats = playerStats[tostring(player.UserId)]
-- for _,test in playersStats do
-- for name2,test2 in test do
-- print(name2, test2)
-- end
-- end
if (isHome) then
module.Values.HomeInfo.PASS = module.Values.HomeInfo.PASS+playersStats["qb"]["yds"]
module.Values.HomeInfo.RUSH = module.Values.HomeInfo.RUSH+playersStats["rb"]["yds"]
module.Values.HomeInfo.TURN = module.Values.HomeInfo.TURN+playersStats["qb"]["int"]+playersStats["def"]["rec"]
else
module.Values.AwayInfo.PASS = module.Values.AwayInfo.PASS+playersStats["qb"]["yds"]
module.Values.AwayInfo.RUSH = module.Values.AwayInfo.RUSH+playersStats["rb"]["yds"]
module.Values.AwayInfo.TURN = module.Values.AwayInfo.TURN+playersStats["qb"]["int"]+playersStats["def"]["rec"]
end
end
end
end)
return module