×

Langue

Fermer
Atelier 801
  • Forums
  • Dev Tracker
  • Connexion
    • English Français
      Português do Brasil Español
      Türkçe Polski
      Magyar Română
      العربية Skandinavisk
      Nederlands Deutsch
      Bahasa Indonesia Русский
      中文 Filipino
      Lietuvių kalba 日本語
      Suomi עברית
      Italiano Česky
      Hrvatski Slovensky
      Български Latviešu
      Estonian
  • Langue
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • #tfmdraw
#tfmdraw
Klipus
« Citoyen »
1455968160000
    • Klipus#0000
    • Profil
    • Derniers messages
    • Tribu
#1
  0
  • Strona główna
  • Pomoc & komendy
  • Screeny

http://img.atelier801.com/a4a4f06d.jpg


Cześć,
Chciałem wam zaprezentować mój moduł LUA #tfmdraw.
Skrypt ten pozwala Wam na rysowanie w swojej chatce wraz z przyjaciółmi.
Jest on bardzo rozbudowany i posiada wiele funkcji, takich jak:
  • rozbudowana kontrola uprawnień
  • dostosowywanie parametrów pędzla
  • i wiele innych...

Sprawdź sam:
Kod źródłowy

Code 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
-- #tfmdraw - Transformice Drawing Module by Klipus

-- Data
tools_menu_pattern = "<p align='center' ><font size='20' >Tools</font></p><a href='event:clear' >Clear</a>\n<a href='event:undo' >Undo</a>\n\n<a href='event:new' >New</a>\n<a href='event:open' >Open</a>\n<a href='event:save' >Save</a>\n\n<a href='event:pencil' >[$PENCIL$] Pencil</a>\n<a href='event:line' >[$LINE$] Line</a>\n\nSize: $SIZE$ <a href='event:incSize' ><b>+</b></a> <a href='event:decSize' ><b>-</b></a>\nOpacity: $ALPHA$% <a href='event:incAlpha' ><b>+</b></a> <a href='event:decAlpha' ><b>-</b></a>\n\n<font color='#$COLOR$' >&#x2588;&#x2588;&#x2588;&#x2588;</font>\n<a href='event:pickColor' >Select color</a>"
-- Default brush settings
default_settings = {
current_tool = "pencil",
color = 0xFFFFFF,
draw_size = 10,
alpha = 100,
click_no = 0, -- DO NOT CHANGE
first_click_x = 0, -- DO NOT CHANGE
first_click_y = 0 -- DO NOT CHANGE
}
preferredAdmins = {"Klipus"}
room_commands = {"admin", "help"}

ui_map_name = "#tfmdraw by Klipus"

default_map = "@6461433"
current_map = "@6461433"

canvas = {}
data = {}

admins = {}
drawers = {}
banned = {}

pixel_id = 0 -- DO NOT CHANGE
cycle_nr = 0 -- DO NOT CHANGE

ground_id = 69

runmode = ""

program_log = ""

-- Code

-- Logging
function logHide(playerName)
ui.addTextArea(500, "<p align='center' ><a href='event:showLog' >&#x25bc; <J>LOG</J> &#x25bc;</a></p>", playerName, 600, 30, 200, 0, 0x324650, 0x324650, 0.6, true)
end

function logShow(playerName)
ui.addTextArea(500, "<p align='center' ><a href='event:hideLog' >&#x25b2; <J>LOG</J> &#x25b2;</a></p>" .. program_log:sub(0, 2000), playerName, 600, 30, 200, 300, 0x324650, 0x324650, 0.6, true)
end

function logprint(data)
program_log = "[" .. os.date("%X") .. "] " .. tostring(data) .. "\n" .. program_log
end

-- Privileges checking
function isAdmin(playerName)
local isAdmin = false
for i, name in pairs(admins) do
if playerName == name then
isAdmin = true
end
end
return isAdmin
end

function isPreferredAdmin(playerName)
local isPreferredAdmin = false
for i, name in pairs(preferredAdmins) do
if playerName == name then
isPreferredAdmin = true
end
end
return isPreferredAdmin
end

function isDrawer(playerName)
local isDrawer = false
for i, name in pairs(drawers) do
if playerName == name then
isDrawer = true
end
end
return isDrawer
end

function isBanned(playerName)
local isBanned = false
for i, name in pairs(banned) do
if playerName == name then
isBanned = true
end
end
return isBanned
end

-- Load new map
function loadMap(map)
logprint("Loading map " .. tostring(current_map))

