-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathninjafc.lua
3723 lines (3281 loc) · 156 KB
/
ninjafc.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 roomCreate = os.time()
tfm.exec.setRoomPassword("")
if string.find(tfm.get.room.name, "^[a-z][a-z2]%-#ninja%d+trade%d*$") or string.find(tfm.get.room.name, "^%*?#ninja%d+trade%d*$") then
--[[ File trade.lua ]]--
tfm.exec.disableAutoShaman(true)
tfm.exec.newGame('@4732029')
tfm.exec.disableAutoNewGame(true)
tfm.exec.disableAutoScore(true)
tfm.exec.setGameTime(0)
tfm.exec.disablePhysicalConsumables(true)
tfm.exec.disableMortCommand(true)
ui.setMapName("#trade<")
local trades = {
[[A1 = {
cc = {
['Extremq#0000'] = 20
},
relic = {
['Extrem#0000'] = "D3"
}
}]]
}
-- Init trades
for _, letter in next, {"A", "B", "C", "D", "E", "F"} do
for number = 1, 10 do
trades[letter .. number] = {
['b'] = {},
['s'] = {}
}
end
end
-- Init playerState
local playerState = {
[[playerName = {
_currentRelic = nil,
_popupState = nil,
_offers = {}
}]]
}
local reloadTime = 1800
local startTime = os.time()
local currentTime = 0
function eventLoop(ct, rt)
currentTime = os.time()
local minutes = math.floor((reloadTime * 1000 - (currentTime - startTime))/60000)
local seconds = math.floor((reloadTime * 1000 - (currentTime - startTime))%60000/1000)
if seconds < 10 then seconds = "0"..tostring(seconds) end
ui.setMapName("#trade <G>|</G> <N>Reloading in</N> "..minutes..":"..seconds.."<")
if currentTime - startTime >= reloadTime * 1000 then
emptyTrades()
for name, data in pairs(tfm.get.room.playerList) do
playerState[name] = {
_currentRelic = nil,
_popupState = nil,
_offers = {}
}
updateRelic(name, nil)
end
startTime = currentTime
end
end
function eventNewPlayer(playerName)
tfm.exec.respawnPlayer(playerName)
if playerName:sub(1,1) == "*" then tfm.exec.killPlayer(playerName) end
ui.addTextArea(30, "", playerName, 210, 15, 380, 225, 0x1C3A3E, 0x203F43, 0.5, false)
local buttons = "<p='align'><font face='Lucida Console' size='15'>\n\n "
for _, letter in next, {"A", "B", "C", "D", "E", "F"} do
for j = 1, 10 do
buttons = buttons.."<a href='event:"..letter..j.."'>"..letter..j.."</a> "
end
buttons = buttons.."\n\n "
if letter == "C" then
ui.addTextArea(31, buttons:sub(0, 2000), playerName, 200, 25, 400, 120, 0x1C3A3E, 0xEFCE8F, 0, false)
buttons = "<p='align'><font face='Lucida Console' size='15'> "
end
end
ui.addTextArea(32, buttons:sub(0, 2000), playerName, 200, 145, 400, 120, 0x1C3A3E, 0xEFCE8F, 0, false)
ui.addTextArea(33, "<p align='center'>Selected: <R>none</R></p>", playerName, 200, 25, 400, 16, 0x1C3A3E, 0x1C3A3E, 0, false)
ui.addTextArea(9, "", playerName, -1, 49, 202, 302, 0xEFCE8F, 0xEFCE8F, 0, false)
ui.addTextArea(10, "<p align='center'><font size='20' face='Soopafresh,Verdana'>Buying <a href='event:B'><VP>+</VP></a></font></p><textformat tabstops='0, 50'><V>Price\tName</textformat></V>", playerName, 0, 15, 200, 290, 0x1C3A3E, 0x1C3A3E, 0.5, false)
ui.addTextArea(11, "", playerName, 5, 65, 190, 235, 0x203F43, 0x203F43, 0.7, false)
ui.addTextArea(19, "", playerName, 599, 49, 202, 302, 0xEFCE8F, 0xEFCE8F, 0, false)
ui.addTextArea(20, "<p align='center'><font size='20' face='Soopafresh,Verdana'>Selling <a href='event:S'><VP>+</VP></a></font></p><textformat tabstops='0, 50'><V>Price\tName</textformat></V>", playerName, 600, 15, 200, 290, 0x1C3A3E, 0x1C3A3E, 0.5, false)
ui.addTextArea(21, "", playerName, 605, 65, 190, 235, 0x203F43, 0x203F43, 0.7, false)
playerState[playerName] = {
_currentRelic = nil,
_popupState = nil,
_offers = {}
}
end
for a, b in pairs(tfm.get.room.playerList) do
--tfm.exec.killPlayer(a)
eventNewPlayer(a)
end
function eventPopupAnswer(id, playerName, answer)
local relicType = playerState[playerName]._currentRelic
if not relicType then return end
if id == 50 then
createTrade(playerName, relicType, answer)
end
end
function createTrade(playerName, type, value)
-- We overwrite the current offer the player put anyway
local state = playerState[playerName]._popupState
local invState = 'b'
if state == 'b' then invState = 's' end
-- Offer has a match already
for player, offer in pairs(trades[type][invState]) do
if tostring(offer):upper() == value and player ~= playerName then
tfm.exec.chatMessage("<J>There already is someone that is offering what you want.\n/trade "..player, playerName)
tfm.exec.chatMessage("<J>"..playerName.." wants your offer for "..type..".\n/trade "..playerName, player)
end
end
if value:match("^%d+$") and #value < 4 then
trades[type][state][playerName] = tonumber(value)
elseif value:match("^[A-Fa-f][1-9]0?$") then
trades[type][state][playerName] = value:upper()
else
return
end
playerState[playerName]._offers[type] = true
sendUpdate(type, state)
updateRelic(playerName, type)
playerState[playerName]._popupState = nil
end
function eraseTrade(playerName, type, where)
if trades[type][where][playerName] then
trades[type][where][playerName] = nil
end
if where == 's' then
where = 'b'
else
where = 's'
end
if not trades[type][where][playerName] then
playerState[playerName]._offers[type] = nil
end
sendUpdate(type, playerState[playerName]._popupState)
updateRelic(playerName, type)
playerState[playerName]._popupState = nil
end
function eventTextAreaCallback(id, playerName, event)
if playerName:sub(1,1) == "*" then return end
local relicType = playerState[playerName]._currentRelic
if (id == 31 or id == 32) and event ~= relicType and event:match("^[A-F][1-9]0?$") then
playerState[playerName]._currentRelic = event
updateRelic(playerName, event)
end
if not relicType then return end
if (id == 11 or id == 21) and event ~= playerName then
tfm.exec.chatMessage("<J>/trade "..event, playerName)
tfm.exec.chatMessage("<J>"..playerName.." clicked on one of your offers.", event)
elseif id == 10 then
playerState[playerName]._popupState = "b"
if trades[relicType]['b'][playerName] then
eraseTrade(playerName, relicType, 'b')
else
ui.addPopup(50, 2, "<p align='center'>Set value (number for cheese or relic name).\nExample: 120 or A6</p>", playerName, 300, 150, 200, 100)
end
elseif id == 20 then
playerState[playerName]._popupState = "s"
if trades[relicType]['s'][playerName] then
eraseTrade(playerName, relicType, 's')
else
ui.addPopup(50, 2, "<p align='center'>Set value (number for cheese or relic name).\nExample: 120 or A6</p>", playerName, 300, 150, 200, 100)
end
end
end
function updateRelic(playerName, type)
local buttons = "<p='align'><font face='Lucida Console' size='15'>\n\n "
for _, letter in next, {"A", "B", "C", "D", "E", "F"} do
for j = 1, 10 do
local current = letter..j
local visual = current
if current == type then visual = "<u>"..visual.."</u>" end
if playerState[playerName]._offers[current] then visual = "<BV>"..visual.."</BV>" end
buttons = buttons.."<a href='event:"..current.."'>"..visual.."</a> "
end
buttons = buttons.."\n\n "
if letter == "C" then
buttons = buttons.."</font></p>"
ui.updateTextArea(31, buttons:sub(0, 2000), playerName)
buttons = "<p='align'><font face='Lucida Console' size='15'> "
end
end
buttons = buttons.."</font></p>"
ui.updateTextArea(32, buttons:sub(0, 2000), playerName)
if not type then type = "<R>none</R>" end
ui.updateTextArea(33, "<p align='center'>Selected: <VP>"..type.."</VP></p>", playerName)
if type ~= "<R>none</R>" and trades[type]['b'][playerName] then
ui.updateTextArea(10, "<p align='center'><font size='20' face='Soopafresh,Verdana'>Buying "..type.." <a href='event:B'><R>-</R></a></font></p><textformat tabstops='0, 50'><V>Price\tName</textformat></V>", playerName)
else
ui.updateTextArea(10, "<p align='center'><font size='20' face='Soopafresh,Verdana'>Buying "..type.." <a href='event:B'><VP>+</VP></a></font></p><textformat tabstops='0, 50'><V>Price\tName</textformat></V>", playerName)
end
if type ~= "<R>none</R>" and trades[type]['s'][playerName] then
ui.updateTextArea(20, "<p align='center'><font size='20' face='Soopafresh,Verdana'>Selling "..type.." <a href='event:B'><R>-</R></a></font></p><textformat tabstops='0, 50'><V>Price\tName</textformat></V>", playerName)
else
ui.updateTextArea(20, "<p align='center'><font size='20' face='Soopafresh,Verdana'>Selling "..type.." <a href='event:B'><VP>+</VP></a></font></p><textformat tabstops='0, 50'><V>Price\tName</textformat></V>", playerName)
end
if type == "<R>none</R>" then return end
updateOffers(playerName, type, 's')
updateOffers(playerName, type, 'b')
end
function sendUpdate(relicType, which)
local text = "<textformat tabstops='0, 50'>"
local relicOff = {}
local ccOff = {}
for playerName, offer in pairs(trades[relicType][which]) do
if type(offer) == "string" then
relicOff[#relicOff + 1] = {offer, playerName}
else
ccOff[#ccOff + 1] = {offer, playerName}
end
end
table.sort(relicOff, function(a, b)
return a[1] < b[1]
end)
table.sort(ccOff, function(a, b)
return a[1] < b[1]
end)
if which == "s" then
table.sort(ccOff, function(a, b)
return a[1] < b[1]
end)
else
table.sort(ccOff, function(a, b)
return a[1] > b[1]
end)
end
for i = 1, #ccOff do
text = text..ccOff[i][1].."CC\t<a href='event:"..ccOff[i][2].."'>"..ccOff[i][2]..'</a>\n'
end
for i = 1, #relicOff do
text = text..relicOff[i][1].."\t<a href='event:"..relicOff[i][2].."'>"..relicOff[i][2]..'</a>\n'
end
local id = 11
if which == "s" then id = 21 end
text = text:sub(0, 2000)
print(text)
for playerName, data in pairs(playerState) do
if data._currentRelic == relicType then
ui.updateTextArea(id, text, playerName)
end
end
end
function updateOffers(playerName, relicType, which)
local text = "<textformat tabstops='0, 50'>"
local relicOff = {}
local ccOff = {}
for playerName, offer in pairs(trades[relicType][which]) do
if type(offer) == "string" then
relicOff[#relicOff + 1] = {offer, playerName}
else
ccOff[#ccOff + 1] = {offer, playerName}
end
end
table.sort(relicOff, function(a, b)
return a[1] < b[1]
end)
if which == "s" then
table.sort(ccOff, function(a, b)
return a[1] < b[1]
end)
else
table.sort(ccOff, function(a, b)
return a[1] > b[1]
end)
end
for i = 1, #ccOff do
text = text..ccOff[i][1].."CC\t<a href='event:"..ccOff[i][2].."'>"..ccOff[i][2]..'</a>\n'
end
for i = 1, #relicOff do
text = text..relicOff[i][1].."\t<a href='event:"..relicOff[i][2].."'>"..relicOff[i][2]..'</a>\n'
end
local id = 11
if which == "s" then id = 21 end
text = text:sub(0, 2000)
ui.updateTextArea(id, text, playerName)
end
system.disableChatCommandDisplay(nil, true)
function eventChatCommand(playerName, cmd)
local arg = {}
for argument in cmd:gmatch("[^%s]+") do
arg[#arg + 1] = argument
end
if arg[1]:lower() == "buy" and arg[2]:match("^[A-Fa-f][1-9]0?$") and arg[3] then
print("a")
playerState[playerName]._popupState = 'b'
createTrade(playerName, arg[2], arg[3])
elseif arg[1]:lower() == "sell" and arg[2]:match("^[A-Fa-f][1-9]0?$") and arg[3] then
playerState[playerName]._popupState = 's'
createTrade(playerName, arg[2], arg[3])
end
-- elseif arg[1]:lower() == "delete" and arg[2] then
-- if arg[2]:match("^[A-Fa-f][1-9]0?$") then
-- if playerState[playerName]._offers[arg[2]] then
-- eraseTrade(playerName, arg[2], 's')
-- eraseTrade(playerName, arg[2], 'b')
-- end
-- elseif arg[2] == "all" then
-- for _, relic in pairs(playerState[playerName]._offers) do
-- eraseTrade(playerName, relic, 's')
-- eraseTrade(playerName, relic, 'b')
-- end
-- end
-- end
end
function emptyTrades()
for _, letter in next, {"A", "B", "C", "D", "E", "F"} do
for number = 1, 10 do
trades[letter .. number] = {
['b'] = {},
['s'] = {}
}
end
end
end
--[[ End of file trade.lua ]]--
else
-- LOCALS FOR SPEED
local room = tfm.get.room
local displayParticle = tfm.exec.displayParticle
local movePlayer = tfm.exec.movePlayer
local setNameColor = tfm.exec.setNameColor
local addImage = tfm.exec.addImage
local bindKeyboard = system.bindKeyboard
local chatMessage = tfm.exec.chatMessage
local removeImage = tfm.exec.removeImage
local killPlayer = tfm.exec.killPlayer
local respawnPlayer = tfm.exec.respawnPlayer
local setPlayerScore = tfm.exec.setPlayerScore
local setMapName = ui.setMapName
local random = math.random
local addTextArea = ui.addTextArea
local updateTextArea = ui.updateTextArea
local removeTextArea = ui.removeTextArea
-- RETURN PLAYER ID
function playerId(playerName)
return playerIds[playerName]
end
function removeTag(playerName)
return playerName:gsub("#%d%d%d%d", "")
end
VERSION = "1.6, 18.09.2020"
local translations = {}
--[[ File json.lua ]]--
--
-- json.lua
--
-- Copyright (c) 2019 rxi
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy of
-- this software and associated documentation files (the "Software"), to deal in
-- the Software without restriction, including without limitation the rights to
-- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-- of the Software, and to permit persons to whom the Software is furnished to do
-- so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in all
-- copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
--
local json = { _version = "0.1.2" }
-- NOTE: This is a slightly modified version of the script you will find here:
-- https://github.com/rxi/json.lua
-- It has been modified so it uses less runtime, by making the next functions
-- accessible via a single variable and by disabling some encoding/decoding
-- checks. It is not recommended to use this version if you're not 100% sure your
-- data is totally valid.
local string_format = string.format
local string_byte = string.byte
local table_concat = table.concat
local string_gsub = string.gsub
local string_sub = string.sub
local string_find = string.find
local string_char = string.char
local math_floor = math.floor
-------------------------------------------------------------------------------
-- Encode
-------------------------------------------------------------------------------
local encode
local escape_char_map = {
[ "\\" ] = "\\\\",
[ "\"" ] = "\\\"",
[ "\b" ] = "\\b",
[ "\f" ] = "\\f",
[ "\n" ] = "\\n",
[ "\r" ] = "\\r",
[ "\t" ] = "\\t",
}
local escape_char_map_inv = { [ "\\/" ] = "/" }
for k, v in next, escape_char_map do
escape_char_map_inv[v] = k
end
local function escape_char(c)
return escape_char_map[c] or string_format("\\u%04x", string_byte(c))
end
local function encode_nil(val)
return "null"
end
local function encode_table(val)--, stack)
local res = {}
-- stack = stack or {}
-- Circular reference?
-- if stack[val] then error("circular reference") end
-- stack[val] = true
if rawget(val, 1) ~= nil then-- or next(val) == nil then
-- Treat as array -- check keys are valid and it is not sparse
-- local n = 0
-- for k in next, val do
-- if type(k) ~= "number" then
-- error("invalid table: mixed or invalid key types")
-- end
-- n = n + 1
-- end
-- if n ~= #val then
-- error("invalid table: sparse array")
-- end
-- Encode
for i = 1, #val do
res[i] = encode(val[i])--, stack)
end
--stack[val] = nil
return "[" .. table_concat(res, ",") .. "]"
else
-- Treat as an object
local n = 0
for k, v in next, val do
-- if type(k) ~= "string" then
-- error("invalid table: mixed or invalid key types")
-- end
n = n + 1
res[n] = encode(k) .. ":" .. encode(v)--, stack) .. ":" .. encode(v, stack)
end
--stack[val] = nil
return "{" .. table_concat(res, ",") .. "}"
end
end
local function encode_string(val)
return '"' .. string_gsub(val, '[%z\1-\31\\"]', escape_char) .. '"'
end
local function encode_number(val)
-- Check for NaN, -inf and inf
-- if val ~= val or val <= -math.huge or val >= math.huge then
-- error("unexpected number value '" .. tostring(val) .. "'")
-- end
if val % 1 == 0 then
return tostring(val)
else
return string_format("%.14g", val)
end
end
local type_func_map = {
[ "nil" ] = encode_nil,
[ "table" ] = encode_table,
[ "string" ] = encode_string,
[ "number" ] = encode_number,
[ "boolean" ] = tostring,
}
encode = function(val)--, stack)
return type_func_map[type(val)](val)--, stack)
end
json.encode = encode
-------------------------------------------------------------------------------
-- Decode
-------------------------------------------------------------------------------
local parse
local function create_set(...)
local res = {}
for i = 1, select("#", ...) do
res[ select(i, ...) ] = true
end
return res
end
local space_chars = create_set(" ", "\t", "\r", "\n")
local delim_chars = create_set(" ", "\t", "\r", "\n", "]", "}", ",")
local escape_chars = create_set("\\", "/", '"', "b", "f", "n", "r", "t", "u")
local literals = create_set("true", "false", "null")
local literal_map = {
[ "true" ] = true,
[ "false" ] = false,
[ "null" ] = nil,
}
local function next_char(str, idx, set, negate)
for i = idx, #str do
if set[string_sub(str, i, i)] ~= negate then
return i
end
end
return #str + 1
end
local function decode_error(str, idx, msg)
local line_count = 1
local col_count = 1
for i = 1, idx - 1 do
col_count = col_count + 1
if string_sub(str, i, i) == "\n" then
line_count = line_count + 1
col_count = 1
end
end
error( string_format("%s at line %d col %d", msg, line_count, col_count) )
end
local function codepoint_to_utf8(n)
-- http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=iws-appendixa
if n <= 0x7f then
return string_char(n)
elseif n <= 0x7ff then
return string_char(math_floor(n / 64) + 192, n % 64 + 128)
elseif n <= 0xffff then
return string_char(math_floor(n / 4096) + 224, math_floor(n % 4096 / 64) + 128, n % 64 + 128)
elseif n <= 0x10ffff then
return string_char(math_floor(n / 262144) + 240, math_floor(n % 262144 / 4096) + 128,
math_floor(n % 4096 / 64) + 128, n % 64 + 128)
end
error( string_format("invalid unicode codepoint '%x'", n) )
end
local function parse_unicode_escape(s)
local n1 = tonumber( string_sub(s, 3, 6), 16 )
local n2 = tonumber( string_sub(s, 9, 12), 16 )
-- Surrogate pair?
if n2 then
return codepoint_to_utf8((n1 - 0xd800) * 0x400 + (n2 - 0xdc00) + 0x10000)
else
return codepoint_to_utf8(n1)
end
end
local function parse_string(str, i)
local has_unicode_escape = false
local has_surrogate_escape = false
local has_escape = false
local last
for j = i + 1, #str do
local x = string_byte(str, j)
if x < 32 then
decode_error(str, j, "control character in string")
end
if last == 92 then -- "\\" (escape char)
if x == 117 then -- "u" (unicode escape sequence)
local hex = string_sub(str, j + 1, j + 5)
if not string_find(hex, "%x%x%x%x") then
decode_error(str, j, "invalid unicode escape in string")
end
if string_find(hex, "^[dD][89aAbB]") then
has_surrogate_escape = true
else
has_unicode_escape = true
end
else
local c = string_char(x)
if not escape_chars[c] then
decode_error(str, j, "invalid escape char '" .. c .. "' in string")
end
has_escape = true
end
last = nil
elseif x == 34 then -- '"' (end of string)
local s = string_sub(str, i + 1, j - 1)
if has_surrogate_escape then
s = string_gsub(s, "\\u[dD][89aAbB]..\\u....", parse_unicode_escape)
end
if has_unicode_escape then
s = string_gsub(s, "\\u....", parse_unicode_escape)
end
if has_escape then
s = string_gsub(s, "\\.", escape_char_map_inv)
end
return s, j + 1
else
last = x
end
end
decode_error(str, i, "expected closing quote for string")
end
local function parse_number(str, i)
local x = next_char(str, i, delim_chars)
local s = string_sub(str, i, x - 1)
local n = tonumber(s)
if not n then
decode_error(str, i, "invalid number '" .. s .. "'")
end
return n, x
end
local function parse_literal(str, i)
local x = next_char(str, i, delim_chars)
local word = string_sub(str, i, x - 1)
if not literals[word] then
decode_error(str, i, "invalid literal '" .. word .. "'")
end
return literal_map[word], x
end
local function parse_array(str, i)
local res = {}
local n = 1
i = i + 1
while 1 do
local x
i = next_char(str, i, space_chars, true)
-- Empty / end of array?
if string_sub(str, i, i) == "]" then
i = i + 1
break
end
-- Read token
x, i = parse(str, i)
res[n] = x
n = n + 1
-- Next token
i = next_char(str, i, space_chars, true)
local chr = string_sub(str, i, i)
i = i + 1
if chr == "]" then break end
if chr ~= "," then decode_error(str, i, "expected ']' or ','") end
end
return res, i
end
local function parse_object(str, i)
local res = {}
i = i + 1
while 1 do
local key, val
i = next_char(str, i, space_chars, true)
-- Empty / end of object?
if string_sub(str, i, i) == "}" then
i = i + 1
break
end
-- Read key
if string_sub(str, i, i) ~= '"' then
decode_error(str, i, "expected string for key")
end
key, i = parse(str, i)
-- Read ':' delimiter
i = next_char(str, i, space_chars, true)
if string_sub(str, i, i) ~= ":" then
decode_error(str, i, "expected ':' after key")
end
i = next_char(str, i + 1, space_chars, true)
-- Read value
val, i = parse(str, i)
-- Set
res[key] = val
-- Next token
i = next_char(str, i, space_chars, true)
local chr = string_sub(str, i, i)
i = i + 1
if chr == "}" then break end
if chr ~= "," then decode_error(str, i, "expected '}' or ','") end
end
return res, i
end
local char_func_map = {
[ '"' ] = parse_string,
[ "0" ] = parse_number,
[ "1" ] = parse_number,
[ "2" ] = parse_number,
[ "3" ] = parse_number,
[ "4" ] = parse_number,
[ "5" ] = parse_number,
[ "6" ] = parse_number,
[ "7" ] = parse_number,
[ "8" ] = parse_number,
[ "9" ] = parse_number,
[ "-" ] = parse_number,
[ "t" ] = parse_literal,
[ "f" ] = parse_literal,
[ "n" ] = parse_literal,
[ "[" ] = parse_array,
[ "{" ] = parse_object,
}
parse = function(str, idx)
local chr = string_sub(str, idx, idx)
local f = char_func_map[chr]
if f then
return f(str, idx)
end
decode_error(str, idx, "unexpected character '" .. chr .. "'")
end
function json.decode(str)
if type(str) ~= "string" then
error("expected argument of type string, got " .. type(str))
end
local res, idx = parse(str, next_char(str, 1, space_chars, true))
idx = next_char(str, idx, space_chars, true)
if idx <= #str then
decode_error(str, idx, "trailing garbage")
end
return res
end
--[[ End of file json.lua ]]--
--[[ File string.utf8.lua ]]--
--[[
name: string.utf8.lua
description: Utf8 string handler - credits to Bolodefchoco#0000
]]--
do
-- Based on Luvit's ustring
local charLength = function(byte)
if bit32.rshift(byte, 7) == 0x00 then
return 1
elseif bit32.rshift(byte, 5) == 0x06 then
return 2
elseif bit32.rshift(byte, 4) == 0x0E then
return 3
elseif bit32.rshift(byte, 3) == 0x1E then
return 4
end
return 0
end
local sub, byte = string.sub, string.byte
string.utf8 = function(str)
local utf8str = { }
local index, append = 1, 0
local charLen
for i = 1, #str do
repeat
local char = sub(str, i, i)
local byte = byte(char)
if append ~= 0 then
utf8str[index] = utf8str[index] .. char
append = append - 1
if append == 0 then
index = index + 1
end
break
end
charLen = charLength(byte)
utf8str[index] = char
if charLen == 1 then
index = index + 1
end
append = append + charLen - 1
until true
end
return utf8str
end
end
--[[ End of file string.utf8.lua ]]--
--[[ Directory translations ]]--
--[[ File translations/en.lua ]]--
translations.en = {
name = "en",
lastTime = "Your last time: %ss",
lastBestTime = "Your best time: %ss",
helpToolTip = "<p align='center'>Press <b>H</b> for help.</p>",
optionsYes = "<font color='#53ba58'>Yes</font>",
optionsNo = "<font color='#f73625'>No</font>",
graffitiSetting = "Enable graffitis",
particlesSetting = "Enable dash/jump particles",
timePanelsSetting = "Enable time panels",
globalChatSetting = "Enable global chat",
voteStart = "%s started a vote to skip the current map. Type !yes to vote positively.",
newRecord = "<R>%s finished the map in the fastest time! %ss</R>",
devInfo = "<V>Want to submit a map? Check this link: https://atelier801.com/topic?f=6&t=888399</V>\n<font color='#CB546B'>This module is in development. Please report any bugs to Extremq#0000 or Railysse#0000.</font>",
discordInfo = "<BV>Join our discord! https://discord.gg/WawZVaq</BV>",
welcomeInfo = "Welcome to <font color='#E68D43'>#ninja</font>! Press <font color='#E68D43'>H</font> for help.",
finishedInfo = "You finished the map! (<V>%ss</V>)",
helpBody = "You have to bring the cheese back to the hole as fast as you can.\n\n<b>Abilities</b>:\n» Dash - Press <b><font color='#CB546B'>Left</font></b> or <b><font color='#CB546B'>Right Arrows</font></b> twice. (1s cooldown)\n» Jump - Press <b><font color='#CB546B'>Up Arrow</font></b> twice. (2s cooldown)\n» Rewind - Press <b><font color='#CB546B'>Space</font></b> to leave a checkpoint. Press <b><font color='#CB546B'>Space</font></b> again within 3 seconds to teleport back to the checkpoint. (10s cooldown)\n\n<b>Other shortcuts</b>:\n» Kill the mouse - Press <b><font color='#CB546B'>X</font></b> or write /mort to kill the mouse.\n» Open menu - Press <b><font color='#CB546B'>M</font></b> or click in the left side of your screen to open/close the menu.\n» Place a graffiti - Press <b><font color='#CB546B'>C</font></b> to leave a graffiti. (60s cooldown)\n» Open help - Press <b><font color='#CB546B'>H</font></b> to open/close this screen.\n\n<b>Commands</b>:\n» !p %s - Check the stats of another player.\n» !pw Password - Place a password on the room. (the room must be made by you)\n» !m @code - Load any map you want. (the room must have a password)\n» !langue country - Change the language of the module. (only for you)\n\n<p align='center'><a href='event:CloseMenu'><b><font color='#CB546B'>Close</font></b></a></p>", --23
Xbtn = "X",
shopTitle = "Collection",
profileTitle = "Profile",
leaderboardsTitle = "Leaderboards",
settingsTitle = "Settings",
aboutTitle = "About",
aboutBody = "Module coded by <font color='#FFD991'>Extremq#0000</font>.\nGameplay ideas, bug-testing and maps provided by <font color='#FFD991'>Railysse#0000</font>.\n\nThis module is fully supported by the mice fundation „Red Cheese” with the „Save Module” project. All funds that we will earn will be donated to mice which play #parkour so we can bribe them to play our module.\n\nWe're just kidding, thank you for trying our module! :D\n\n<p align='center'><font color='#f73625'><3</font></p>", -- 30
playtime = "Playtime",
firsts = "Firsts",
finishedMaps = "Completed maps",
firstRate = "First rate",
holeEnters = "Times entered the hole",
graffitiUses = "Graffiti uses",
dashUses = "Times dashed",
timesDoubleJumped = "Double jumps",
rewindUses = "Times rewinded",
hardcoreMaps = "Hardcore maps done",
shopNotice = "The shop is in development.",
leaderboardsNotice = "A leaderboard will be implemented when the module becomes official.",
notValidCommand = "%s is not a valid command or you mistyped an argument.",
cantSetPass = "Cannot set a password in this room.",
translator = "Translated by Extremq#0000.",
version = "Version: %s",
yourLoadout = "Your loadout:",
yourGraffiti = "Your graffiti:",
change = "Change",
select = "Select",
selected = "Selected",
locked = "Locked",
back = "Back",
comingSoon = "Coming soon!",
requirements = "Requirements",
particleUnlock = "<ROSE>You unlocked a new particle! Press M and navigate to Collection to try it.</ROSE>",
graffitiColorUnlock = "<ROSE>You unlocked a new graffiti color! Press M and navigate to Collection to try it.</ROSE>",
graffitiFontUnlock = "<ROSE>You unlocked a new grafitti font! Press M and navigate to Collection to try it.</ROSE>",
free = "Free.",
finishMaps = "Finish %s map(s).",
finishMapsFirst = "Finish %s map(s) first.",
dashTimes = "Dash %s times.",
doubleJumps = "Double jump %s times.",
finishHardcoreMaps = "Finish %s hardcore map(s).",
sprayGraffiti = "Spray a graffiti %s times.",
rewindTimes = "Rewind %s times.",
dontRewind = "<CS>You rewinded, your stats haven't been saved!</CS>",
enoughPlayers = "<V>[•]<BL> There are %s players in this room and all stats are counted!",
notEnoughPlayers = "<V>[•]<BL> More players are needed for some stats to count. [%s/3]",
statsCount = "<V>[•]<BL> All stats are now counted!",
statsDontCount = "<V>[•]<BL> Some stats are not counted!",
--- PARTICLE START
particleDef = "This is the default particle.",
particleHearts = "Add some hearts to your dash!",
particleSleek = "Sleek. Just like you.",
particleLikeNinja = "Wow, you really like playing #ninja.",
particleYouPro = "Cool. You're a pro now.",
particleToSky = "To the sky!",
--- GRAFFITI COLOR START
graffitiColDef = "This is the default graffiti color.",
graffitiColBlack = "You're a dark person.",
graffitiColDarkRed = "Where's this... blood from?",
graffitiColDarkGreen = "If you were a cow you'd love this.",
graffitiColSkyBlue = "We all live under the same sky.",
graffitiColDarkBlue = "Deep enough?",
graffitiColDarkViolet = "Don't drink if you're underage, please.",
graffitiColPink = "^-^",
graffitiColOrange = "Plain old orange.",
graffitiColAlgae = "1.13",
graffitiColLeafGreen = "Breathe in the forest.",
graffitiColYellowRed = "Not orange.",
graffitiColToxicGreen = "Ew, toxic.",
--- GRAFFITI FONT START
graffitiFontDef = "This is the default font for graffitis.",
graffitiFontPapyrus = "You seem old.",
graffitiFontVerdana = "A classic.",
graffitiFontCenturyGothic = "Wow, you're so modern.",
graffitiFontTahoma = "So thin.",
graffitiFontKristenITC = "FunKYyY :d)",
graffitiFontBahnschriftSemiBold = "Clean and professional.",
graffitiFontCourier = "Any mail?",
graffitiFontBookAntiqua = "You would find this in a library...",
graffitiFontFixedSys = "l33t 1s c00l, right?",
graffitiFontImpact = "When you want to make a statement.",
infobarLevel = "Level:",
infobarMice = "Mice:",
infobarHardcore = "<R>HARDCORE</R>",
infobarBlitz = "<J>BLITZ</J>",
infobarTimeOver = "STATISTICS TIME!",
infobarRecord = "Record:",
infobarLoading = "Loading...",
levelUp = "<v>%s</v> <Bl>is now level <J>%s</J>!",
slowestPlayer = "Longest time: ",
mostDeaths = "Most deaths this round: ",
mostAbilities = "Most abilities used this round: ",
--- SENSEI
senseiGreeting1 = "Welcome to #ninja! You’ll have a great time here if you keep practicing!",