Tectoon

[TFM] Pallete Multiplayers

Jun 25th, 2015
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.67 KB | None | 0 0
  1. ---
  2. -- Palette+
  3. ---
  4.  
  5. local LANG = 'EN'
  6. local CLEANER = 'Transforlays'
  7. local help = {
  8.     TR = [[<textformat tabstops="[150]"><R><p align="center"><R>1<VP>2<G>3<font color="#E88F4F">4<J>5<V>6<ROSE>7<CH>8<T>9
  9. <p align="left">
  10. <N>Fırça kenar rengin <font color="#%x">
  11. <VP>Yön tuşları/Numpad   <N>Fırça kontrolü
  12. <VP>Boşluk/Numpad 0    <N>Sil (Basılı tutabilirsin)
  13. <VP>Ctrl/Numpad 5   <N>Boya (Basılı tutabilirsin)
  14. <G>!c [renk]    <N>Renk değiştirme
  15. <G>!!   <N>Ekranı temizle
  16. <p align="center"><font size="11">
  17. <BL>Oyuncu listesini görmek için <VP>P <BL>tuşuna basılı tut
  18. Bu ekranı görmek için <VP>Shift <BL>tuşuna basılı tut]],
  19.     EN = [[<textformat tabstops="[150]"><R><p align="center"><R>1<VP>2<G>3<font color="#E88F4F">4<J>5<V>6<ROSE>7<CH>8<T>9
  20. <p align="left">
  21. <N>Your brush border color  <font color="#%x">
  22. <VP>Arrow keys/Numpad   <N>Brush control
  23. <VP>Space/Numpad 0  <N>Erase (You can hold it)
  24. <VP>Ctrl/Numpad 5   <N>Paint (You can hold it)
  25. <G>!c [color]   <N>Change color
  26. <G>!!   <N>Clear the screen
  27. <p align="center"><font size="11">
  28. <BL>Hold <VP>P <BL>key to see player list
  29. Hold <VP>Shift <BL>key to make this screen appear]] }
  30. local colors = { 0xCB546B, 0x2ECF73, 0x606090, 0xE88F4F, 0xBABD2F, 0x009D9D, 0xED67EA, 0x98E2EB, 0xA4CF9E }
  31. local colorStr, playerStr = {}, ''
  32. local pixels, brushX, brushY, brushC, brushD, eraserD, brushB, brushI = {}, {}, {}, {}, {}, {}, {}, { -10 }
  33. function init()
  34.     tfm.exec.disableAutoNewGame(true)
  35.     tfm.exec.disableAfkDeath(true)
  36.     tfm.exec.disableAutoShaman(true)
  37.     system.disableChatCommandDisplay('c')
  38.     system.disableChatCommandDisplay('!')
  39.  
  40.     for i=1, 9 do
  41.         getColorStr(colors[i])
  42.     end
  43.     for n in pairs(tfm.get.room.playerList) do
  44.         eventNewPlayer(n, true)
  45.     end
  46.  
  47.     makePlayerStr()
  48.     tfm.exec.newGame([[<C><P /><Z><S><S X="400" o="0" L="50" Y="180" H="10" P="0,0,0.3,0.2,0,0,0,0" T="12" /><S X="400" o="0" L="50" Y="220" H="10" P="0,0,0.3,0.2,0,0,0,0" T="12" /><S X="370" o="0" L="10" Y="200" H="50" P="0,0,0.3,0.2,0,0,0,0" T="12" /><S X="430" o="0" L="10" Y="200" H="50" P="0,0,0.3,0.2,0,0,0,0" T="12" /></S><D><DS X="400" Y="200" /></D><O /></Z></C>]])
  49. end
  50. function showHelp(name)
  51.     ui.addTextArea(-2, help[LANG]:format(brushB[name]), name, 250, 100, 300, nil, 1, 1, 0.8, true)
  52. end
  53. function updateBrush(name, x, y)
  54.     if brushI[name] then
  55.         local x, y = (x < 0 and 79 or x), (y < 1 and 38 or y)
  56.         x, y = (x > 79 and 0 or x), (y > 38 and 1 or y)
  57.         brushX[name], brushY[name] = x, y
  58.         ui.addTextArea(brushI[name], '', nil, x*10 + 4, y*10 + 7, 10, 10, brushC[name], brushB[name], 0.5)
  59.     end
  60. end
  61. function getColorStr(c)
  62.     if colorStr[c] == nil then
  63.         colorStr[c] = string.format('<font size="14" font="Verdana" color="#%x">■', c)
  64.     end
  65.     return colorStr[c]
  66. end
  67. function fillBlock(x, y, c)
  68.     if x >= 0 and y > 0 and x < 80 and y < 39 then
  69.         local i = x*79 + y
  70.         if c then
  71.             local c = getColorStr(c)
  72.             ui.addTextArea(i, c, nil, x*10, y*10, nil, nil, 0, 0, 0)
  73.             pixels[i] = c
  74.         else
  75.             ui.removeTextArea(i)
  76.             pixels[i] = nil
  77.         end
  78.     end
  79. end
  80. function makePlayerStr(name)
  81.     if name then
  82.         if #playerStr < 1976 then
  83.             playerStr = string.format('%s<font color="#%x">%s\t\n', playerStr, brushB[name], name):sub(1,2e3)
  84.         end
  85.     else
  86.         local s, i = { '<textformat tabstops="[180]"><font size="11" font="Verdana">' }, 2
  87.         for n,c in pairs(brushB) do
  88.             s[i] = string.format('<font color="#%x">%s\t\n', c, n)
  89.             i = 1 + i
  90.         end
  91.         playerStr = table.concat(s):sub(1, 2e3)
  92.     end
  93. end
  94. function eventNewGame()
  95.     tfm.exec.setUIMapName("Lays' Palette+")
  96. end
  97. function eventNewPlayer(name, init)
  98.     ui.addTextArea(-1, '', name, -100, -100, 1000, 600, 0x6A7495, 0x6A7495, 1)
  99.  
  100.     if brushI[name] == nil then
  101.         brushI[1] = -1 + brushI[1]
  102.         brushC[name] = colors[math.random(1, 9)]
  103.         brushI[name] = brushI[1]
  104.     end
  105.     brushB[name] = math.random(0xff, 0xff0000)
  106.  
  107.     updateBrush(name, math.random(20, 60),  math.random(10, 30))
  108.     system.bindMouse(name, true)
  109.     showHelp(name)
  110.  
  111.     if init == nil then
  112.         makePlayerStr(name)
  113.         eventNewGame()
  114.         for i, c in pairs(pixels) do
  115.             ui.addTextArea(i, c, name, math.floor(i/79) * 10, (i%79) * 10, nil, nil, 0, 0, 0)
  116.         end
  117.         for n, b in pairs(brushB) do
  118.             ui.addTextArea(brushI[n], '', nil, brushX[n]*10 + 4, brushY[n]*10 + 7, 10, 10, brushC[n], b, 0.5)
  119.         end
  120.     end
  121.  
  122.     for _, key in pairs({ 16, 17, 32, 37, 38, 39, 40, 49, 50, 51, 52, 53, 54, 55, 56, 57, 80, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105 }) do
  123.         tfm.exec.bindKeyboard(name, key, true, true)
  124.     end
  125.     for _, key in pairs({ 16, 17, 32, 80, 96, 101 }) do
  126.         tfm.exec.bindKeyboard(name, key, false, true)
  127.     end
  128. end
  129. function eventPlayerLeft(name)
  130.     ui.removeTextArea(brushI[name])
  131.     brushB[name] = nil
  132.     makePlayerStr()
  133. end
  134. function eventMouse(name, x, y)
  135.     local x, y = math.floor((x-7)/10), math.floor((y-7)/10)
  136.     x = math.min(79, math.max(0, x))
  137.     y = math.min(38, math.max(1, y))
  138.     updateBrush(name, x, y)
  139.     if brushD[name] then
  140.         fillBlock(x, y, brushC[name])
  141.     elseif eraserD[name] then
  142.         fillBlock(x, y)
  143.     end
  144. end
  145. function eventKeyboard(name, key, down)
  146.     local x, y = brushX[name], brushY[name]
  147.     if key == 16 then
  148.         if down then
  149.             showHelp(name)
  150.         else
  151.             ui.removeTextArea(-2, name)
  152.         end
  153.     elseif key == 80 then
  154.         if down then
  155.             ui.addTextArea(-3, playerStr, name, 10, 20, 200, nil, 1, 0, 0.8, true)
  156.         else
  157.             ui.removeTextArea(-3, name)
  158.         end
  159.     elseif key == 17 or key == 101 then
  160.         brushD[name] = down
  161.         if down then
  162.             fillBlock(x, y, brushC[name])
  163.         end
  164.     elseif key == 32 or key == 96 then
  165.         eraserD[name] = down
  166.         if down then
  167.             fillBlock(x, y)
  168.         end
  169.     elseif (key > 36 and key < 41) or (key > 96 and key < 106) then
  170.         if key == 37 or key == 97 or key == 100 or key == 103 then
  171.             x = -1 + x
  172.         elseif key == 39 or key == 99 or key == 102 or key == 105 then
  173.             x = 1 + x
  174.         end
  175.         if key == 38 or key == 103 or key == 104 or key == 105 then
  176.             y = -1 + y
  177.         elseif key == 40 or key == 97 or key == 98 or key == 99 then
  178.             y = 1 + y
  179.         end
  180.         updateBrush(name, x, y)
  181.         if brushD[name] then
  182.             fillBlock(x, y, brushC[name])
  183.         elseif eraserD[name] then
  184.             fillBlock(x, y)
  185.         end
  186.     elseif key > 48 and key < 58 then
  187.         brushC[name] = colors[key - 48]
  188.         updateBrush(name, x, y)
  189.     end
  190. end
  191. function eventChatCommand(name, cmd)
  192.     if '!' == cmd and CLEANER == name then
  193.         local l, n = {}, 0
  194.         for k in pairs(pixels) do
  195.             ui.removeTextArea(k)
  196.             n = 1 + n
  197.             l[n] = k
  198.         end
  199.         for i=1, n do
  200.             pixels[l[i]] = nil
  201.         end
  202.     elseif 'c ' == cmd:sub(1,2) then
  203.         local cl = cmd:sub(3)
  204.         if '#' == cl:sub(1,1) then
  205.             cl = '0x' .. cl:sub(2)
  206.         end
  207.         brushC[name] = tonumber(cl) or brushC[name]
  208.         updateBrush(name, brushX[name], brushY[name])
  209.     end
  210. end
  211. init()
Advertisement
Add Comment
Please, Sign In to add comment