tfm.exec.disableAutoShaman(true)
tfm.exec.newGame(map)
tfm.exec.disableAfkDeath(true)
tfm.exec.disableAutoNewGame(true)
tfm.exec.disableAutoScore(true)
tfm.exec.disableAutoShaman(true)
tfm.exec.disableAutoTimeLeft(true)
tfm.exec.setGameTime(0)

ui.setMapName(ui_map_name)
tfm.exec.addPhysicObject(ground_id, 0, 0, {type = 14})
end

-- Book place in data table and bind mouse
function prepareEnv(playerName)
logprint("Setting up environment for player " .. playerName)

data[playerName] = {
current_tool = default_settings.current_tool,
color = default_settings.color,
draw_size = default_settings.draw_size,
alpha = default_settings.alpha,
click_no = default_settings.click_no,
first_click_x = default_settings.first_click_x,
first_click_y = default_settings.first_click_y
}
system.bindMouse(playerName, true)
end

function hideGamePlayerBanned(playerName)
tfm.exec.killPlayer(playerName)
ui.addTextArea(990, "", playerName, -300, -50, 1400, 700, 0x324650, 0x324650, 0.5, true)
ui.addTextArea(991, "<font size='50' ><b><R>BANNED</R></b></font>", playerName, 300, 150, 300, 0, 0x324650, 0x324650, 0, true)
end

function showGamePlayerUnbanned(playerName)
tfm.exec.respawnPlayer(playerName)
ui.removeTextArea(990, playerName)
ui.removeTextArea(991, playerName)
end

-- Handle new player
function eventNewPlayer(playerName)
logprint("New player joined: " .. playerName)

prepareEnv(playerName)

