-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.lua
More file actions
1790 lines (1540 loc) · 69.9 KB
/
main.lua
File metadata and controls
1790 lines (1540 loc) · 69.9 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
-- name: \\#316BE8\\Tag (v2.4)\\#dcdcdc\\
-- description: All Tag Related Gamemodes!\n\nThis mod contains Tag, Freeze Tag, Infection, Hot Potato, Juggernaut, Assassins, and more, with modifiers, and full romhack support!\n\nHave fun playing Tag!\n\nDeveloped by \\#a5ae8f\\EmeraldLockdown\\#dcdcdc\\\n\nSnippets of code taken from \\#f7b2f3\\EmilyEmmi\\#dcdcdc\\,\\#ff7f00\\ Agent X\\#dcdcdc\\, Sunk, and \\#F2F3AE\\B\\#EDD382\\l\\#FC9E4F\\o\\#F4442E\\c\\#9B1D20\\ky\n\n\\#dcdcdc\\Painting textures taken from Shine Thief, by \\#f7b2f3\\EmilyEmmi\n\n\\#dcdcdc\\More credits can be found inside the mod.
-- incompatible: gamemode tag
-- if your trying to learn this code, I hope I've done a good job.
-- This file is pretty much (other than a-misc.lua) the most unorganized file of them all
-- threw so much crap in here that isn't even apart of the actual game loop or anything
-- anyways other than that, everything should be good, so
-- wish you luck on your journey!
-- tag versions
versions = {
"v2.4",
"v2.32",
"v2.31",
"v2.3",
"v2.21",
"v2.2",
"v2.1",
"v2.0",
}
-- constants
-- round states
ROUND_WAIT_PLAYERS = 0
ROUND_ACTIVE = 1
ROUND_WAIT = 2
ROUND_TAGGERS_WIN = 3
ROUND_RUNNERS_WIN = 4
ROUND_TOURNAMENT_LEADERBOARD = 5
ROUND_HOT_POTATO_INTERMISSION = 6
ROUND_VOTING = 7
ROUND_SARDINE_HIDING = 8
-- roles (gamemode-specific roles specified in designated gamemode files, and replace the wildcard role)
RUNNER = 0
TAGGER = 1
WILDCARD_ROLE = 2
SPECTATOR = 3
-- gamemodes
MIN_GAMEMODE = 1
TAG = 1
FREEZE_TAG = 2
INFECTION = 3
HOT_POTATO = 4
JUGGERNAUT = 5
ASSASSINS = 6
SARDINES = 7
HUNT = 8
DEATHMATCH = 9
TERMINATOR = 10
ODDBALL = 11
ROYALE = 12
MAX_GAMEMODE = 12
-- spectator states
SPECTATOR_STATE_MARIO = 0
SPECTATOR_STATE_FREECAM = 1
SPECTATOR_STATE_FOLLOW = 2
-- modifiers
MODIFIER_MIN = 0
MODIFIER_NONE = 0
MODIFIER_BOMBS = 1
MODIFIER_LOW_GRAVITY = 2
MODIFIER_NO_RADAR = 3
MODIFIER_NO_BOOST = 4
MODIFIER_ONE_TAGGER = 5
MODIFIER_FOG = 6
MODIFIER_SPEED = 7
MODIFIER_INCOGNITO = 8
MODIFIER_HIGH_GRAVITY = 9
MODIFIER_FLY = 10
MODIFIER_BLASTER = 11
MODIFIER_ONE_RUNNER = 12
MODIFIER_DOUBLE_JUMP = 13
MODIFIER_SHELL = 14
MODIFIER_BLJS = 15
MODIFIER_FRIENDLY_FIRE = 16
MODIFIER_HARD_SURFACE = 17
MODIFIER_SAND = 18
MODIFIER_SWAP = 19
MODIFIER_Z_BUTTON_CHALLENGE = 20
MODIFIER_ONLY_FIRSTIES = 21
MODIFIER_MAX = 21
-- binds
BIND_BOOST = 0
BIND_BOMBS = 1
BIND_GUN = 2
BIND_DOUBLE_JUMP = 3
BIND_MAX = 3
-- boost states
BOOST_STATE_RECHARGING = 0
BOOST_STATE_READY = 1
BOOST_STATE_BOOSTING = 2
-- tournament point systems
TOURNAMENT_SYSTEM_MIN = 0
TOURNAMENT_SYSTEM_POINT_LIMIT = 0
TOURNAMENT_SYSTEM_ROUND_LIMIT = 1
TOURNAMENT_SYSTEM_MAX = 1
-- textures
TEXTURE_TAG_LOGO = get_texture_info("logo")
-- models
E_MODEL_BOOST_TRAIL = smlua_model_util_get_id("boost_trail_geo")
-- globals and sync tables
-- this is the round state, this variable tells you what current round it is
gGlobalSyncTable.roundState = ROUND_WAIT_PLAYERS
-- what the current gamemode is
gGlobalSyncTable.gamemode = TAG
-- this is the currently selected modifier. If random modifiers are off (as in you've selected
-- one manually) then MODIFIER_NONE = Disabled
gGlobalSyncTable.modifier = MODIFIER_NONE
-- dictates whether or not modifiers and gamemodes are random
gGlobalSyncTable.randomGamemode = true
gGlobalSyncTable.randomModifiers = true
-- toggles for bljs, cannons, and water
gGlobalSyncTable.bljs = false
gGlobalSyncTable.cannons = false
gGlobalSyncTable.water = false
-- display timer, used for all sorts of timers, timers from the top
-- of the screen, to timers in the vote menu
gGlobalSyncTable.displayTimer = 1
-- the current selected level. When romhacks are enabled, this is set to the actual level
-- number (i.e LEVEL_BOB), otherwise, it's set to the level in the levels table (found below here)
gGlobalSyncTable.selectedLevel = 1
-- max lives. Since this changes depending on player count, make it a global variable
gGlobalSyncTable.tagMaxLives = 15
-- amount of time left in a round
gGlobalSyncTable.amountOfTime = 120 * 30
-- ttc speed, because ttc syncing sucks
gGlobalSyncTable.ttcSpeed = 0
-- toggles elimination on death
gGlobalSyncTable.eliminateOnDeath = true
-- toggles late joining
gGlobalSyncTable.lateJoining = false
-- toggles vote level system
gGlobalSyncTable.doVoting = true
-- init gamemode vars
init_gamemode_settings()
-- auto mode
gGlobalSyncTable.autoMode = true
-- enable tagger boosts or not
gGlobalSyncTable.boosts = true
-- enable friendly fire or not
gGlobalSyncTable.friendlyFire = false
-- boost cooldown
gGlobalSyncTable.boostCooldown = 15 * 30
-- enable or disable hazardous surfaces
gGlobalSyncTable.hazardSurfaces = false
-- enable or disable pipes
gGlobalSyncTable.pipes = true
-- override for romhacks
gGlobalSyncTable.romhackOverride = nil
-- if we are in tournament mode or not
gGlobalSyncTable.tournamentMode = false
-- tournament point system
gGlobalSyncTable.tournamentPointSystem = TOURNAMENT_SYSTEM_POINT_LIMIT
-- current round number
gGlobalSyncTable.tournamentRound = 0
-- rounds needed to end a tournament
gGlobalSyncTable.tournamentRoundLimit = 5
-- points needed to win a tournament
gGlobalSyncTable.tournamentPointsReq = 50
-- swap timer
gGlobalSyncTable.swapTimer = 0
-- init modifier settings
init_modifier_settings()
-- blacklisted courses, gamemodes, and modifiers
gGlobalSyncTable.blacklistedCourses = {}
gGlobalSyncTable.blacklistedGamemodes = {}
for i = MIN_GAMEMODE, MAX_GAMEMODE do
gGlobalSyncTable.blacklistedGamemodes[i] = false
end
gGlobalSyncTable.blacklistedModifiers = {}
for i = MIN_GAMEMODE, MAX_GAMEMODE do
gGlobalSyncTable.blacklistedModifiers[i] = false
end
for i = 0, MAX_PLAYERS - 1 do -- set all states for every player on init if we are the server
if network_is_server() then
-- the player's role
gPlayerSyncTable[i].state = RUNNER
-- the player's invinc timer, I forgot why I use the player sync table, think for
-- syincing it or something, anyways that's what it is so
gPlayerSyncTable[i].invincTimer = 0
-- amount of tags a player has gotten, and the amount of time a runner has
-- been a runner, this is for the leaderboard, and adding stats
gPlayerSyncTable[i].amountOfTags = 0
gPlayerSyncTable[i].amountOfTimeAsRunner = 0
-- amount of tags till death (used for multiple gamemodes)
gPlayerSyncTable[i].tagLives = 0
-- the assassins's target
gPlayerSyncTable[i].assassinTarget = -1
-- what number you voted for in the level voting system
gPlayerSyncTable[i].votingNumber = 0
-- whether or not you're boosting
gPlayerSyncTable[i].boosting = false
-- spectator state
gPlayerSyncTable[i].spectatorState = SPECTATOR_STATE_MARIO
-- current title
gPlayerSyncTable[i].playerTitle = nil
-- current trail
gPlayerSyncTable[i].playerTrail = E_MODEL_BOOST_TRAIL
-- timer for oddball
gPlayerSyncTable[i].oddballTimer = 0
-- tournament points
gPlayerSyncTable[i].tournamentPoints = 0
end
end
-- server settings
gServerSettings.playerInteractions = PLAYER_INTERACTIONS_SOLID -- force player attacks to be on
gServerSettings.bubbleDeath = 0 -- just.... no
-- level values
gLevelValues.disableActs = true
-- levels
levels = {}
-- if we are using coopdx or not
usingCoopDX = get_coop_compatibility_enabled ~= nil
-- initialized mh api for chat stuff
_G.mhApi = {}
-- variables
-- this is the local server timer used to set gGlobalSyncTable.displayTimer and other variables
timer = 0
-- if we are a romhack or not (checked in check_mods function)
isRomhack = false
-- if nametags are enabled or not (checked in check_mods function)
nametagsEnabled = false
-- owner and developer vars
isOwner = false
isDeveloper = false
-- the previous level, used for when the server selects levels to pick
prevLevel = 1 -- make it the same as the selected level so it selects a new level
-- These are levels that are failed to be warped to for romhacks
badLevels = {}
-- the global sound source, used for audio
gGlobalSoundSource = { x = 0, y = 0, z = 0 }
-- if we are paused or not, for custom pause menu
isPaused = false
-- whether or not to use romhack cam
useRomhackCam = true
-- auto hide hud option
autoHideHud = true
-- auto hide hud always show timer option
autoHideHudAlwaysShowTimer = true
-- show titles or not
showTitles = true
-- amount of times the pipe has been used
pipeUse = 0
-- how long it has been since we last entered a pipe
pipeTimer = 0
-- binds
binds = {}
-- boost bind
binds[BIND_BOOST] = {name = "Boost", btn = Y_BUTTON}
-- bomb bind
binds[BIND_BOMBS] = {name = "Bombs", btn = Y_BUTTON}
-- gun bind
binds[BIND_GUN] = {name = "Blaster", btn = X_BUTTON}
-- double jump bind
binds[BIND_DOUBLE_JUMP] = {name = "Double Jump", btn = A_BUTTON}
-- stats
stats = {
globalStats = {
playTime = 0,
totalTags = 0,
totalTimeAsRunner = 0,
runnerVictories = 0,
taggerVictories = 0,
totalTournamentPoints = 0,
totalTournamentWins = 0,
},
[TAG] = {
playTime = 0,
totalTags = 0,
totalTimeAsRunner = 0,
runnerVictories = 0,
taggerVictories = 0,
},
[FREEZE_TAG] = {
playTime = 0,
totalTags = 0,
totalTimeAsRunner = 0,
runnerVictories = 0,
taggerVictories = 0,
},
[INFECTION] = {
playTime = 0,
totalTags = 0,
totalTimeAsRunner = 0,
runnerVictories = 0,
taggerVictories = 0,
},
[HOT_POTATO] = {
playTime = 0,
totalTags = 0,
totalTimeAsRunner = 0,
runnerVictories = 0,
taggerVictories = 0,
},
[JUGGERNAUT] = {
playTime = 0,
totalTags = 0,
totalTimeAsRunner = 0,
runnerVictories = 0,
taggerVictories = 0,
},
[ASSASSINS] = {
playTime = 0,
totalTags = 0,
taggerVictories = 0,
},
[SARDINES] = {
playTime = 0,
totalTags = 0,
totalTimeAsRunner = 0,
taggerVictories = 0,
},
[HUNT] = {
playTime = 0,
totalTags = 0,
totalTimeAsRunner = 0,
runnerVictories = 0,
taggerVictories = 0,
},
[DEATHMATCH] = {
playTime = 0,
totalTags = 0,
taggerVictories = 0,
},
[TERMINATOR] = {
playTime = 0,
totalTags = 0,
totalTimeAsRunner = 0,
runnerVictories = 0,
taggerVictories = 0,
},
[ODDBALL] = {
playTime = 0,
totalTags = 0,
totalTimeAsRunner = 0,
runnerVictories = 0,
},
[ROYALE] = {
playTime = 0,
totalTags = 0,
taggerVictories = 0,
},
}
remoteStats = {
playTime = 0,
totalTags = 0,
totalTimeAsRunner = 0,
runnerVictories = 0,
taggerVictories = 0,
}
playersNeeded = {
[TAG] = 2,
[FREEZE_TAG] = 3,
[INFECTION] = 3,
[HOT_POTATO] = 3,
[JUGGERNAUT] = 2,
[ASSASSINS] = 2,
[SARDINES] = 3,
[HUNT] = 2,
[DEATHMATCH] = 2,
[TERMINATOR] = 2,
[ODDBALL] = 2,
[ROYALE] = 2,
}
-- selected theme
selectedTheme = 1
-- speed boost timer
local speedBoostTimer = 0
-- boost state
local boostState = BOOST_STATE_RECHARGING
-- hot potato timer multiplier is when the timer
-- is faster if there's more people currently active
local hotPotatoTimerMultiplier = 1
-- hud fade
local hudFade = 255
-- previous romhack override
local prevRomhackOverride = nil
-- initialized save data
local initializedSaveData = false
-- room timer
local roomTimer = 0
-- water region values
local waterRegions = {}
-- just some global variables, honestly idk why the second one is there but it is so, uh, enjoy?
_G.tag = {}
-- just a action we can use, used for when the round ends and mario freezes
ACT_NOTHING = allocate_mario_action(ACT_FLAG_IDLE)
local function server_update()
-- set some basic sync table vars
for i = 0, MAX_PLAYERS - 1 do
if not gNetworkPlayers[i].connected then
gPlayerSyncTable[i].state = -1
gPlayerSyncTable[i].amountOfTimeAsRunner = 0
gPlayerSyncTable[i].amountOfTags = 0
gPlayerSyncTable[i].tagLives = 0
gPlayerSyncTable[i].tournamentPoints = 0
end
end
-- reset tournament rounds if tournaments are off
if not gGlobalSyncTable.tournamentMode then
gGlobalSyncTable.tournamentRound = 0
end
-- get number of players
local numPlayers = player_count_no_spectators()
if ((not gGlobalSyncTable.randomGamemode and numPlayers < playersNeeded[gGlobalSyncTable.gamemode])
or numPlayers < 2) and gGlobalSyncTable.roundState ~= ROUND_VOTING then
gGlobalSyncTable.roundState = ROUND_WAIT_PLAYERS -- set round state to waiting for players
elseif gGlobalSyncTable.roundState == ROUND_WAIT_PLAYERS then
-- if we aren't in auto mode, then don't run this code, and run designated code in the if statemnt
if not gGlobalSyncTable.autoMode then
if timer >= 16 * 30 then
for i = 0, MAX_PLAYERS - 1 do
if gPlayerSyncTable[i].state ~= SPECTATOR then
gPlayerSyncTable[i].state = RUNNER
end
end
end
goto ifend
end
timer = 15 * 30 -- 15 seconds
select_new_level()
log_to_console("Tag: Round State is now ROUND_WAIT")
::ifend::
end
if gGlobalSyncTable.roundState == ROUND_WAIT_PLAYERS then
-- force state to be runner, so long as they aren't a spectator, and we are in auto mode
for i = 0, MAX_PLAYERS - 1 do
if gPlayerSyncTable[i].state ~= SPECTATOR and gGlobalSyncTable.autoMode then
gPlayerSyncTable[i].state = RUNNER
end
end
-- set timer to 15 seconds to prevent state being set constantly
timer = 15 * 30
elseif gGlobalSyncTable.roundState == ROUND_WAIT then
-- select a modifier and gamemode if timer is at its highest point
if timer == 15 * 30 then
if gGlobalSyncTable.randomModifiers then
-- see if we should use a modifier modifiers or not
local selectModifier = math.random(1, 2) -- 50% chance
if selectModifier == 2 then
::selectmodifier::
-- select a random modifier
gGlobalSyncTable.modifier = math.random(MODIFIER_MIN + 1, MODIFIER_MAX) -- select random modifier, exclude MODIFIER_NONE
if (gGlobalSyncTable.gamemode == ASSASSINS
or gGlobalSyncTable.gamemode == SARDINES
or gGlobalSyncTable.gamemode == JUGGERNAUT)
and (gGlobalSyncTable.modifier == MODIFIER_ONE_TAGGER
or gGlobalSyncTable.modifier == MODIFIER_ONE_RUNNER) then
goto selectmodifier
end
if (levels[gGlobalSyncTable.selectedLevel].name == "ithi"
or levels[gGlobalSyncTable.selectedLevel].name == "lll"
or levels[gGlobalSyncTable.selectedLevel].name == "bitfs")
and not isRomhack
and gGlobalSyncTable.modifier == MODIFIER_FOG then
goto selectmodifier
end
if gGlobalSyncTable.blacklistedModifiers[gGlobalSyncTable.modifier] == true then
goto selectmodifier
end
else
gGlobalSyncTable.modifier = MODIFIER_NONE -- set the modifier to none
end
end
-- if we select a random gamemode, select that random gamemode now
if gGlobalSyncTable.randomGamemode then
-- check if we have all gamemodes blacklisted
local gamemodesBlacklisted = MIN_GAMEMODE - 1
for i = MIN_GAMEMODE, MAX_GAMEMODE do
if gGlobalSyncTable.blacklistedGamemodes[i] == true then
gamemodesBlacklisted = gamemodesBlacklisted + 1
end
end
-- if they all are, skip setting gamemode
if gamemodesBlacklisted == MAX_GAMEMODE then
goto amountoftime
end
::selectgamemode::
gGlobalSyncTable.gamemode = math.random(MIN_GAMEMODE, MAX_GAMEMODE)
if gGlobalSyncTable.blacklistedGamemodes[gGlobalSyncTable.gamemode] == true
or playersNeeded[gGlobalSyncTable.gamemode] > numPlayers then
goto selectgamemode
end
end
-- set the amount of time var and players needed var
::amountoftime::
gGlobalSyncTable.amountOfTime = gGlobalSyncTable.activeTimers[gGlobalSyncTable.gamemode]
log_to_console("Tag: Modifier is set to " .. strip_hex(get_modifier_text()) .. " and the gamemode is set to " .. strip_hex(get_gamemode(gGlobalSyncTable.gamemode)))
end
for i = 0, MAX_PLAYERS - 1 do
if gPlayerSyncTable[i].state ~= SPECTATOR and gGlobalSyncTable.autoMode then
gPlayerSyncTable[i].state = RUNNER -- set everyone's state to runner
end
local m = gMarioStates[0]
if m.action == ACT_NOTHING then
set_mario_action(m, ACT_IDLE, 0)
end
gPlayerSyncTable[i].tagLives = 0 -- reset tag lives
gPlayerSyncTable[i].assassinTarget = -1 -- reset assassin target
gPlayerSyncTable[i].amountOfTags = 0 -- reset amount of tags
gPlayerSyncTable[i].amountOfTimeAsRunner = 0 -- reset amount of time as runner
gPlayerSyncTable[i].oddballTimer = gGlobalSyncTable.activeTimers[ODDBALL] -- reset oddball timer
end
timer = timer - 1 -- subtract timer by one
gGlobalSyncTable.displayTimer = timer -- set display timer to timer
if timer <= 0 then
-- set the amount of time var and players needed var
gGlobalSyncTable.amountOfTime = gGlobalSyncTable.activeTimers[gGlobalSyncTable.gamemode]
timer = gGlobalSyncTable.amountOfTime -- set timer to amount of time in a round
-- set timer to hiding timer if we are in the gamemodes which require it
if gGlobalSyncTable.gamemode == SARDINES then timer = gGlobalSyncTable.hidingTimer[gGlobalSyncTable.gamemode] end
-- if we have custom roles, skip straight to actually starting the round
local skipTaggerSelection = false
for i = 0, MAX_PLAYERS - 1 do
if gNetworkPlayers[i].connected then
if gPlayerSyncTable[i].state == TAGGER then
skipTaggerSelection = true
end
end
end
local amountOfTaggersNeeded = math.floor(numPlayers / playersNeeded[gGlobalSyncTable.gamemode]) -- always have the amount of the players needed, rounding down, be taggers
-- set tag max lives for gamemodes like juggernaut, hunt, and deathmatch
gGlobalSyncTable.tagMaxLives = gGlobalSyncTable.maxLives[gGlobalSyncTable.gamemode]
for i = 0, MAX_PLAYERS - 1 do
gPlayerSyncTable[i].tagLives = gGlobalSyncTable.tagMaxLives
end
if not skipTaggerSelection then
if gGlobalSyncTable.modifier == MODIFIER_ONE_TAGGER
or gGlobalSyncTable.gamemode == TERMINATOR then
amountOfTaggersNeeded = 1
elseif gGlobalSyncTable.modifier == MODIFIER_ONE_RUNNER then
amountOfTaggersNeeded = numPlayers - 1
end
if gGlobalSyncTable.gamemode == JUGGERNAUT
or gGlobalSyncTable.gamemode == SARDINES
or gGlobalSyncTable.gamemode == ODDBALL then
amountOfTaggersNeeded = numPlayers - 1
end
log_to_console("Tag: Assigning Players")
local amountOfTaggers = 0
while amountOfTaggers < amountOfTaggersNeeded do
-- select taggers
local randomIndex = math.random(0, MAX_PLAYERS - 1) -- select random index
if gPlayerSyncTable[randomIndex].state ~= TAGGER and gPlayerSyncTable[randomIndex].state ~= SPECTATOR and gPlayerSyncTable[randomIndex].state ~= -1 and gNetworkPlayers[randomIndex].connected then
gPlayerSyncTable[randomIndex].state = TAGGER
log_to_console("Tag: Assigned " .. gNetworkPlayers[randomIndex].name .. " as " .. get_role_name(TAGGER))
amountOfTaggers = amountOfTaggers + 1
end
end
end
if gGlobalSyncTable.gamemode == HOT_POTATO then
-- get current amount of runners
local curRunnerCount = 0
for i = 0, MAX_PLAYERS - 1 do
local np = gNetworkPlayers[i]
local s = gPlayerSyncTable[i]
if s.state == RUNNER
and np.connected then
curRunnerCount = curRunnerCount + 1
end
end
hotPotatoTimerMultiplier = curRunnerCount / 2
if hotPotatoTimerMultiplier > 2.3 then hotPotatoTimerMultiplier = 2.3 end
else
hotPotatoTimerMultiplier = 1
end
if gGlobalSyncTable.gamemode == ASSASSINS
or gGlobalSyncTable.gamemode == DEATHMATCH
or gGlobalSyncTable.gamemode == ROYALE then
for i = 0, MAX_PLAYERS - 1 do
if gPlayerSyncTable[i].state ~= SPECTATOR then
gPlayerSyncTable[i].state = TAGGER
end
end
end
gGlobalSyncTable.roundState = ROUND_ACTIVE -- begin round
-- if the gamemode is sardines, set round state to hiding
if gGlobalSyncTable.gamemode == SARDINES then gGlobalSyncTable.roundState = ROUND_SARDINE_HIDING end
log_to_console("Tag: Started the game")
end
elseif gGlobalSyncTable.roundState == ROUND_SARDINE_HIDING then
timer = timer - 1
gGlobalSyncTable.displayTimer = timer
-- attempt to find a runner
local doesRunnerExist = false
for i = 0, MAX_PLAYERS - 1 do
if gNetworkPlayers[i].connected and gPlayerSyncTable[i].state == RUNNER then
doesRunnerExist = true
break
end
end
if not doesRunnerExist then
-- select random sardine
local randomIndex = math.random(0, MAX_PLAYERS - 1) -- select random index
if gPlayerSyncTable[randomIndex].state ~= RUNNER and gPlayerSyncTable[randomIndex].state ~= SPECTATOR and gPlayerSyncTable[randomIndex].state ~= -1 and gNetworkPlayers[randomIndex].connected then
gPlayerSyncTable[randomIndex].state = RUNNER
log_to_console("Tag: Assigned " .. gNetworkPlayers[randomIndex].name .. " as " .. get_role_name(RUNNER))
end
timer = gGlobalSyncTable.hidingTimer[gGlobalSyncTable.gamemode]
end
if timer <= 0 or gGlobalSyncTable.gamemode ~= SARDINES then
timer = gGlobalSyncTable.amountOfTime
gGlobalSyncTable.roundState = ROUND_ACTIVE
end
elseif gGlobalSyncTable.roundState == ROUND_ACTIVE then
if timer > 0 and gGlobalSyncTable.gamemode ~= ODDBALL then
timer = timer - 1 * hotPotatoTimerMultiplier
gGlobalSyncTable.displayTimer = clamp(timer, 0, timer) -- set display timer to timer
end
for i = 0, MAX_PLAYERS - 1 do
if (gPlayerSyncTable[i].state == RUNNER
or (gGlobalSyncTable.gamemode == SARDINES
and gPlayerSyncTable[i].state == WILDCARD_ROLE))
and gGlobalSyncTable.roundState == ROUND_ACTIVE then
gPlayerSyncTable[i].amountOfTimeAsRunner = gPlayerSyncTable[i].amountOfTimeAsRunner + 1 -- increase amount of time as runner
end
end
if timer <= 0 then
if gGlobalSyncTable.gamemode ~= HOT_POTATO then
timer = 5 * 30 -- 5 seconds
if gGlobalSyncTable.gamemode == ASSASSINS
or gGlobalSyncTable.gamemode == DEATHMATCH
or gGlobalSyncTable.gamemode == ROYALE then
gGlobalSyncTable.roundState = ROUND_TAGGERS_WIN -- end round
else
gGlobalSyncTable.roundState = ROUND_RUNNERS_WIN -- end round
end
log_to_console("Tag: Timer's Set to 0, ending round...")
return
else
for i = 0, MAX_PLAYERS - 1 do
if gNetworkPlayers[i].connected then
if gPlayerSyncTable[i].state == TAGGER then
spawn_sync_object(id_bhvExplosion, E_MODEL_EXPLOSION, gMarioStates[i].pos.x,
gMarioStates[i].pos.y, gMarioStates[i].pos.z, function() end)
gPlayerSyncTable[i].state = WILDCARD_ROLE
explosion_popup(i)
end
end
end
end
end
check_round_status() -- check current round status
elseif gGlobalSyncTable.roundState == ROUND_RUNNERS_WIN
or gGlobalSyncTable.roundState == ROUND_TAGGERS_WIN then
timer = timer - 1
gGlobalSyncTable.displayTimer = timer
if timer <= 0 then
if gGlobalSyncTable.tournamentMode then
gGlobalSyncTable.roundState = ROUND_TOURNAMENT_LEADERBOARD
timer = 5 * 30 -- 5 seconds
-- see if someone has won
if has_tournament_ended() then
timer = 10 * 30
end
log_to_console("Tag: Setting round state to ROUND_TOURNAMENT_LEADERBOARD...")
elseif gGlobalSyncTable.doVoting and gGlobalSyncTable.autoMode and #levels - #gGlobalSyncTable.blacklistedCourses >= 4 then
gGlobalSyncTable.roundState = ROUND_VOTING
timer = 11 * 30 -- 11 seconds
log_to_console("Tag: Setting round state to ROUND_VOTING...")
else
if not gGlobalSyncTable.autoMode then
for i = 0, MAX_PLAYERS - 1 do
if gPlayerSyncTable[i].state ~= SPECTATOR then
gPlayerSyncTable[i].state = RUNNER
end
end
gGlobalSyncTable.roundState = ROUND_WAIT_PLAYERS
goto ifend
end
timer = 15 * 30 -- 15 seconds
select_new_level()
gGlobalSyncTable.roundState = ROUND_WAIT -- set round state to the intermission state
log_to_console("Tag: Settings round state to ROUND_WAIT...")
::ifend::
end
end
elseif gGlobalSyncTable.roundState == ROUND_TOURNAMENT_LEADERBOARD then
timer = timer - 1
gGlobalSyncTable.displayTimer = timer
if timer <= 0 then
if gGlobalSyncTable.doVoting and gGlobalSyncTable.autoMode and #levels - #gGlobalSyncTable.blacklistedCourses >= 4 then
gGlobalSyncTable.roundState = ROUND_VOTING
timer = 11 * 30 -- 11 seconds
log_to_console("Tag: Setting round state to ROUND_VOTING...")
else
if not gGlobalSyncTable.autoMode then
for i = 0, MAX_PLAYERS - 1 do
if gPlayerSyncTable[i].state ~= SPECTATOR then
gPlayerSyncTable[i].state = RUNNER
end
end
gGlobalSyncTable.roundState = ROUND_WAIT_PLAYERS
goto ifend
end
timer = 15 * 30 -- 15 seconds
select_new_level()
log_to_console("Tag: Settings round state to ROUND_WAIT...")
::ifend::
end
end
elseif gGlobalSyncTable.roundState == ROUND_HOT_POTATO_INTERMISSION then
timer = timer - 1
gGlobalSyncTable.displayTimer = timer
if timer <= 0 then
local currentConnectedCount = 0
for i = 0, MAX_PLAYERS - 1 do
if gNetworkPlayers[i].connected then
if gPlayerSyncTable[i].state ~= SPECTATOR and gPlayerSyncTable[i].state ~= WILDCARD_ROLE then
currentConnectedCount = currentConnectedCount + 1
end
end
end
local amountOfTaggersNeeded = math.floor(currentConnectedCount / playersNeeded[gGlobalSyncTable.gamemode]) -- always have the amount of the players needed, rounding down, be taggers
if amountOfTaggersNeeded < 1 then amountOfTaggersNeeded = 1 end
if gGlobalSyncTable.modifier == MODIFIER_ONE_TAGGER then
amountOfTaggersNeeded = 1
elseif gGlobalSyncTable.modifier == MODIFIER_ONE_RUNNER then
amountOfTaggersNeeded = numPlayers - 1
end
timer = gGlobalSyncTable.amountOfTime
log_to_console("Tag: Assigning Taggers")
local amountOfTaggers = 0
while amountOfTaggers < amountOfTaggersNeeded do
-- select taggers
local randomIndex = math.random(0, MAX_PLAYERS - 1) -- select random index
if gPlayerSyncTable[randomIndex].state ~= TAGGER and gPlayerSyncTable[randomIndex].state ~= SPECTATOR and gPlayerSyncTable[randomIndex].state ~= WILDCARD_ROLE and gPlayerSyncTable[randomIndex].state ~= -1 and gNetworkPlayers[randomIndex].connected then
gPlayerSyncTable[randomIndex].state = TAGGER
log_to_console("Tag: Assigned " .. gNetworkPlayers[randomIndex].name .. " as Tagger or Infector")
amountOfTaggers = amountOfTaggers + 1
end
end
hotPotatoTimerMultiplier = amountOfTaggersNeeded
if hotPotatoTimerMultiplier > 2.3 then hotPotatoTimerMultiplier = 2.3 end
gGlobalSyncTable.roundState = ROUND_ACTIVE
end
elseif gGlobalSyncTable.roundState == ROUND_VOTING then
timer = timer - 1
if timer >= 0 then
gGlobalSyncTable.displayTimer = timer
end
if timer <= -3 * 30 then
timer = 15 * 30 -- 15
local voteResult = -1
local maxVotes = -1
for i = 1, 4 do
-- get number of votes
local votes = 0
for v = 0, MAX_PLAYERS - 1 do
if gNetworkPlayers[v].connected then
if gPlayerSyncTable[v].votingNumber == i then
votes = votes + 1
end
end
end
if votes > maxVotes then
voteResult = i
maxVotes = votes
end
end
if voteRandomLevels[voteResult] ~= nil then
gGlobalSyncTable.selectedLevel = voteRandomLevels[voteResult]
end
select_new_level()
end
end
end
local function update()
-- server update
if network_is_server() then server_update() end
if gPlayerSyncTable[0].invincTimer ~= nil and gPlayerSyncTable[0].invincTimer > 0 then
gPlayerSyncTable[0].invincTimer = gPlayerSyncTable[0].invincTimer - 1
end
-- handle romhack overrides
if gGlobalSyncTable.romhackOverride ~= nil
and gGlobalSyncTable.romhackOverride ~= prevRomhackOverride then
-- get romhack
local romhack = romhacks[gGlobalSyncTable.romhackOverride]
if romhack == nil then return end
-- set levels var to romhack override
levels = romhack.levels
-- popup
djui_popup_create("Set romhack to\n" .. romhack.name, 3)
-- set prev romhack override
prevRomhackOverride = gGlobalSyncTable.romhackOverride
end
-- set some variables if we are a spectator
if gPlayerSyncTable[0].state == SPECTATOR then
gPlayerSyncTable[0].amountOfTimeAsRunner = 0
gPlayerSyncTable[0].amountOfTags = 0
end
-- set network descriptions
for i = 0, MAX_PLAYERS - 1 do
local np = gNetworkPlayers[i]
local s = gPlayerSyncTable[i]
local text = get_role_name(s.state)
network_player_set_description(np, text, 220, 220, 220, 255)
end
-- handle time stop
if gGlobalSyncTable.roundState == ROUND_TOURNAMENT_LEADERBOARD
or gGlobalSyncTable.roundState == ROUND_RUNNERS_WIN
or gGlobalSyncTable.roundState == ROUND_TAGGERS_WIN
or gGlobalSyncTable.roundState == ROUND_VOTING then
enable_time_stop()
else
disable_time_stop()
end
end
---@param m MarioState
local function mario_update(m)
if levels[gGlobalSyncTable.selectedLevel].overrideWater ~= true
and not gGlobalSyncTable.water then
-- get rid of water
for i = 0, 10 do
set_water_level(i, -10000, false)
end
else
-- bring back water
for i = 0, 10 do
if waterRegions[i] ~= nil then
set_water_level(i, waterRegions[i], false)
end
end
end
-- disable special triple jump
m.specialTripleJump = 0
-- this ensures bljs are a no go, but hey, you can go as fast as a dive, so
if not bljs_enabled() and m.forwardVel <= -48
and (m.action == ACT_LONG_JUMP or m.action == ACT_LONG_JUMP_LAND
or m.action == ACT_LONG_JUMP_LAND_STOP) then
m.forwardVel = -48 -- this is the dive speed
end
m.peakHeight = m.pos.y -- disables fall damage
-- disable hangable ceilings
if m.ceil and m.ceil.type == SURFACE_HANGABLE then
m.ceil.type = SURFACE_DEFAULT
end
-- set player that just joined to be invisible (-1 is not a valid state so)
if gPlayerSyncTable[m.playerIndex].state == -1 then
obj_set_model_extended(m.marioObj, E_MODEL_NONE)
end
-- this is for bowser stages
if m.statusForCamera.cameraEvent == CAM_EVENT_BOWSER_INIT then
m.statusForCamera.cameraEvent = 0
m.area.camera.cutscene = 0
end
-- don't lose cap permanently (thanks shine thief)
m.cap = 0
-- this sets cap flags
-- guide:
-- | = add
-- & ~ = subtract
if gPlayerSyncTable[m.playerIndex].state ~= SPECTATOR
and gPlayerSyncTable[m.playerIndex].state ~= WILDCARD_ROLE then
if gGlobalSyncTable.modifier ~= MODIFIER_FLY then
m.flags = m.flags & ~MARIO_WING_CAP
else
m.flags = m.flags | MARIO_WING_CAP
end
m.flags = m.flags & ~MARIO_METAL_CAP
m.flags = m.flags & ~MARIO_VANISH_CAP