-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodule.lua
1493 lines (1313 loc) · 37.9 KB
/
module.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
local module = {
owner = "Bolodefchoco#0015",
id = "cn",
min_mice = 4,
map_file = 0,
xp_per_30_sec = 5,
xp_per_victory = 15
}
--[[ Translations ]]--
local translations = {
en = {
-- Init
welcome = "Welcome to #cannonup. Your aim is to be the survivor!\n<VP>Press <B>P</B> to open your profile or <B>!p nickname</B> to see someone's profile!\n<J>Submit maps in <S>https://atelier801.com/topic?f=6&t=859067\n\t<J>Report any issue to Bolodefchoco#0015.",
-- Info
nowinner = "No one won!",
-- Simple words
soon = "Soon!",
won = "won!",
-- Profile
profile = { "Rounds", "Victories", "Badges" },
-- Titles
unlock = "%s just unlocked the title «%s»",
titlecmd = "Type !title to change your title.",
titlemsg = "Type !title X to choose a title in the list below :",
usetitle = "Your new title is <CH>«%s»",
titles = {
[1] = {
[1] = "Survivor",
[2] = "Veteran",
[3] = "Blessed",
[4] = "Anti Robot",
[5] = "Addicted",
[6] = "King of the Hill",
[7] = "Psychedelic Mouse"
},
[2] = {
[1] = "Leve Mouse",
[2] = "Cannon Boy",
[3] = "Unkillable Mouse",
[4] = "Undetectable Mouse",
[5] = "Warrior",
[6] = "Explosion",
[7] = "F = Mouse * A",
[8] = "Matrix",
[9] = "Survivor Master",
},
[3] = {
[1] = "Watermelon",
[2] = "Mapmaker", -- at least 5 maps in the module
[3] = "Dodger", -- desviar de x cn
[4] = "Parkour Mouse", -- jump 120x
}
}
},
br = {
welcome = "Bem-vindo ao #cannonup. Seu objetivo é ser o sobrevivente!\n<VP>Aperte <B>P</B> para abrir seu perfil ou <B>!p nickname</B> para ver o perfil de alguém!\n<J>Envie mapas em <S>https://atelier801.com/topic?f=6&t=859067\n\t<J>Reporte qualquer problema para Bolodefchoco#0015.",
nowinner = "Ninguém ganhou!",
soon = "Em breve!",
won = "venceu!",
profile = { "Partidas", "Vitórias", "Medalhas" },
unlock = "%s desbloqueou o título «%s»",
titlecmd = "Digite !title para mudar seu título.",
titlemsg = "Digite !title X para escolher um título na lista abaixo :",
usetitle = "Seu novo título é <CH>«%s»",
titles = {
[1] = {
[1] = "Survivor",
[2] = "Veterano",
[3] = "Abençoado",
[4] = "Anti Robô",
[5] = "Viciado",
[6] = "Rei da Colina",
[7] = "Rato Psicodélico"
},
[2] = {
[1] = "Rato Leve",
[2] = "Cannon Boy",
[3] = "Rato Imortal",
[4] = "Rato Indetectável",
[5] = "Guerreiro",
[6] = "Explosão",
[7] = "F = Mouse * A",
[8] = "Matrix",
[9] = "Mestre Survivor",
},
[3] = {
[1] = "Melancia",
[2] = "Mapper", -- at least 5 maps in the module
[3] = "Dodger", -- desviar de x cn
[4] = "Rato do Parkour", -- jump 120x
}
}
},
}
local translation = translations[tfm.get.room.community] or translations.en
--[[ Data ]]--
local mapEvaluators = {
["Bolodefchoco#0015"] = true,
["Acer#0010"] = true,
["Jota#0676"] = true,
["Grapeup#0020"] = true
}
local artist = {
["Flindix#0095"] = true
}
local keys = {
P = string.byte('P')
}
local badges = {
{ 2^0, "1660271f4c6.png" }, -- Map Reviewer
{ 2^1, "165df979c2f.png" }, -- Artist
{ 2^2, "165df891e2a.png" }, -- Mapper (more than 5)
}
local titles = {
-- Rounds, Victories, Challenges
[1] = {
[1] = 0,
[2] = 50,
[3] = 150,
[4] = 250,
[5] = 450,
[6] = 750,
[7] = 1000
},
[2] = {
[1] = 10,
[2] = 50,
[3] = 70,
[4] = 150,
[5] = 250,
[6] = 320,
[7] = 450,
[8] = 500,
[9] = 1000
},
[3] = {
[1] = { 2^0, true },
[2] = { 2^1, true },
[3] = { 2^2, true },
[4] = { 2^3, true }
}
}
--[[ Data Handler ]]--
local DataHandler = {}
DataHandler.VERSION = '1.3.3'
DataHandler.__index = DataHandler
function DataHandler.new(moduleID, skeleton, otherOptions)
local self = setmetatable({}, DataHandler)
assert(moduleID, 'Invalid module ID (nil)')
assert(moduleID ~= '', 'Invalid module ID (empty text)')
assert(skeleton, 'Invalid skeleton (nil)')
for k, v in next, skeleton do
v.type = v.type or type(v.default)
end
self.players = {}
self.moduleID = moduleID
self.moduleSkeleton = skeleton
self.moduleIndexes = {}
self.otherOptions = otherOptions
self.otherData = {}
self.originalStuff = {}
for k,v in pairs(skeleton) do
self.moduleIndexes[v.index] = k
end
if self.otherOptions then
self.otherModuleIndexes = {}
for k,v in pairs(self.otherOptions) do
self.otherModuleIndexes[k] = {}
for k2,v2 in pairs(v) do
self.otherModuleIndexes[k][v2.index] = k2
end
end
end
return self
end
function DataHandler.newPlayer(self, name, dataString)
assert(name, 'Invalid player name (nil)')
assert(name ~= '', 'Invalid player name (empty text)')
self.players[name] = {}
self.otherData[name] = {}
dataString = dataString or ''
self.originalStuff[name] = dataString
-- turns a simple table into a string
local function turnStringToTable(str)
local output = {}
for data in string.gsub(str, '%b{}', function(b) return b:gsub(',', '\0') end):gmatch('[^,]+') do
-- for data in string.gsub(str, '({.*()})', function(b) return b:gsub(',', '\0') end):gmatch('[^,]+') do
data = data:gsub('%z', ',')
if string.match(data, '^{.-}$') then
table.insert(output, turnStringToTable(string.match(data, '^{(.-)}$')))
else
table.insert(output, tonumber(data) or data)
end
end
return output
end
-- get the field index
local function getDataIndexName(skeleton, index)
for k,v in pairs(skeleton) do
if v.index == index then
return k
end
end
return 0
end
-- gets the higher index
local function getHigherIndex(skeleton)
local higher = 0
for k,v in pairs(skeleton) do
if v.index > higher then
higher = v.index
end
end
return higher
end
-- creates the fields in the player's table
-- loads the other modules' data too
local function handleModuleData(moduleID, skeleton, moduleData, makeTable)
local dataIndex = 1
local higherIndex = getHigherIndex(skeleton)
if makeTable then
self.players[name]['__'..moduleID] = {}
end
local setPlayerData = function(data, dataType, dataName, dataDefault)
if dataType == 'number' then
if makeTable then
self.players[name]['__'..moduleID][dataName] = tonumber(data) or dataDefault
else
self.players[name][dataName] = tonumber(data) or dataDefault
end
elseif dataType == 'string' then
if makeTable then
if string.match(data or '', '^".-"$') then
self.players[name]['__'..moduleID][dataName] = string.match(data, '^"(.-)"$')
else
self.players[name]['__'..moduleID][dataName] = dataDefault
end
else
if string.match(data or '', '^".-"$') then
self.players[name][dataName] = string.match(data, '^"(.-)"$')
else
self.players[name][dataName] = dataDefault
end
end
elseif dataType == 'table' then
if makeTable then
if string.match(data or '', '^{.-}$') then
self.players[name]['__'..moduleID][dataName] = turnStringToTable(string.match(data, '^{(.-)}$'))
else
self.players[name]['__'..moduleID][dataName] = dataDefault
end
else
if string.match(data or '', '^{.-}$') then
self.players[name][dataName] = turnStringToTable(string.match(data, '^{(.-)}$'))
else
self.players[name][dataName] = dataDefault
end
end
elseif dataType == 'boolean' then
if makeTable then
self.players[name]['__'..moduleID][dataName] = data and (tonumber(data) == 1) or dataDefault
else
self.players[name][dataName] = data and (tonumber(data) == 1) or dataDefault
end
end
end
if #moduleData > 0 then
for data in string.gsub(moduleData, '%b{}', function(b) return b:gsub(',', '\0') end):gmatch('[^,]+') do
-- for data in string.gsub(moduleData, '({.*()})', function(b) return b:gsub(',', '\0') end):gmatch('[^,]+') do
data = data:gsub('%z', ',')
-- pega info a respeito do esqueleto
local dataName = getDataIndexName(skeleton, dataIndex)
local dataType = skeleton[dataName].type
local dataDefault = skeleton[dataName].default
setPlayerData(data, dataType, dataName, dataDefault)
dataIndex = dataIndex + 1
end
end
-- fields are missing, will set them to default
if dataIndex <= higherIndex then
for i = dataIndex, higherIndex do
local dataName = getDataIndexName(skeleton, i)
local dataType = skeleton[dataName].type
local dataDefault = skeleton[dataName].default
setPlayerData(nil, dataType, dataName, dataDefault)
end
end
end
local modules, originalStuff = self:getModuleData(dataString)
-- keeps other unrelated stuff
self.originalStuff[name] = originalStuff
if not modules[self.moduleID] then
modules[self.moduleID] = '{}'
end
handleModuleData(self.moduleID, self.moduleSkeleton, modules[self.moduleID]:sub(2,-2), false)
if self.otherOptions then
-- if the player does not have the other modules' data and we need them
-- then creates the data using the default values provided
for moduleID, skeleton in pairs(self.otherOptions) do
if not modules[moduleID] then
local strBuilder = {}
for k,v in pairs(skeleton) do
if v.type == 'string' then
strBuilder[v.index] = '"'..tostring(v.default)..'"'
elseif v.type == 'table' then
strBuilder[v.index] = '{}'
elseif v.type == 'number' then
strBuilder[v.index] = v.default
end
end
modules[moduleID] = '{'..table.concat(strBuilder, ',')..'}'
end
end
end
-- loads the player's data from other modules
for moduleID, moduleData in pairs(modules) do
if moduleID ~= self.moduleID then
if self.otherOptions and self.otherOptions[moduleID] then
handleModuleData(moduleID, self.otherOptions[moduleID], moduleData:sub(2,-2), true)
else
self.otherData[name][moduleID] = moduleData
end
end
end
end
function DataHandler.dumpPlayer(self, name)
-- dumps player data to string
local output = {}
-- turns a simple table into a string
local function turnTableToString(tbl)
local output = {}
for k,v in pairs(tbl) do
if type(v) == 'table' then
output[#output+1] = '{'
output[#output+1] = turnTableToString(v)
if output[#output]:sub(-1) == ',' then
output[#output] = output[#output]:sub(1, -2)
end
output[#output+1] = '}'
output[#output+1] = ','
else
if type(v) == 'string' then
output[#output+1] = '"'
output[#output+1] = v
output[#output+1] = '"'
elseif type(v) == 'boolean' then
output[#output+1] = v and '1' or '0'
else
output[#output+1] = v
end
output[#output+1] = ','
end
end
if output[#output] == ',' then
output[#output] = ''
end
return table.concat(output)
end
-- returns a module's data in string
local function getPlayerDataFrom(name, moduleID)
local output = {moduleID, '=', '{'}
local player = self.players[name]
local moduleIndexes = self.moduleIndexes
local moduleSkeleton = self.moduleSkeleton
if self.moduleID ~= moduleID then
moduleIndexes = self.otherModuleIndexes[moduleID]
moduleSkeleton = self.otherOptions[moduleID]
moduleID = '__'..moduleID
player = self.players[name][moduleID]
end
for i = 1, #moduleIndexes do
local dataName = moduleIndexes[i]
if moduleSkeleton[dataName].type == 'string' then
-- inserts "string"
output[#output+1] = '"'
output[#output+1] = player[dataName]
output[#output+1] = '"'
elseif moduleSkeleton[dataName].type == 'number' then
-- inserts number
output[#output+1] = player[dataName]
elseif moduleSkeleton[dataName].type == 'boolean' then
output[#output+1] = player[dataName] and '1' or '0'
elseif moduleSkeleton[dataName].type == 'table' then
-- inserts table
output[#output+1] = '{'
output[#output+1] = turnTableToString(player[dataName])
output[#output+1] = '}'
end
output[#output+1] = ','
end
if output[#output] == ',' then
output[#output] = '}'
else
output[#output+1] = '}'
end
return table.concat(output)
end
output[#output+1] = getPlayerDataFrom(name, self.moduleID)
-- builds the output
if self.otherOptions then
for k,v in pairs(self.otherOptions) do
output[#output+1] = ','
output[#output+1] = getPlayerDataFrom(name, k)
end
end
for k,v in pairs(self.otherData[name]) do
output[#output+1] = ','
output[#output+1] = k
output[#output+1] = '='
output[#output+1] = v
end
return table.concat(output)..self.originalStuff[name]
end
function DataHandler.get(self, name, dataName, moduleName)
-- returns some player data
if not moduleName then
return self.players[name][dataName]
else
assert(self.players[name]['__'..moduleName], 'Module data not available ('..moduleName..')')
return self.players[name]['__'..moduleName][dataName]
end
end
function DataHandler.set(self, name, dataName, value, moduleName)
-- sets some player data
if moduleName then
self.players[name]['__'..moduleName][dataName] = value
else
self.players[name][dataName] = value
end
return self
end
function DataHandler.save(self, name)
-- tbl:set():save("Smth")
system.savePlayerData(name, self:dumpPlayer(name))
end
function DataHandler.getModuleData(self, str)
local output = {}
for moduleID, moduleData in string.gmatch(str, '([0-9A-Za-z_]+)=(%b{})') do
output[moduleID] = moduleData
end
local strCopy = str
for k,v in pairs(output) do
strCopy = strCopy:gsub(k..'='..v:gsub("[%(%)%.%%%+%-%*%?%[%]%^%$]", "%%%0")..',?', '')
end
return output, strCopy
end
local playerData = DataHandler.new(module.id, {
rounds = {
index = 1,
default = 0
},
victories = {
index = 2,
default = 0
},
xp = {
index = 3,
default = 21
},
badges = {
index = 4,
default = 0
},
titles = {
index = 5,
default = { 11, 1, 0, 0 } -- Wearing title ((cat - 1) .. id), Round, Victory, Challenge
},
})
local playerCache = { }
local xpToLvl = function(xp)
local last, total, level, remain, need = 20, 0, 0, 0, 0
for i = 1, 100 do
local nlast = last + (i - ((i < 26 and 1 or i < 46 and 20 or 30)))
local ntotal = total + nlast
if ntotal >= xp then
level, remain, need = i - 1, xp - total, ntotal - xp
return level, remain, need
else
last, total = nlast, ntotal
end
end
end
local lvlToXp = function(lvl)
local last, total = 20, 0
for i = 1, lvl do
last = last + (i - ((i < 26 and 1 or i < 46 and 20 or 30)))
total = total + last
end
return last, total
end
--[[ Maps ]]--
local maps = { 6001536, 6001536, 4591929, "#10" }
local mapHashes = { }
local mapsToAdd = { }
local loading_maps = system.loadFile(module.map_file)
local reloader
reloader = system.newTimer(function()
if not loading_maps then
loading_maps = system.loadFile(module.map_file)
end
end, 1000, true)
--[[ Settings ]]--
-- Status
local players = {
room = { _count = 0 },
alive = { _count = 0 },
currentRound = { _count = 0 }
}
local soloGame = false
local review = false
-- New Game
local cannon = {
x = 0,
y = 0,
time = 2.5,
quantity = 1,
speed = 25,
mul = 1,
}
local toSpawn = {}
local toDespawn = {}
local currentRound = 1
local announceWinner = true
local wasReview = false
local cannonID = {}
local mapSettingsReview = false
-- Hard mode
local hardMode = string.find(tfm.get.room.name, "*?#cannonup%d+hard$") and 2 or 0
-- Data
local canSave
do
local isRoom = string.byte(tfm.get.room.name, 2) ~= 3
canSave = function()
return isRoom and tfm.get.room.uniquePlayers >= module.min_mice and not review and not wasReview
end
end
--[[ API ]]--
math.clamp = function(value, min, max)
return value < min and min or value > max and max or value
end
string.nick = function(player, ignoreCheck)
if not ignoreCheck and not player:find("#") then
player = player .. "#0000"
end
return string.gsub(string.lower(player), "%a", string.upper, 1)
end
string.split = function(value, pattern, f)
local out = {}
for v in string.gmatch(value, pattern) do
out[#out + 1] = (not f and v or f(v))
end
return out
end
system.isPlayer = function(n)
--[[
The player must not be a souris;
The player must have played Transformice for at least 5 days
]]
return not not (string.sub(n, 1, 1) ~= "*" and tfm.get.room.playerList[n] and (os.time() - (tfm.get.room.playerList[n].registrationDate or os.time())) >= 432e6)
end
table.copy = function(list)
local out = {}
for k, v in next, list do
out[k] = (type(v) == "table" and table.copy(v) or v)
end
return out
end
table.merge = function(this, src)
for k, v in next, src do
if this[k] then
if type(v) == "table" then
this[k] = table.turnTable(this[k])
table.merge(this[k], v)
else
this[k] = this[k] or v
end
else
this[k] = v
end
end
end
table.random = function(t, q)
return t[math.random(q or #t)]
end
table.shuffle = function(t)
local len = #t
for i = len, 1, -1 do
local rand = math.random(i)
t[i], t[rand] = t[rand], t[i]
end
return t
end
table.turnTable = function(x)
return (type(x)=="table" and x or {x})
end
local insert = function(where, playerName)
if not where[playerName] and system.isPlayer(playerName) then
where._count = where._count + 1
where[where._count] = playerName
where[playerName] = where._count
end
end
local remove = function(where, playerName)
if where[playerName] then
where._count = where._count - 1
table.remove(where, where[playerName])
for i = where[playerName], where._count do
where[where[i]] = where[where[i]] - 1
end
where[playerName] = nil
end
end
local timer
do
timer = {
_timers = {
_count = 0
}
}
timer.start = function(callback, ms, times, ...)
local t = timer._timers
t._count = t._count + 1
t[t._count] = {
id = t._count,
callback = callback,
args = { ... },
defaultMilliseconds = ms,
milliseconds = ms,
times = times
}
t[t._count].args[#t[t._count].args + 1] = t[t._count]
return t._count
end
timer.delete = function(id)
timer._timers[id] = nil
end
timer.loop = function()
local t
for i = 1, timer._timers._count do
t = timer._timers[i]
if t then
t.milliseconds = t.milliseconds - 500
if t.milliseconds <= 0 then
t.milliseconds = t.defaultMilliseconds
t.times = t.times - 1
t.callback(table.unpack(t.args))
if t.times == 0 then
timer.delete(i)
end
end
end
end
end
end
ui.banner = function(image, aX, aY, n, time)
time = time or 5
aX = aX or 100
aY = aY or 100
local img = tfm.exec.addImage(image .. ".png", "&0", aX, aY, n)
timer.start(tfm.exec.removeImage, time * 1000, 1, img)
end
local xml = {}
xml.parseParameters = function(currentXml)
currentXml = string.match(currentXml, "<P (.-)/>") or ""
local out = {}
for tag, _, value in string.gmatch(currentXml, "([%-%w]+)=([\"'])(.-)%2") do
out[tag] = value
end
return out, currentXml
end
xml.attribFunc = function(currentXml, funcs)
local attributes, properties = xml.parseParameters(currentXml)
for k,v in next, funcs do
if attributes[v.attribute] then
v.func(attributes[v.attribute])
end
end
return properties
end
xml.getCoordinates = function(s)
if string.find(s, ";") then
local x, y
local axis, value = string.match(s, "(%a);(%-?%d+)")
value = tonumber(value)
if value then
if axis == "x" then
x = value
elseif axis == "y" then
y = value
end
end
return x or 0, y or 0
else
local pos = {}
for x, y in string.gmatch(s, "(%-?%d+) ?, ?(%-?%d+)") do
pos[#pos + 1] = { x = x, y = y }
end
return pos
end
end
--[[ System ]]--
-- Translations
for k, v in next, translations do
if k ~= "en" then
table.merge(v, translations.en, true)
end
end
-- Cannon
local getCannon
do
local currentMonth = tonumber(os.date("%m"))
local cannons = { 17, 17, 17, 1706 }
if currentMonth == 1 or currentMonth == 12 then
cannons[#cannons + 1] = 1703 -- Christmas decoration
cannons[#cannons + 1] = 1703
cannons[#cannons + 1] = 1705 -- Apple
elseif currentMonth == 2 then
cannons[#cannons + 1] = 1701 -- Glass
cannons[#cannons + 1] = 1705
cannons[#cannons + 1] = 1706 -- Watermelon
cannons[#cannons + 1] = 1706
elseif currentMonth > 2 and currentMonth < 10 then
if currentMonth == 5 then
cannons[#cannons + 1] = 1704 -- Shaman
cannons[#cannons + 1] = 1704
cannons[#cannons + 1] = 1704
cannons[#cannons + 1] = 1709 -- Light
elseif currentMonth > 5 and currentMonth < 9 then
cannons[#cannons + 1] = 1705
cannons[#cannons + 1] = 1705
cannons[#cannons + 1] = 1710 -- Nut
elseif currentMonth == 9 then
cannons[#cannons + 1] = 1711 -- Flower
end
cannons[#cannons + 1] = 1706
cannons[#cannons + 1] = 1706
elseif currentMonth == 10 then
cannons[#cannons + 1] = 1701
cannons[#cannons + 1] = 1702 -- Lollipop
cannons[#cannons + 1] = 1702
cannons[#cannons + 1] = 1702
cannons[#cannons + 1] = 1707 -- Purple
cannons[#cannons + 1] = 1708 -- Spike
end
getCannon = function()
if #cannonID > 0 then
return table.random(cannonID)
end
return table.random(cannons)
end
end
-- Shoot
local newCannon = function()
if players.alive._count > 0 then
local player
repeat
player = tfm.get.room.playerList[table.random(players.alive, players.alive._count)]
until not player or not player.isDead
if not player then return end
local coordinates = {
{ player.x, math.random() * 700 },
{ player.y, math.random() * 300 },
{ false, false }
}
local id
if type(cannon.x) == "table" then
id = math.random(#cannon.x)
coordinates[1][2] = cannon.x[id]
coordinates[3][1] = true
else
if cannon.x ~= 0 then
coordinates[1][2] = cannon.x
coordinates[3][1] = true
end
end
if type(cannon.y) == "table" then
coordinates[2][2] = cannon.y[id]
coordinates[3][2] = true
else
if cannon.y ~= 0 then
coordinates[2][2] = cannon.y
coordinates[3][2] = true
end
end
if not coordinates[3][2] and coordinates[2][2] > coordinates[2][1] then
coordinates[2][2] = coordinates[2][1] - math.random(100) - 35
end
if not coordinates[3][1] and math.abs(coordinates[1][2] - coordinates[1][1]) > 350 then
coordinates[1][2] = coordinates[1][1] + math.random(-100,100)
end
local ang = math.deg(math.atan2(coordinates[2][2] - coordinates[2][1],coordinates[1][2] - coordinates[1][1]))
tfm.exec.addShamanObject(0, coordinates[1][2] - (coordinates[3][1] and 0 or 10), coordinates[2][2] - (coordinates[3][2] and 0 or 10), ang + 90)
toSpawn[#toSpawn + 1] = { os.time() + 150, getCannon(), coordinates[1][2], coordinates[2][2], ang - 90, cannon.speed }
end
end
-- Valid map code
local mapCode = function(x)
if string.sub(x, 1, 1) == "@" then
x = string.sub(x, 2)
end
local str = x
x = tonumber(x)
return x, not not x and #str > 3
end
-- Unlock title
local unlockTitle = function(playerName, category, id)
tfm.exec.chatMessage("<CH>" .. string.format(translation.unlock, playerName, translation.titles[category][id]))
tfm.exec.chatMessage("<BV>" .. translation.titlecmd, playerName)
end
-- Check title (for round and victory only)
local checkTitle = function(playerName, category)
local titleData = playerData:get(playerName, "titles")
local id = category + 1
local newTitle = titles[category][titleData[id] + 1]
if newTitle and newTitle <= playerData:get(playerName, (category == 1 and "rounds" or "victories")) then
titleData[id] = titleData[id] + 1
playerData:set(playerName, "titles", titleData)
unlockTitle(playerName, category, titleData[id])
save = true
end
playerCache[playerName].titles[id] = titleData[id]
return save
end
--[[ UI ]]--
ui.removeProfile = function(n)
playerCache[n].profile.target = nil
for i = 0, 7 do
ui.removeTextArea(i, n)
end
for i = 1, #playerCache[n].profile do
tfm.exec.removeImage(playerCache[n].profile[i])
end
playerCache[n].profile = { }
end
do
local colors = { owner = "AB5BC2", map = "2ECF73", art = "FE7100", normal = "C1F8FB" }
ui.profile = function(p, n)
if playerCache[n].profile.target then
ui.removeProfile(n)
end
playerCache[n].profile.target = p
playerCache[n].profile[1] = tfm.exec.addImage("165e26f4172.png", ":0", 256, 41, n)
ui.addTextArea(0, "<p align='center'><font size='" .. (#p > 17 and 14 or 18) .. "' color='#" .. colors[(p == module.owner and "owner" or mapEvaluators[p] and "map" or artist[p] and "art" or "normal")] .. "'>" .. (p:gsub("#", "<font size='10'><N2>#", 1)), n, 280, 65, 240, nil, 1, 1, 0, true)
playerCache[n].profile[2] = tfm.exec.addImage("165f818ebff.png", ":1", 290, 108, n) -- 165df8ebe60.png
ui.addTextArea(1, "<font size='16' color='#C1F8FB'>" .. translation.soon, n, 350, 126, 150, nil, 1, 1, 0, true)
local playerLevel, total, remaining = xpToLvl(playerData:get(p, "xp"))
local width = math.clamp(total * (210 / (total + remaining)), 1, 210)
ui.addTextArea(2, "", n, 295, 300, 210, 10, 0x151C2A, 0x00CCFF, 1, true)
ui.addTextArea(3, "", n, 295, 300, width, 10, 0x00CCFF, 0x00CCFF, 1, true)
ui.addTextArea(4, "<font color='#00CCFF'><B>LVL " .. playerLevel, n, 290, 275, 220, nil, 1, 1, 0, true)
ui.addTextArea(5, "<p align='right'><BL>" .. total .. " / " .. (total + remaining) .. " XP", n, 290, 275, 220, nil, 1, 1, 0, true)
ui.addTextArea(6, (p == n and "<a href='event:titles'>" or "") .. "<p align='center'><font size='16' color='#C1F8FB'>«" .. translation.titles[playerCache[p].titles[1][1]][playerCache[p].titles[1][2]] .. "»\n", n, 295, 322, 210, nil, 1, 1, 0, true)
local counter, x = 2, 0
for _, badge in next, playerCache[p].badges do
x = x + 45
counter = counter + 1
playerCache[n].profile[counter] = tfm.exec.addImage(badge, ":2", 248 + x, 240, n)
end
ui.addTextArea(7, "<font size='14' color='#C1F8FB'>" .. translation.profile[1] .. " : <BL>" .. playerData:get(p, "rounds") .. "</BL>\n" .. translation.profile[2] .. " : <BL>" .. playerData:get(p, "victories") .. (counter > 2 and ("</BL>\n<font size='7'>\n</font><p align='center'>" .. translation.profile[3]) or ""), n, 290, 170, 220, nil, 1, 1, 0, true)
end
end
--[[ Events ]]--
-- NewPlayer
eventNewPlayer = function(n)
playerCache[n] = {
ready = false,
profile = { },
badges = { },
titles = { { 1, 1 }, 0, 0, 0 },
afkMaps = 0
}
system.loadPlayerData(n)
insert(players.room, n)
tfm.exec.lowerSyncDelay(n)
tfm.exec.chatMessage("<J>" .. translation.welcome .. "\n\t<ROSE>Discord: https://discord.gg/quch83R", n)
system.bindKeyboard(n, keys.P, true, true)
for i = 0, 3 do
-- Moves not to be AFK
system.bindKeyboard(n, i, true, true)