forked from KirbyKid256/mari0_aces
-
Notifications
You must be signed in to change notification settings - Fork 0
/
animation.lua
1256 lines (1206 loc) · 38.8 KB
/
animation.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
animation = class:new()
--[[ TRIGGERS:
mapload when the map is loaded
timepassed:time when <time> ms have passed
playerxgreater:x when a player's x is greater than x
playerxless:x when a player's x is less than x
playerygreater:x when a player's y is greater than y
playeryless:x when a player's y is less than y
animationtrigger:i when animationtrigger with ID i is triggered
mariotimeless:i when mariotime is less than i
buttonpressed:button when player presses button
buttonreleased:button when player releases button
pswitchtrigger:on/off when p switch is pressed or done
switchblocktrigger:i when switch block is used
playerlandsonground:i when player lands on ground
playerhurt:i when player gets hurt
whennumber:i:>/</=:v when a variable turns something
--]]
--[[ CONDITIONS:
noprevsublevel doesn't if the level was changed from another sublevel (Mario goes through pipe, lands in 1-1_1, prevsublevel was _0, no trigger.)
worldequals:i only triggers if current world is i
levelequals:i only triggers if current level is i
sublevelequals:i only triggers if current sublevel is i
requirecoins:i requires i coins to trigger (will not remove coins)
playersize[:player]:size requires a player to be size
requirecollectables:i requires i collectables to trigger (will not remove coins)
requirepoints:i requires i points
buttonhelddown:button only if button is held down
requirekeys[:player]:i requires i keys
ifnumber:i:>/</=:v if a variable is equal/greater than something
ifcoins:>/</=:v if coin count is equal/greater than v
ifcollectables:>/</=:v:i if collectable count of a type is equal/greater than v
ifpoints:>/</=:v if points is equal/greater than v
requireplayers:i requires i players to trigger
--]]
--[[ ACTIONS:
disablecontrols[:player] disables player input and hides the portal line
enablecontrols[:player] enables player input and shows portal line
sleep:time waits for <time> secs
setcamerax:x sets the camera xscroll to <x>
setcameray:y sets the camera yscroll to <y>
pancameratox:x:time pans the camera horizontally over <time> secs to <x>
pancameratoy:y:time pans the camera vertically over <time> secs to <y>
pancamera:x:y:time pans the camera relative to current position over <time>
disablescroll disables autoscroll
enablescroll enables autoscroll
setx[:player]:x sets the x-position of player(s)
sety[:player]:y sets the y-position of player(s)
playerwalk[:player]:direction:speed makes players walk into the given <direction>
playeranimationstop[:player] stops whatever animation the player is in
disableanimation disables this animation from triggering
enableanimation enables this animation to trigger
playerjump[:player] makes players jump (as high as possible)
playerstopjump[:player] makes players abort the jump (for small jumps)
dialogbox:text[:speaker][:color] creates a dialogbox with <text> and <speaker> and <color> (from textcolors in variables.lua)
removedialogbox removes the dialogbox
playmusic:i plays music <i>
screenshake:power makes the screen shake with <power>
addcoins:coins adds <coins> coins
addpoints:points adds <points> points
changebackgroundcolor:r:g:b changes background color to rgb
killplayer[:player] hurts player(s)
changetime:time changes the time left to <time>
loadlevel:world:level:sublevel:exit starts level <world>-<level>_<sublevel> pipeexitid:<exit>
nextlevel goes to next level
disableplayeraim:player disables mouse or joystick aiming for <player>
enableplayeraim:player enables mouse or joystick aiming for <player>
closeportals[:player] closes portals for <player>
makeplayerlook:player:angle makes players aim in direction of <angle>, starting at right and going CCW, should probably be used in connection with "disableplayeraim" because it's just once
makeplayerfireportal:player:i makes a player shoot one of their portal
enableportalgun:player enable portal gun of player
disableportalgun:player disable portal gun of player
repeat repeats animation
instantkillplayer[:player] kills player(s)
disablejumping disable jumping
enablejumping enables jumping
changebackground:background changes background
changeforeground:background changes foreground
removecoins:amount removes coins
removepoints:points removes <points> points
removecollectables:amount:i removes collectables
resetcollectables:amount:i resets collected collectables
disablehorscroll disables horizontal scrolling
nextlevel goes to next level
setautoscrolling sets autoscrolling to <speedx> and <speedy>
stopautoscrolling stops autoscrolling
playsound plays <sound>
stopsound stops <sound>
stopsounds stops all sounds
togglewind toggle wind
togglelightsout toggle lights out
togglelowgravity toggle low gravity
animationoutput:i:signal triggers animationoutput with ID i
transformenemy:i transforms enemy with "transformtrigger": "animation" and "transformanimation": i
killallenemies kills all enemies
triggeranimation:i preforms animation trigger
addkeys[:player]:amount adds keys
removekeys[:player]:amount removes keys
setnumber:name:=/+:v change number by something
resetnumbers resets all animation numbers
launchplayer[:player]:x:y launches player at defined speed
addtime:time adds <seconds> time
removetime:time removes <seconds> time
settime:time sets time
setplayerlight:blocks sets player's light in lights out mode
waitforinput waits until a spesific/any player presses a button
waitfrotrigger waits until a spesific animation is triggered
makeinvincible:i makes player invincible/give star for i or default seconds
changeswitchstate:i trigger switchblocks
--]]
function animation:init(path, name)
self.filepath = path
self.name = name
self.raw = love.filesystem.read(self.filepath)
self:decode(self.raw)
self.queue = {}
self.firstupdate = true
self.running = false
self.sleep = 0
self.waiting = false
self.enabled = true
end
function animation:decode(s)
self.triggers = {}
self.conditions = {}
self.actions = {}
local animationjson
if s then
animationjson = JSON:decode(s)
else
animationjson = {}
notice.new("Could not read animation", notice.red, 2)
end
for i, v in pairs(animationjson.triggers) do
self:addtrigger(v)
end
for i, v in pairs(animationjson.conditions) do
self:addcondition(v)
end
for i, v in pairs(animationjson.actions) do
self:addaction(v)
end
end
function animation:addtrigger(v)
table.insert(self.triggers, {unpack(v)})
if v[1] == "mapload" then
elseif v[1] == "timepassed" then
self.timer = 0
elseif v[1] == "playerx" then
elseif v[1] == "animationtrigger" then
if not animationtriggerfuncs[v[2] ] then
animationtriggerfuncs[v[2] ] = {}
end
table.insert(animationtriggerfuncs[v[2] ], self)
elseif v[1] == "buttonpressed" then
local name = v[2]
if name:find("player ") then
name = tonumber(string.sub(v[2], -1))
end
if not animationbuttontriggerfuncs[v[2]] then --player
animationbuttontriggerfuncs[v[2]] = {}
end
table.insert(animationbuttontriggerfuncs[v[2]], {self, v[3]})
elseif v[1] == "buttonreleased" then
local name = v[2]
if name:find("player ") then
name = tonumber(string.sub(v[2], -1))
end
if not animationbuttonreleasetriggerfuncs[v[2]] then --player
animationbuttonreleasetriggerfuncs[v[2]] = {}
end
table.insert(animationbuttonreleasetriggerfuncs[v[2]], {self, v[3]})
elseif v[1] == "switchblocktrigger" then
table.insert(animationswitchtriggerfuncs, {self, v[2]})
elseif v[1] == "pswitchtrigger" then
table.insert(animationswitchtriggerfuncs, {self, "pswitch-" .. v[2]})
elseif v[1] == "playerlandsonground" then
local name = v[2]
if name:find("player ") then
name = tonumber(string.sub(v[2], -1))
end
if not animationplayerlandtriggerfuncs[name] then --player
animationplayerlandtriggerfuncs[name] = {}
end
table.insert(animationplayerlandtriggerfuncs[name], self)
elseif v[1] == "playerhurt" then
local name = v[2]
if name:find("player ") then
name = tonumber(string.sub(v[2], -1))
end
if not animationplayerhurttriggerfuncs[name] then --player
animationplayerhurttriggerfuncs[name] = {}
end
table.insert(animationplayerhurttriggerfuncs[name], self)
end
end
function animation:addcondition(v)
table.insert(self.conditions, {unpack(v)})
end
function animation:addaction(v)
table.insert(self.actions, {unpack(v)})
end
function animation:update(dt)
--check my triggers for triggering, yo
for i, v in pairs(self.triggers) do
if v[1] == "mapload" then
if self.firstupdate then
self:trigger()
end
elseif v[1] == "timepassed" then
self.timer = self.timer + dt
if tonumber(v[2]) and self.timer >= tonumber(v[2]) and self.timer - dt < tonumber(v[2]) then
self:trigger()
end
elseif v[1] == "mariotimeless" then
if mariotime <= tonumber(v[2]) and not levelfinished then
self:trigger()
end
elseif v[1] == "playerxgreater" then
local trig = false
for i = 1, players do
if objects["player"][i].x+objects["player"][i].width/2 > tonumber(v[2]) then
trig = true
end
end
if trig then
self:trigger()
end
elseif v[1] == "playerxless" then
local trig = false
for i = 1, players do
if objects["player"][i].x+objects["player"][i].width/2 < tonumber(v[2]) then
trig = true
end
end
if trig then
self:trigger()
end
elseif v[1] == "playerygreater" then
local trig = false
for i = 1, players do
if objects["player"][i].y+objects["player"][i].height/2 > tonumber(v[2]) then
trig = true
end
end
if trig then
self:trigger()
end
elseif v[1] == "playeryless" then
local trig = false
for i = 1, players do
if objects["player"][i].y+objects["player"][i].height/2 < tonumber(v[2]) then
trig = true
end
end
if trig then
self:trigger()
end
elseif v[1] == "whennumber" then
local trig = false
local name = tostring(v[2])
local operation = v[3]
local value = tonumber(v[4])
if name then
if (not animationnumbers[name]) or (not value) then
trig = false
else
if operation == "=" then
if animationnumbers[name] == value then
trig = true
end
elseif operation == ">" then
if animationnumbers[name] > value then
trig = true
end
elseif operation == "<" then
if animationnumbers[name] < value then
trig = true
end
end
end
end
if trig then
self:trigger()
end
end
end
self.firstupdate = false
if self.running then
if self.sleep > 0 then
self.sleep = math.max(0, self.sleep - dt)
elseif self.waiting then
if self.waiting.t == "input" then
local pstart, pend = 1, players
local button = self.waiting.button
if self.waiting.player ~= "everyone" then
local p = tonumber(string.sub(self.waiting.player, -1))
pstart, pend = p, p
end
local press = false
for i = pstart, pend do
if button == "jump" and jumpkey(i) then
press = true
elseif button == "left" and leftkey(i) then
press = true
elseif button == "right" and rightkey(i) then
press = true
elseif button == "up" and upkey(i) then
press = true
elseif button == "down" and downkey(i) then
press = true
elseif button == "run" and runkey(i) then
press = true
elseif button == "use" and usekey(i) then
press = true
elseif button == "reload" and reloadkey(i) then
press = true
end
if press then
self.waiting = false
end
end
elseif self.waiting.t == "trigger" then
if animationtriggerfuncs[self.waiting.name] and animationtriggerfuncs[self.waiting.name].triggered then
animationtriggerfuncs[self.waiting.name].triggered = nil
self.waiting = false
end
end
end
while self.sleep == 0 and (not self.waiting) and self.currentaction <= #self.actions do
local v = self.actions[self.currentaction]
if v[1] == "disablecontrols" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i].controlsenabled = false
end
else
local p = objects["player"][tonumber(string.sub(v[2], -1))]
if p then
p.controlsenabled = false
end
end
elseif v[1] == "enablecontrols" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i].controlsenabled = true
end
else
local p = objects["player"][tonumber(string.sub(v[2], -1))]
if p then
p.controlsenabled = true
end
end
elseif v[1] == "sleep" then
self.sleep = tonumber(v[2])
elseif v[1] == "waitforinput" then
self.waiting = {t="input", button=v[2], player=v[3]}
elseif v[1] == "waitfortrigger" then
self.waiting = {t="trigger", name=v[2]}
elseif v[1] == "setcamerax" then
xscroll = tonumber(v[2])
elseif v[1] == "setcameray" then
yscroll = tonumber(v[2])
elseif v[1] == "pancameratox" then
autoscrollx = false
if tonumber(v[3]) == 0 then
camerasnap(tonumber(v[2]), yscroll, "animation")
generatespritebatch()
else
cameraxpan(tonumber(v[2]), tonumber(v[3]))
end
elseif v[1] == "pancameratoy" then
autoscrolly = false
if tonumber(v[3]) == 0 then
camerasnap(xscroll, tonumber(v[2]), "animation")
generatespritebatch()
else
cameraypan(tonumber(v[2]), tonumber(v[3]))
end
elseif v[1] == "pancamera" then
local hor, ver = tonumber(v[2]), tonumber(v[3])
if hor ~= 0 then
autoscrollx = false
end
if ver ~= 0 then
autoscrolly = false
end
if tonumber(v[4]) == 0 then
camerasnap(xscroll+hor, yscroll+ver, "animation")
generatespritebatch()
else
cameraxpan(xscroll+hor, tonumber(v[4]))
cameraypan(yscroll+ver, tonumber(v[4]))
end
elseif v[1] == "disablescroll" then
autoscroll = false
autoscrolly = false
autoscrollx = false
elseif v[1] == "disableverscroll" then
autoscrolly = false
elseif v[1] == "disablehorscroll" then
autoscrollx = false
elseif v[1] == "enablescroll" then
autoscroll = true
autoscrolly = true
autoscrollx = true
elseif v[1] == "enableverscroll" then
autoscrolly = true
elseif v[1] == "enablehorscroll" then
autoscrollx = true
elseif v[1] == "setx" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i].x = tonumber(v[3])
end
else
if objects["player"][tonumber(string.sub(v[2], -1))] then
objects["player"][tonumber(string.sub(v[2], -1))].x = tonumber(v[3])
end
end
elseif v[1] == "sety" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i].y = tonumber(v[3])
end
else
if objects["player"][tonumber(string.sub(v[2], -1))] then
objects["player"][tonumber(string.sub(v[2], -1))].y = tonumber(v[3])
end
end
elseif v[1] == "playerwalk" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i]:animationwalk(v[3], tonumber(v[4]))
end
else
if objects["player"][tonumber(string.sub(v[2], -1))] then
objects["player"][tonumber(string.sub(v[2], -1))]:animationwalk(v[3], tonumber(v[4]))
end
end
elseif v[1] == "playeranimationstop" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i]:stopanimation()
end
else
if objects["player"][tonumber(string.sub(v[2], -1))] then
objects["player"][tonumber(string.sub(v[2], -1))]:stopanimation()
end
end
elseif v[1] == "disableanimation" then
self.enabled = false
elseif v[1] == "enableanimation" then
self.enabled = true
elseif v[1] == "playerjump" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i]:jump(true)
end
else
if objects["player"][tonumber(string.sub(v[2], -1))] then
objects["player"][tonumber(string.sub(v[2], -1))]:jump(true)
end
end
elseif v[1] == "playerstopjump" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i]:stopjump(true)
end
else
if objects["player"][tonumber(string.sub(v[2], -1))] then
objects["player"][tonumber(string.sub(v[2], -1))]:stopjump()
end
end
elseif v[1] == "dialogbox" then
createdialogbox(v[2], v[3], v[4])
elseif v[1] == "removedialogbox" then
dialogboxes = {}
elseif v[1] == "playmusic" then
love.audio.stop()
if v[2] then
--if musicname then
-- music:stop(musicname)
--end
stopmusic()
musicname = v[2]
if v[2] == "star" then
musicname = "starmusic"
end
for i, m in pairs(music.list) do
if m == musicname then
musici = i + 1 -- plus one because of the none music being number 1
end
end
for i, m in pairs(custommusics) do
if m == "mappacks/" .. mappack .. "/" .. musicname then
musicname = m
musici = 7
custommusic = musicname
end
end
music:play(musicname)
--playmusic()
end
elseif v[1] == "playsound" then
if v[2] then
for i, s in pairs(soundliststring) do
if s == v[2] then
if customsounds and customsounds[i] then
playsound(_G[soundliststring[i] .. "sound"])
else
playsound(soundlist[i])
end
end
end
end
elseif v[1] == "stopsound" then
if v[2] then
for i, s in pairs(soundliststring) do
if s == v[2] then
if customsounds and customsounds[i] then
_G[soundliststring[i] .. "sound"]:stop()
else
soundlist[i]:stop()
end
end
end
end
elseif v[1] == "stopsounds" then
if v[2] then
for i, s in pairs(soundliststring) do
if customsounds and customsounds[i] then
_G[soundliststring[i] .. "sound"]:stop()
else
soundlist[i]:stop()
end
end
end
elseif v[1] == "screenshake" then
earthquake = tonumber(v[2]) or 1
elseif v[1] == "addcoins" then
collectcoin(nil, nil, tonumber(v[2]) or 1)
elseif v[1] == "addpoints" then
addpoints(tonumber(v[2]) or 1)
elseif v[1] == "removepoints" then
marioscore = math.max(0, marioscore - (tonumber(v[2]) or 1))
elseif v[1] == "addtime" then
local oldtime = mariotime
mariotime = mariotime + (tonumber(v[2]) or 0)
if oldtime < 100 and mariotime > 100 and not lowtimesound:isPlaying() then
music:stopall()
playmusic()
end
elseif v[1] == "removetime" then
local oldtime = mariotime
mariotime = math.max(0.01, mariotime - (tonumber(v[2]) or 0))
if oldtime > 100 and mariotime < 100 then
startlowtime()
end
elseif v[1] == "settime" then
local oldtime = mariotime
mariotime = math.max(0.01, tonumber(v[2]) or mariotime)
if oldtime > 100 and mariotime < 100 then
startlowtime()
elseif oldtime < 100 and mariotime > 100 and not lowtimesound:isPlaying() then
music:stopall()
playmusic()
end
elseif v[1] == "changebackgroundcolor" then
love.graphics.setBackgroundColor((tonumber(v[2]) or 255)/255, (tonumber(v[3]) or 255)/255, (tonumber(v[4]) or 255)/255)
elseif v[1] == "killplayer" then
if v[2] == "everyone" then
for i = 1, players do
if not objects["player"][i].dead then
objects["player"][i]:die("script")
end
end
else
if objects["player"][tonumber(string.sub(v[2], -1))] and not objects["player"][tonumber(string.sub(v[2], -1))].dead then
objects["player"][tonumber(string.sub(v[2], -1))]:die("script")
end
end
elseif v[1] == "instantkillplayer" then
if v[2] == "everyone" then
for i = 1, players do
if not objects["player"][i].dead then
objects["player"][i]:die("killscript")
end
end
else
if objects["player"][tonumber(string.sub(v[2], -1))] and not objects["player"][tonumber(string.sub(v[2], -1))].dead then
objects["player"][tonumber(string.sub(v[2], -1))]:die("killscript")
end
end
elseif v[1] == "changetime" then
mariotime = (tonumber(v[2]) or 400)
elseif v[1] == "loadlevel" or v[1] == "loadlevelinstant" then
love.audio.stop()
--why do sublevels suck so much
local oldsub = mariosublevel
marioworld = tonumber(v[2]) or marioworld
mariolevel = tonumber(v[3]) or mariolevel
mariosublevel = tonumber(v[4]) or mariosublevel
testlevelworld = marioworld
testlevellevel = mariolevel
actualsublevel = mariosublevel
respawnsublevel = mariosublevel
levelscreen_load("animation")
if v[5] then --Edit ID
pipeexitid = tonumber(v[5])
animationprevsublevel = oldsub --dumb work around
end
mariosublevel = tonumber(v[4]) or mariosublevel
actualsublevel = mariosublevel
respawnsublevel = mariosublevel
if v[1] == "loadlevelinstant" then
levelscreentimer = blacktime
end
elseif v[1] == "nextlevel" then
nextlevel()
elseif v[1] == "disableplayeraim" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i].disableaiming = true
end
else
if objects["player"][tonumber(string.sub(v[2], -1))] then
objects["player"][tonumber(string.sub(v[2], -1))].disableaiming = true
end
end
elseif v[1] == "enableplayeraim" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i].disableaiming = false
end
else
if objects["player"][tonumber(string.sub(v[2], -1))] then
objects["player"][tonumber(string.sub(v[2], -1))].disableaiming = false
end
end
elseif v[1] == "closeportals" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i]:removeportals()
end
else
if objects["player"][tonumber(string.sub(v[2], -1))] then
objects["player"][tonumber(string.sub(v[2], -1))]:removeportals()
end
end
elseif v[1] == "makeplayerlook" then
local ang = math.fmod(math.fmod(tonumber(v[3]), 360)+360, 360)
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i].pointingangle = math.rad(ang)-math.pi/2
end
else
if objects["player"][tonumber(string.sub(v[2], -1))] then
objects["player"][tonumber(string.sub(v[2], -1))].pointingangle = math.rad(ang)-math.pi/2
end
end
elseif v[1] == "makeplayerfireportal" then
if tonumber(v[3]) == 1 or tonumber(v[3]) == 2 then
if v[2] == "everyone" then
for i = 1, players do
local sourcex = objects["player"][i].x+6/16
local sourcey = objects["player"][i].y+6/16
local direction = objects["player"][i].pointingangle
shootportal(i, 1, sourcex, sourcey, direction)
end
else
local i = tonumber(string.sub(v[2], -1))
if objects["player"][i] then
local sourcex = objects["player"][i].x+6/16
local sourcey = objects["player"][i].y+6/16
local direction = objects["player"][i].pointingangle
shootportal(i, 1, sourcex, sourcey, direction)
end
end
end
elseif v[1] == "disableportalgun" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i].portalgundisabled = true
end
else
local i = tonumber(string.sub(v[2], -1))
if objects["player"][i] then
objects["player"][i].portalgundisabled = true
end
end
elseif v[1] == "enableportalgun" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i].portalgundisabled = false
end
else
local i = tonumber(string.sub(v[2], -1))
if objects["player"][i] then
objects["player"][i].portalgundisabled = false
end
end
elseif v[1] == "launchplayer" then
local sx, sy = v[3]:gsub("B","-"), v[4]:gsub("B","-")
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i].speedx = tonumber(sx) or 0
objects["player"][i].speedy = tonumber(sy) or 0
end
else
local i = tonumber(string.sub(v[2], -1))
if objects["player"][i] then
objects["player"][i].speedx = tonumber(sx) or 0
objects["player"][i].speedy = tonumber(sy) or 0
end
end
elseif v[1] == "changebackground" then
if v[2] then
loadcustombackground(v[2])
end
custombackground = v[2]
elseif v[1] == "changeforeground" then
if v[2] then
loadcustomforeground(v[2])
end
customforeground = v[2]
elseif v[1] == "removecoins" then
mariocoincount = math.max(0, mariocoincount-(tonumber(v[2]) or 0))
elseif v[1] == "removecollectables" then
collectablescount[tonumber(v[3]) or 1] = math.max(0, collectablescount[tonumber(v[3]) or 1]-(tonumber(v[2]) or 1))
for i, o in pairs(objects["collectablelock"]) do
o:removecheck()
end
elseif v[1] == "addcollectables" then
local t = tonumber(v[3]) or 1
collectablescount[t] = collectablescount[t]+(tonumber(v[2]) or 1)
playsound(_G["collectable" .. t .. "sound"])
elseif v[1] == "resetcollectables" then
local i = tonumber(v[2]) or 1
--iterate through collected collectable list and remove any saved locations
local w, l, s = tostring(marioworld), tostring(mariolevel), tostring(actualsublevel)
local level = w .. "-" .. l .. "-" .. s
for n, t in pairs(collectableslist[i]) do
collectables[t[1]][t[2]] = nil
if level == t[1] then
--respawn collectable
local s = t[2]:split("-") --find coords
local x, y = tonumber(s[1]), tonumber(s[2])
local coinblock = (ismaptile(x, y) and tilequads[map[x][y][1]].collision and tilequads[map[x][y][1]].coinblock)
objects["collectable"][tilemap(x,y)] = collectable:new(x, y, map[x][y], false, coinblock)
end
end
collectableslist[i] = {}
--finally, reset the amount and update locks
collectablescount[i] = 0
for i, o in pairs(objects["collectablelock"]) do
o:removecheck()
end
elseif v[1] == "setautoscrolling" then
local sx, sy = v[2]:gsub("B","-"), v[3]:gsub("B","-")
autoscrolling = true
autoscrollingx = tonumber(sx) or autoscrollingdefaultspeed
if autoscrollingx == 0 then
autoscrollingx = false
end
autoscrollingy = tonumber(sy) or autoscrollingdefaultspeed
if autoscrollingy == 0 then
autoscrollingy = false
end
elseif v[1] == "stopautoscrolling" then
autoscrolling = false
autoscrollingx = false
autoscrollingy = false
elseif v[1] == "togglewind" then
if v[2] then
local speed = tonumber(v[2])
if speed == 0 then
windstarted = false
else
windentityspeed = speed
end
else
windstarted = not windstarted
end
elseif v[1] == "togglelowgravity" then
lowgravity = not lowgravity
setphysics(currentphysics)
elseif v[1] == "togglelightsout" then
lightsout = not lightsout
elseif v[1] == "centercamera" then
setcamerasetting(2)
elseif v[1] == "removeshoe" then
if v[2] == "everyone" then
for i = 1, players do
if objects["player"][i].shoe then
objects["player"][i].yoshi = false
objects["player"][i]:shoed(false)
end
end
else
local i = tonumber(string.sub(v[2], -1))
if objects["player"][i] then
if objects["player"][i].shoe then
objects["player"][i].yoshi = false
objects["player"][i]:shoed(false)
end
end
end
elseif v[1] == "removehelmet" then
if v[2] == "everyone" then
for i = 1, players do
if objects["player"][i].helmet then
objects["player"][i]:helmeted(false)
end
end
else
local i = tonumber(string.sub(v[2], -1))
if objects["player"][i] then
if objects["player"][i].helmet then
objects["player"][i]:helmeted(false)
end
end
end
elseif v[1] == "animationoutput" then
for name, obj in pairs(objects["animationoutput"]) do
if obj.id == v[2] then
obj:trigger(v[3])
end
end
elseif v[1] == "transformenemy" then
transformenemyanimation(v[2])
elseif v[1] == "killallenemies" then
for i2, v2 in kpairs(objects, objectskeys) do
if i2 ~= "tile" and i2 ~= "buttonblock" then
for i3, v3 in pairs(objects[i2]) do
if v3.active and v3.shotted and (not v3.resistseverything) then
local dir = "right"
if math.random(1,2) == 1 then
dir = "left"
end
v3:shotted(dir)
end
end
end
end
elseif v[1] == "setplayersize" then
if v[3] == "everyone" then
for i = 1, players do
objects["player"][i]:setsize(tonumber(v[2]))
objects["player"][i].size = tonumber(v[2])
playsound(mushroomeatsound)
end
else
local i = tonumber(string.sub(v[3], -1))
if objects["player"][i] then
objects["player"][i]:setsize(tonumber(v[2]))
objects["player"][i].size = tonumber(v[2])
playsound(mushroomeatsound)
end
end
elseif v[1] == "disablejumping" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i].disablejumping = true
end
else
local p = objects["player"][tonumber(string.sub(v[2], -1))]
if p then
p.disablejumping = true
end
end
elseif v[1] == "enablejumping" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i].disablejumping = false
end
else
local p = objects["player"][tonumber(string.sub(v[2], -1))]
if p then
p.disablejumping = false
end
end
elseif v[1] == "changeportal" then
local pstart, pend = 1, players
if v[2] ~= "everyone" then
pstart, pend = tonumber(string.sub(v[2], -1)), tonumber(string.sub(v[2], -1))
end
for i = pstart, pend do
if objects["player"][i] then
local p = objects["player"][i]
p.portalgun = (v[3] ~= "none")
if p.portalgun and (not p.characterdata.noportalgun) and playertype ~= "classic" and playertype ~= "cappy" then
p.portals = v[3]
p:updateportalsavailable()
end
end
end
elseif v[1] == "triggeranimation" then
if animationtriggerfuncs[v[2]] then
for i = 1, #animationtriggerfuncs[v[2]] do
animationtriggerfuncs[v[2]][i]:trigger()
end
animationtriggerfuncs[v[2]].triggered = true
end
elseif v[1] == "addkeys" then
if v[3] == "everyone" then
for i = 1, players do
if objects["player"][i].key then
objects["player"][i].key = objects["player"][i].key + tonumber(v[2])
else
objects["player"][i].key = tonumber(v[2])
end
end
playsound(keysound)
else
local i = tonumber(string.sub(v[3], -1))
if objects["player"][i] then
if objects["player"][i].key then
objects["player"][i].key = objects["player"][i].key + tonumber(v[2])
else
objects["player"][i].key = tonumber(v[2])
end
playsound(keysound)
end
end
elseif v[1] == "removekeys" then
if v[3] == "everyone" then
for i = 1, players do
if objects["player"][i].key then
objects["player"][i].key = math.max(0, objects["player"][i].key - tonumber(v[2]))
end
end
else
local i = tonumber(string.sub(v[3], -1))
if objects["player"][i] then
if objects["player"][i].key then
objects["player"][i].key = math.max(0, objects["player"][i].key - tonumber(v[2]))
end
end
end
elseif v[1] == "setplayerlight" then
for i = 1, players do
objects["player"][i].light = tonumber(v[2])
end
elseif v[1] == "makeinvincible" then
local time = mariostarduration
if v[2] ~= "" and tonumber(v[2]) and tonumber(v[2]) > 0 then
time = tonumber(v[2])
end
if v[3] == "everyone" then
for i = 1, players do
if objects["player"][i].animation ~= "grow1" and objects["player"][i].animation ~= "grow2" and objects["player"][i].animation ~= "shrink" then
objects["player"][i]:star()
objects["player"][i].startimer = (mariostarduration-time)
end
end
else
local i = tonumber(string.sub(v[3], -1))