if runmode == "tribe" then
if tfm.get.room.playerList[playerName].tribeName == string.sub(tfm.get.room.name, 3) then
admins[#admins+1] = playerName
drawers[#drawers+1] = playerName
end
elseif runmode == "room" then
-- Room name type: name (#tfmdraw)
for room_type, room_name in string.gmatch(tfm.get.room.name, "(%p+)(%a+)") do
if isPreferredAdmin(playerName) then
admins[#admins+1] = playerName
drawers[#drawers+1] = playerName
end
end

-- Room name type: name + number (#tfmdraw0)
for room_type, room_name, room_number in string.gmatch(tfm.get.room.name, "(%p+)(%a+)(%d+)") do
if isPreferredAdmin(playerName) then
admins[#admins+1] = playerName
drawers[#drawers+1] = playerName
end
end

-- Room name type: name + number + nick (#tfmdraw0Klipus)
for room_type, room_name, room_number, room_owner in string.gmatch(tfm.get.room.name, "(%p+)(%a+)(%d+)(%a+)") do
admins[#admins+1] = room_owner
drawers[#drawers+1] = room_owner
end
end

ui.setMapName(ui_map_name)
tfm.exec.addPhysicObject(ground_id, 0, 0, {type = 14})

ui.addTextArea(1, "", playerName, -130, 30, 125, 300, 0x324650, 0x324650, 1.0, true)
update_toolbar(1, playerName)

if isAdmin(playerName) then
logHide(playerName)
end

if not isBanned(playerName) then
tfm.exec.respawnPlayer(playerName)
else
hideGamePlayerBanned(playerName)
end
end

function eventPlayerLeft(playerName)
logprint("Player " .. playerName .. " left")

for i, name in pairs(admins) do
if name == playerName then
table.remove(admins, i)
break
end
end

for i, name in pairs(drawers) do
if name == playerName then
table.remove(drawers, i)
break
end
end
end

-- Respawn player
function eventPlayerDied(playerName)
if not isBanned(playerName) then
tfm.exec.respawnPlayer(playerName)
end
end

-- Respawn player
function eventPlayerWon(playerName)
if not isBanned(playerName) then
tfm.exec.respawnPlayer(playerName)
end
end

-- Draw single pixel
function drawPixel(pixel_x, pixel_y, pixel_color, pixel_alpha, pixel_size)
-- Joint data
local tab = {
type = 0,
point1 = pixel_x .. "," .. pixel_y,
point2 = pixel_x .. "," .. pixel_y + 1,
line = pixel_size,
color = pixel_color,
alpha = pixel_alpha,
foreground = true
}

pixel_id = pixel_id + 1 -- Increment pixel id
tfm.exec.addJoint(pixel_id, ground_id, ground_id, tab) -- Draw joint
-- Insert pixel into table
canvas[#canvas+1] = {
pixel_type = "P",
pixel_x = pixel_x,
pixel_y = pixel_y,
pixel_color = pixel_color,
pixel_alpha = pixel_alpha,
pixel_size = pixel_size
}
return pixel_id
end

-- Draw single line
function drawLine(line_src_x, line_src_y, line_dst_x, line_dst_y, line_color, line_alpha, line_size)
-- Joint data
local tab = {
type = 0,
point1 = line_src_x .. "," .. line_src_y,
point2 = line_dst_x .. "," .. line_dst_y,
line = line_size,
color = line_color,
alpha = line_alpha,
foreground = true
}

pixel_id = pixel_id + 1 -- Increment pixel id
tfm.exec.addJoint(pixel_id, ground_id, ground_id, tab) -- Draw joint
-- Insert line into table
canvas[#canvas+1] = {
pixel_type = "L",
pixel_x = line_src_x,
pixel_y = line_src_y,
pixel_dst_x = line_dst_x,
pixel_dst_y = line_dst_y,
pixel_color = line_color,
pixel_alpha =line_alpha,
pixel_size = line_size
}
return pixel_id
end

function eventLoop()
if cycle_nr == 4 then
-- Remove welcome popup
ui.removeTextArea(0, nil)

-- Create tools popup
local tools_menu = tools_menu_pattern
tools_menu = tools_menu:gsub("($PENCIL$)", "<font color='#FFFFFF' ><b>*</b></font>")
tools_menu = tools_menu:gsub("($SIZE$)", default_settings.draw_size)
tools_menu = tools_menu:gsub("($COLOR$)", string.format("%X", default_settings.color))
tools_menu = tools_menu:gsub("($ALPHA$)", string.format("%d", default_settings.alpha))
tools_menu = tools_menu:gsub("%$(.-)%$", " ")
ui.addTextArea(1, tools_menu, nil, -130, 30, 125, 300, 0x324650, 0x324650, 1.0, true)
end

cycle_nr = cycle_nr + 1
end

function eventColorPicked(id, playerName, color)
if id == 0 then
data[playerName].color = color
update_toolbar(1, playerName)
end
end

function eventMouse(playerName, x, y)
if not isBanned(playerName) then
if isDrawer(playerName) then
-- Player can draw

-- Number of clicks: usable when need more than one click to do something
data[playerName].click_no = data[playerName].click_no + 1

-- Draw pixel
if data[playerName].current_tool == "pencil" then
drawPixel(x, y, data[playerName].color, tonumber(data[playerName].alpha/100), data[playerName].draw_size, true)
data[playerName].click_no = 0
end

-- Draw line
if data[playerName].current_tool == "line" then
if data[playerName].click_no == 1 then
-- First step: get coordinates of begin of the line
data[playerName].first_click_x = x
data[playerName].first_click_y = y
else
-- Last step: get coordinates of end of the line
-- and draw line
drawLine(data[playerName].first_click_x, data[playerName].first_click_y, x, y, data[playerName].color, tonumber(data[playerName].alpha/100), data[playerName].draw_size, true)
data[playerName].click_no = 0
end
end
end
end
end

-- Update tools popup
function update_toolbar(id, playerName)
local tools_menu = tools_menu_pattern
tools_menu = tools_menu:gsub("($" .. data[playerName].current_tool:upper() .. "$)", "<font color='#FFFFFF' ><b>*</b></font>")
tools_menu = tools_menu:gsub("($SIZE$)", data[playerName].draw_size)
tools_menu = tools_menu:gsub("($COLOR$)", string.format("%X", data[playerName].color))
tools_menu = tools_menu:gsub("($ALPHA$)", string.format("%d", data[playerName].alpha))
tools_menu = tools_menu:gsub("%$(.-)%$", " ")
ui.updateTextArea(id, tools_menu, playerName)
end

-- Make error popup
function popup_error(playerName, msg)
ui.removeTextArea(2, playerName)
content = "<p align='center' ><font size='25' ><b>Error</b></font></p><p align='center' >" .. msg .. "</p><p align='center' ><a href='event:close' ><b>Close</b></a></p>"
ui.addTextArea(2, content, playerName, 250, 150, 300, 100, 0x324650, 0x324650, 1.0, true)
end

function eventChatCommand(playerName, command)
logprint("Player " .. playerName .. " called command: !" .. command)

if command == "admin" then
if isAdmin(playerName) then
logprint("Player " .. playerName .. " called admin panel")
ui.addTextArea(3, "<p align='center' ><font size='25' ><b>Admin Panel</b></font></p><p align='center' ><font size='9' >(scroll for more commands)</font>\n\n<a href='event:adminAddDel' >Add/remove admin</a>\n<a href='event:drawerAddDel' >Add/remove drawer</a>\n<a href='event:banPlayer' >Ban player from room</a>\n<a href='event:changeMap' >Change room map</a>\n<a href='event:viewInfo' >View room info</a>\n</p><p align='center' ><a href='event:close' ><b>Close</b></a></p>", playerName, 250, 150, 300, 150, 0x324650, 0x324650, 1.0, true)
else
popup_error(playerName, "Permission denied")
end
end

if command == "help" then
ui.removeTextArea(99, playerName)
ui.addTextArea(99, "<p align='center' ><font size='25' ><b>Help</b></font></p><p align='center' ><font size='10' >(scroll for more)</font></p>404 Help Not Found\n<p align='center' ><a href='event:close' ><b>Close</b></a></p>", playerName, 100, 50, 600, 300, 0x324650, 0x324650, 1.0, true)
end
end

function eventTextAreaCallback(id, playerName, answer)
-- Tools
if id == 1 then
-- Clear canvas
if answer == "clear" then
if isDrawer(playerName) then
logprint("Player " .. playerName .. " called canvas clear")

canvas = {}
for joint_id = 1,pixel_id do
tfm.exec.removeJoint(joint_id)
end
pixel_id = 0
else
popup_error(playerName, "Permission denied")
end
end

-- Undo last step
if answer == "undo" then
if isDrawer(playerName) then
logprint("Player " .. playerName .. " called undo")

table.remove(canvas, #canvas)
tfm.exec.removeJoint(pixel_id)
if pixel_id > 0 then
pixel_id = pixel_id - 1
end
else
popup_error(playerName, "Permission denied")
end
end

-- Reload current map
if answer == "new" then
if isAdmin(playerName) then
logprint("Player " .. playerName .. " called new map")
canvas = {}
loadMap(current_map)
else
popup_error(playerName, "Permission denied")
end
end

-- Open drawing
if answer == "open" then
if isAdmin(playerName) then
logprint("Player " .. playerName .. " called canvas open")

ui.addPopup(0, 2, "Open (paste drawing data here, empty field to close this window)", playerName, 150, 150, 400, true)
popup_error(playerName, "&#x68;ttp_api_init(): Method Not Implemented")
else
popup_error(playerName, "Permission denied")
end
end

-- Save current drawing
if answer == "save" then
if isAdmin(playerName) then
logprint("Player " .. playerName .. " called canvas save")

file = ""
for index, tbl in pairs(canvas) do
local pixel_type = ""
local pixel_x = 0
local pixel_y = 0
local pixel_dst_x = 0
local pixel_dst_y = 0
local pixel_color = 0x000000
local pixel_alpha = 0.0
local pixel_size = 0

for name, value in pairs(tbl) do
if name == "pixel_type" then
pixel_type = value
elseif name == "pixel_x" then
pixel_x = value
elseif name == "pixel_y" then
pixel_y = value
elseif name == "pixel_dst_x" then
pixel_dst_x = value
elseif name == "pixel_dst_y" then
pixel_dst_y = value
elseif name == "pixel_color" then
pixel_color = value
elseif name == "pixel_alpha" then
pixel_alpha = value
elseif name == "pixel_size" then
pixel_size = value
end
end

if pixel_type == "P" then
file = file .. tostring(pixel_type) .. ":" .. tostring(pixel_x) .. "," .. tostring(pixel_y) .. "," .. string.format("%X", tostring(pixel_color)) .. "," .. tostring(pixel_alpha) .. "," .. tostring(pixel_size) .. ";"
elseif pixel_type == "L" then
file = file .. tostring(pixel_type) .. ":" .. tostring(pixel_x) .. "," .. tostring(pixel_y) .. "," .. tostring(pixel_dst_x) .. "," .. tostring(pixel_dst_y) .. "," .. string.format("%X", tostring(pixel_color)) .. "," .. tostring(pixel_alpha) .. "," .. tostring(pixel_size) .. ";"
end
end

print(file)
popup_error(playerName, "&#x68;ttp_api_init(): Method Not Implemented")
else
popup_error(playerName, "Permission denied")
end
end

-- Pencil tool
if answer == "pencil" then
if data[playerName].current_tool == "pencil" then
data[playerName].current_tool = ""
else
data[playerName].current_tool = "pencil"
end

update_toolbar(id, playerName)
end

-- Line tool
if answer == "line" then
if data[playerName].current_tool == "line" then
data[playerName].current_tool = ""
else
data[playerName].current_tool = "line"
end

update_toolbar(id, playerName)
end

-- Increment size of drawing tool
if answer == "incSize" then
if 50 > data[playerName].draw_size and data[playerName].draw_size > 0 then
data[playerName].draw_size = data[playerName].draw_size + 1
update_toolbar(1, playerName)
end
end

-- Decrement size of drawing tool
if answer == "decSize" then
if 50 >= data[playerName].draw_size and data[playerName].draw_size > 1 then
data[playerName].draw_size = data[playerName].draw_size - 1
update_toolbar(1, playerName)
end
end

-- Increment opacity of drawing tool
if answer == "incAlpha" then
if 100 > data[playerName].alpha and data[playerName].alpha > 0 then
data[playerName].alpha = data[playerName].alpha + 10
update_toolbar(1, playerName)
end
end

-- Decrement opacity of drawing tool
if answer == "decAlpha" then
if 100 >= data[playerName].alpha and data[playerName].alpha > 10 then
data[playerName].alpha = data[playerName].alpha - 10
update_toolbar(1, playerName)
end
end

-- Show color picker
if answer == "pickColor" then
ui.showColorPicker(0, playerName, data[playerName].color, "Select color")
end
end

-- Error popup
if id == 2 then
if answer == "close" then
-- Close error popup
ui.removeTextArea(2, playerName)
end
end

-- Admin panel
if id == 3 then
if answer == "close" then
ui.removeTextArea(3, playerName)
end

if answer == "adminAddDel" then
logprint("Player " .. playerName .. " called admin add/delete")

ui.removeTextArea(3, playerName)

local list = ""
for playerName in pairs(tfm.get.room.playerList) do
if isAdmin(playerName) then
button = "<a href='event:del," .. playerName .. "' ><R>Delete</R></a>"
else
button = "<a href='event:add," .. playerName .. "' ><VP>Add</VP></a>"
end

list = list .. playerName .. " " .. button .. "\n"
end

ui.addTextArea(100, "<p align='center' ><font size='25' ><b>Add or remove admin</b></font></p>" .. list .. "<p align='center' ><a href='event:close' ><b>Close</b></a></p>", playerName, 250, 150, 300, 150, 0x324650, 0x324650, 1.0, true)
end

if answer == "drawerAddDel" then
logprint("Player " .. playerName .. " called drawer add/delete")

ui.removeTextArea(3, playerName)

local list = ""
for playerName in pairs(tfm.get.room.playerList) do
if isDrawer(playerName) then
button = "<a href='event:del," .. playerName .. "' ><R>Delete</R></a>"
else
button = "<a href='event:add," .. playerName .. "' ><VP>Add</VP></a>"
end

list = list .. playerName .. " " .. button .. "\n"
end

ui.addTextArea(101, "<p align='center' ><font size='25' ><b>Add or remove drawer</b></font></p>" .. list .. "<p align='center' ><a href='event:close' ><b>Close</b></a></p>", playerName, 250, 150, 300, 150, 0x324650, 0x324650, 1.0, true)
end

if answer == "banPlayer" then
logprint("Player " .. playerName .. " called player ban/unban")

ui.removeTextArea(3, playerName)

local list = ""
for playerName in pairs(tfm.get.room.playerList) do
if isBanned(playerName) then
button = "<a href='event:unban," .. playerName .. "' ><VP>Unban</VP></a>"
else
button = "<a href='event:ban," .. playerName .. "' ><R>Ban</R></a>"
end

list = list .. playerName .. " " .. button .. "\n"
end

ui.addTextArea(102, "<p align='center' ><font size='25' ><b>Ban or unban player</b></font></p>" .. list .. "<p align='center' ><a href='event:close' ><b>Close</b></a></p>", playerName, 250, 150, 300, 150, 0x324650, 0x324650, 1.0, true)
end

if answer == "changeMap" then
logprint("Player " .. playerName .. " called change map")

ui.removeTextArea(3, playerName)
ui.addPopup(1, 2, "Paste map code below (empty field to close this window)", playerName, 200, 200, 400, true)
end

if answer == "viewInfo" then
ui.removeTextArea(3, playerName)
data = ""

data = data .. "<b>Admins:</b><ul>"
for i, playerName in pairs(admins) do data = data .. "<li>" .. playerName .. "</li>" end
data = data .. "</ul>"

data = data .. "<b>Drawers:</b><ul>"
for i, playerName in pairs(drawers) do data = data .. "<li>" .. playerName .. "</li>" end
data = data .. "</ul>"

data = data .. "<b>Banned:</b><ul>"
for i, playerName in pairs(banned) do data = data .. "<li>" .. playerName .. "</li>" end
data = data .. "</ul>"

ui.addTextArea(4, "<p align='center' ><font size='25' ><b>Room info:</b></font></p><p align='center' ><font size='9' >(scroll for more)</font></p>\n" .. data .. "\n<p align='center' ><a href='event:close' ><b>Close</b></a></p>", playerName, 250, 150, 300, 150, 0x324650, 0x324650, 1.0, true)
end
end

-- Room info
if id == 4 then
if answer == "close" then
ui.removeTextArea(4, playerName)
end
end

-- Help
if id == 99 then
if answer == "close" then
ui.removeTextArea(99, playerName)
end
end

-- Add/Remove admin
if id == 100 then
if answer == "close" then
ui.removeTextArea(100, playerName)
else
ui.removeTextArea(100, playerName)

local str = {}
for chunk in string.gmatch(answer, "([^,]+)") do table.insert(str, chunk) end

if str[1] == "add" then
logprint("Player " .. playerName .. " added admin " .. str[2])
table.insert(admins, str[2])
logHide(str[2])
end

if str[1] == "del" then
for i, v in pairs(admins) do
if str[2] == v then
logprint("Player " .. playerName .. " deleted admin " .. str[2])
table.remove(admins, i)
break
end
end
ui.removeTextArea(500, str[2])
end
end
end

-- Add/Remove drawer
if id == 101 then
if answer == "close" then
ui.removeTextArea(101, playerName)
else
ui.removeTextArea(101, playerName)

local str = {}
for chunk in string.gmatch(answer, "([^,]+)") do table.insert(str, chunk) end

if str[1] == "add" then
logprint("Player " .. playerName .. " added drawer " .. str[2])
table.insert(drawers, str[2])
end

if str[1] == "del" then
for i, v in pairs(drawers) do
if str[2] == v then
logprint("Player " .. playerName .. " deleted drawer " .. str[2])
table.remove(drawers, i)
break
end
end
end
end
end

-- Ban/Unban player
if id == 102 then
if answer == "close" then
ui.removeTextArea(102, playerName)
else
ui.removeTextArea(102, playerName)

local str = {}
for chunk in string.gmatch(answer, "([^,]+)") do table.insert(str, chunk) end

if str[1] == "ban" then
logprint("Player " .. playerName .. " banned player " .. str[2])
table.insert(banned, str[2])
hideGamePlayerBanned(str[2])
end

if str[1] == "unban" then
for i, v in pairs(banned) do
if str[2] == v then
logprint("Player " .. playerName .. " unbanned player " .. str[2])
table.remove(banned, i)
break
end
end
showGamePlayerUnbanned(str[2])
end
end
end

-- Log
if id == 500 then
if answer == "showLog" then
ui.removeTextArea(500, playerName)
logShow(playerName)
elseif answer == "hideLog" then
ui.removeTextArea(500, playerName)
logHide(playerName)
end
end
end

function eventPopupAnswer(id, playerName, answer)
-- Load drawing
if id == 0 then
if answer ~= "" then
logprint("Player " .. playerName .. " loaded new drawing")

-- Clear canvas
canvas = {}
for joint_id = 1,pixel_id do
tfm.exec.removeJoint(joint_id)
end
pixel_id = 0

-- Draw pixels from drawing
for data in string.gmatch(answer, "([^;]+)") do
for pixel_type, pixel_data in string.gmatch(data, "([^:]+):([^:]+)") do
if pixel_type == "P" then
for x, y, color, alpha, size in string.gmatch(pixel_data, "(%d+),(%d+),(%x+),(%d+),(%d+)") do
drawPixel(x, y, tonumber("0x" .. color), alpha, size)
end
elseif pixel_type == "L" then
for x, y, dst_x, dst_y, color, alpha, size in string.gmatch(pixel_data, "(%d+),(%d+),(%d+),(%d+),(%x+),(%d+),(%d+)") do
drawLine(x, y, dst_x, dst_y, tonumber("0x" .. color), alpha, size)
end
end
end
end
end
end

-- Change map
if id == 1 then
current_map = answer
logprint("Player " .. playerName .. " changed current map to: " .. tostring(current_map))
loadMap(current_map)
end
end

function eventNewGame()
if tfm.get.room.xmlMapInfo.mapCode == current_map then
loadMap(current_map)
end
end

-- Script init
logprint("Program started")

-- Load new map
loadMap(default_map)

-- Create welcome popup
ui.addTextArea(0, "<p align='center' ><font size='35' face='Comic Sans MS' ><j>TFM Draw</j></font></p><p align='center' ><font>Transformice drawing module\n</font></p><p align='right' ><i><t>by Klipus</t></i></p>", nil, 250, 150, 300, 100, 0x324650, 0x324650, 1.0, true)

-- Check room type
if string.find(tfm.get.room.name, "*"..string.char(3)) then
-- Tribe House
runmode = "tribe"

-- Grant permissions to all players in room
for playerName in pairs(tfm.get.room.playerList) do
if tfm.get.room.playerList[playerName].tribeName == string.sub(tfm.get.room.name, 3) then
admins[#admins+1] = playerName
drawers[#drawers+1] = playerName
end
end
else
-- Public room
runmode = "room"

-- Room name type: name (#tfmdraw)
for room_type, room_name in string.gmatch(tfm.get.room.name, "(%p+)(%a+)") do
for i, preferredAdminPlayerName in pairs(preferredAdmins) do
admins[#admins+1] = preferredAdminPlayerName
drawers[#drawers+1] = preferredAdminPlayerName
end
end

-- Room name type: name + number (#tfmdraw0)
for room_type, room_name, room_number in string.gmatch(tfm.get.room.name, "(%p+)(%a+)(%d+)") do
for i, preferredAdminPlayerName in pairs(preferredAdmins) do
admins[#admins+1] = preferredAdminPlayerName
drawers[#drawers+1] = preferredAdminPlayerName
end
end

-- Room name type: name + number + nick (#tfmdraw0Klipus)
for room_type, room_name, room_number, room_owner in string.gmatch(tfm.get.room.name, "(%p+)(%a+)(%d+)(%a+)") do
admins[#admins+1] = room_owner
drawers[#drawers+1] = room_owner
end
end

logprint("Room type: " .. runmode)

-- Hide special room commands
for i, command in pairs(room_commands) do
system.disableChatCommandDisplay(command, true)
end

logprint("Preparing data")

-- Book place in data table and bind mouse to all players in room
for playerName in pairs(tfm.get.room.playerList) do
prepareEnv(playerName)
end

-- Show log popup for admins
for i, playerName in pairs(admins) do
logHide(playerName)
end

tfm.exec.chatMessage("<J>Welcome in #tfmdraw room</J>", nil)
tfm.exec.chatMessage("<BL>!help</BL> <N>for help</N>", nil)


Uwaga! Jeśli przy pierwszym uruchomieniu skryptu nie załadowała się ta mapa, to załaduj skrypt ponownie!
Skrypt jest jeszcze bardzo nowy i posiada troszkę bugów.

Zaglądaj tu często, aby być pewnym, że używasz najnowszej wersji modułu! :)
Pasek z narzędziami:

    Zarządzanie rysunkiem:
  • Clear - czyści mapę
  • Undo - cofa ostatni krok
  • New - przeładowuje mapę
  • Open - otwiera rysunek - funkcja niedostępna
  • Save - zapisuje rysunek - funkcja niedostępna

  • Narzędzia:
  • Pencil - wybierz to narzędzie, aby rysować pojedyncze piksele
  • Line - wybierz to narzędzie, aby rysować linie
    (pierwsze kliknięcie: początek linii, drugie kliknięcie: koniec linii)

  • Opcje narzędzia:
  • Size - dostosuj rozmiar narzędzia przyciskami + i -
  • Opacity - dostosuj przezroczystość narzędzia przyciskami + i -
  • Select color - kliknij, aby otworzyć paletę barw i wybrać kolor, w którym chcesz rysować

http://img.atelier801.com/bb24f06d.png

Komendy:
!admin - jest to swego rodzaju panel administracyjny, z którego
możemy zarządzać uprawnieniami poszczególnych graczy lub zmienić
mapę, na której będzie się rysować
  • Add/remove admin - w tym miejscu możemy dodawać/usuwać adminów roomu
    Uprawnienia admina:
    • dostęp do tej komendy
    • funkcje New, Open i Save
  • Add/remove drawer - w tym miejscu możemy dodawać/usuwać osoby rysujące
    Uprawnienia drawera:
    • rysowanie na mapie
    • funckcje Clear i Undo
  • Ban player from room - tutaj można zbanować niechcianego gracza.
    Nie będzie on mógł rysować i ukaże mu się mniej więcej taki widok:
    http://img.atelier801.com/ba24f06d.png
  • Change room map - tutaj możemy zmienić mapę, na której rysujemy
  • View room info - funkcja używana do debugowania skryptu

http://img.atelier801.com/bba4f06d.png

http://img.atelier801.com/baa4f06d.png

http://img.atelier801.com/ba24f06d.png

Dernière modification le 1489350840000
Robcikpl
« Censeur »
1455968220000
    • Robcikpl#0000
    • Profil
    • Derniers messages
#2
  0
Wspaniałe
Pegazmysz
« Consul »
1455968400000
    • Pegazmysz#0000
    • Profil
    • Derniers messages
    • Tribu
#3
  0
Dobra robota C:
Barciomysz
« Citoyen »
1455968700000
    • Barciomysz#0000
    • Profil
    • Derniers messages
    • Tribu
#4
  0
Bardzo fajny kod :D
Xpq
« Censeur »
1455969060000
    • Xpq#2943
    • Profil
    • Derniers messages
#5
  0
świetne :D
Sebafrancuz
« Consul »
1455970080000
    • Sebafrancuz#0000
    • Profil
    • Derniers messages
    • Tribu
#6
  0
Ciekawy skrypt.
Aranea
« Consul »
1455970680000
    • Aranea#1648
    • Profil
    • Derniers messages
    • Tribu
#7
  0
Świetnie Ci poszło! Skorzystam :)
Klipus
« Citoyen »
1455972120000
    • Klipus#0000
    • Profil
    • Derniers messages
    • Tribu
#8
  0
Dzięki za podziękowania! :D
Nullalkeed
« Consul »
1455972480000
    • Nullalkeed#1259
    • Profil
    • Derniers messages
    • Tribu
#9
  0
Używaliśmy w chatce. Wojny na kolorowanie tutaj są najlepsze! xd
Klipus
« Citoyen »
1455972600000
    • Klipus#0000
    • Profil
    • Derniers messages
    • Tribu
#10
  0
Nom 8) ^
http://i.imgur.com/Mq3Kooi.png
Klakser
« Consul »
1455982800000
    • Klakser#0000
    • Profil
    • Derniers messages
    • Tribu
#11
  0
to jest super!
Szczurb
« Censeur »
1456146000000
    • Szczurb#5147
    • Profil
    • Derniers messages
    • Tribu
#12
  0
Świetny kod :)
Eli
« Consul »
1456147980000
    • Eli#7850
    • Profil
    • Derniers messages
    • Tribu
#13
  0
ooo wkońcu :D
Unicornvikey
« Citoyen »
1456151400000
    • Unicornvikey#0000
    • Profil
    • Derniers messages
    • Tribu
#14
  0
Ale super, na pewno wypróbuje. ^^
Klipus
« Citoyen »
1461525540000
    • Klipus#0000
    • Profil
    • Derniers messages
    • Tribu
#15
  0
Po blisko dwóch miesiącach pojawia się nowa wersja skryptu #tfmdraw.
Oto kilka nowości w tej wersji:

  • poprawiono kilka błędów
  • poprawiono czytelnośc kodu
  • dodano mechanizm logowania aktywności
  • lepsze zarządzanie uprawnieniami

Zapraszam do wypróbowania nowej wersji (link w #1 poście)
Rkubi
« Censeur »
1461591660000
    • Rkubi#0000
    • Profil
    • Derniers messages
    • Tribu
#16
  0
Fajny kod.
Kingapysia
« Consul »
1461602400000
    • Kingapysia#0000
    • Profil
    • Derniers messages
    • Tribu
#17
  0
Brawo Kli x)
Pastel_doll
« Citoyen »
1468744020000
    • Pastel_doll#2437
    • Profil
    • Derniers messages
#18
  0
SUPER GRAA! tylko nie mogę innym dać rysowania

Dernière modification le 1468930020000
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • #tfmdraw
© Atelier801 2018

Equipe Conditions Générales d'Utilisation Politique de Confidentialité Contact

Version 1.27