Advertisement
Tortuegreen

UnlockDoor pv1.0 [v1.4]

Sep 4th, 2015
491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.47 KB | None | 0 0
  1. ------------------------------------------
  2. -- Module : UnlockDoor (par Tortuegreen) --
  3. ------------------------------------------
  4.  
  5. tfm.exec.disableAutoNewGame(true)
  6. tfm.exec.disableAutoScore (true)
  7. tfm.exec.disableAfkDeath (true)
  8. tfm.exec.disableAutoTimeLeft (true)
  9. tfm.exec.disableAutoShaman (true)
  10.  
  11. players = {}
  12. codes = {}
  13. rules = "<p align='center'><font color='#EB1D51' face='DejaVu Sans Mono' size='25'><b>› UnlockDoor ‹</b></font></p>"
  14. .."<p align='center'><font color='#C2C2DA' face='DejaVu Sans Mono' size='18'>C'est très facile à comprendre.</font></p><br>"
  15. .."<p align='center'><font color='#BABD2F' face='DejaVu Sans Mono' size='15'>Vous êtes positionné sur une des 4 lignes où apparaissent 3 portes vous interdisant l'accès au fromage. Pour les désactiver, cliquez sur les portes puis trouvez le code à 4 chiffres.</font></p><br>"
  16. .."<p align='center'><font color='#BABD2F' face='DejaVu Sans Mono' size='15'>Lorsqu'un chiffre est bon, la case devient verte. Lorsque les 4 cases sont bonnes, cliquez sur le nouveau bouton pour dévérouiller la porte. Une seule chose : soyez rapide !</font></p>"
  17. map = '<C><P DS="m;400,-30" /><Z><S><S L="800" H="50" X="400" Y="375" T="6" P="0,0,0.3,0.2,,0,0,0" /><S L="800" X="400" H="50" Y="285" T="6" P="0,0,0.3,0.2,0,0,0,0" /><S L="800" H="50" X="400" Y="195" T="6" P="0,0,0.3,0.2,0,0,0,0" /><S L="800" H="50" X="400" Y="105" T="6" P="0,0,0.3,0.2,0,0,0,0" /><S L="800" X="400" H="50" Y="15" T="6" P="0,0,0.3,0.2,0,0,0,0" /><S P="0,0,0,0,0,0,0,0" L="10" o="6a7495" X="-5" c="3" Y="150" T="14" H="500" /><S H="500" L="10" o="6a7495" X="805" c="3" Y="150" T="14" P="0,0,0,0,0,0,0,0" /></S><D><P X="46" Y="350" T="0" P="1,0" /><P X="247" Y="349" T="11" P="0,0" /><P X="272" Y="349" T="3" P="0,1" /><P X="455" Y="261" T="3" P="0,0" /><P X="298" Y="349" T="11" P="0,0" /><P X="354" Y="349" T="3" P="0,1" /><P X="392" Y="349" T="3" P="0,1" /><T Y="350" X="120" /><P X="546" Y="349" T="12" P="0,0" /><P X="727" Y="348" T="11" P="0,0" /><P X="677" Y="349" T="3" P="0,0" /><P X="700" Y="350" T="5" P="0,1" /><P X="593" Y="350" T="1" P="0,0" /><P P="0,1" Y="170" T="1" X="431" /><T Y="260" X="120" /><T Y="130" X="120" /><T Y="170" X="120" /><T Y="80" X="120" /><F Y="345" X="680" /><F Y="255" X="680" /><F Y="165" X="680" /><F Y="75" X="680" /><P X="220" Y="260" T="1" P="0,1" /><P X="292" Y="260" T="3" P="0,1" /><P X="519" Y="170" T="3" P="0,0" /><P X="296" Y="80" T="3" P="0,0" /><P X="574" Y="79" T="3" P="0,0" /><P X="754" Y="79" T="3" P="0,1" /><P X="717" Y="170" T="3" P="0,0" /><P X="160" Y="260" T="3" P="0,0" /><P X="32" Y="169" T="3" P="0,0" /><P X="297" Y="168" T="3" P="0,0" /><P X="312" Y="169" T="11" P="0,0" /><P X="85" Y="170" T="11" P="0,1" /><P X="35" Y="260" T="11" P="0,1" /><P X="357" Y="80" T="11" P="0,0" /><P X="413" Y="80" T="11" P="0,1" /><P P="0,0" Y="80" T="12" X="620" /><P P="1,0" Y="260" T="0" X="363" /><P P="0,1" Y="80" T="5" X="54" /></D><O /></Z></C>'
  18. bGs = {'F="0"', 'F="1"', 'F="2"', 'F="3"'}
  19. numPlayers = 0
  20. playersWon = 0
  21.  
  22. function updPlayer(name, val)
  23.     if val == nil then
  24.         players[name] = {}
  25.         numPlayers = numPlayers + 1
  26.         players[name].pos = numPlayers
  27.     else
  28.         for i=1,#players do
  29.             if players[i] == name then
  30.                 table.remove(players, i)
  31.             end
  32.         end
  33.     end
  34. end
  35.  
  36. function eventNewPlayer(name)
  37.     updPlayer(name)
  38.     tfm.exec.respawnPlayer (name)
  39. end
  40.  
  41. function eventPlayerLeft(name)
  42.     updPlayer(name, 1)
  43. end
  44.  
  45. function eventPlayerDied(name)
  46.     updPlayer(name, 1)
  47. end
  48.  
  49. function eventPlayerWon(name, tE, tESR)
  50.     playersWon = playersWon + 1
  51.     if playersWon == numPlayers then
  52.         tfm.exec.setGameTime(5, false)
  53.     end
  54. end
  55.  
  56. for name in pairs(tfm.get.room.playerList) do
  57.     updPlayer(name)
  58. end
  59.  
  60. function startNewGame()
  61.     if #players <= 4 then
  62.         tfm.exec.setUIMapName ("<font color='#C2C2DA'>Module :</font> <font color='#BABD2F'>UnlockDoor</font>")
  63.         for i=1,4 do
  64.             _G["codes"]["c1Part"..i] = math.random(9)
  65.             _G["codes"]["c2Part"..i] = math.random(9)
  66.             _G["codes"]["c3Part"..i] = math.random(9)
  67.         end
  68.         for name in pairs(players) do
  69.             tfm.exec.movePlayer(name, 120, 60+90*(players[name].pos-1), false)
  70.             k = players[name].pos
  71.             players[name] = {
  72.                 pos = k,
  73.                 cNumDoor1 = {0,0,0,0},
  74.                 cNumDoor2 = {0,0,0,0},
  75.                 cNumDoor3 = {0,0,0,0},
  76.                 cOkDoor1 = {0,0,0,0},
  77.                 cOkDoor2 = {0,0,0,0},
  78.                 cOkDoor3 = {0,0,0,0},
  79.                 currDoor = 1
  80.             }
  81.             for i=1,3 do
  82.                 tfm.exec.addPhysicObject(players[name].pos*10+i, 200*i, 60+90*(players[name].pos-1), {type=12, restitution=0.2, friction=0.3, width=30, height=40, foreground=true,  groundCollision=true, color=0x1F1709})
  83.                 ui.addTextArea(players[name].pos*10+i, "<p align='center'><br><br><br><font color='#C2C2DA' face='aharoni' size='40'><a href='event:doorIdToRem"..tostring(i).."'>☵</a></font></p>", name, (200*i)-19, (60+90*(players[name].pos-1))-15, width, height, 0, 0, 0, true)
  84.             end
  85.         end
  86.     else
  87.         tfm.exec.newGame(0)
  88.         tfm.exec.setUIMapName ("Trop de joueurs pour lancer le module")
  89.     end
  90. end
  91.  
  92. function eventNewGame()
  93.     ui.addTextArea(150, "<p align='center'><font color='#C2C2DA' face='DejaVu Sans Mono' size='18'><a href='event:openHelp'><b>?</b></a></font></p>", nil, 775, 24, 25, weight, 0x6A7495, 0x6A7495, 1, true)
  94.     players = {}
  95.     numPlayers = 0
  96.     for name in pairs(tfm.get.room.playerList) do
  97.         updPlayer(name)
  98.     end
  99.     startNewGame()
  100. end
  101.  
  102. function eventTextAreaCallback(tAId, name, cb)
  103.     if cb:sub(0,11) == "doorIdToRem" then
  104.         k = cb:sub(12)
  105.         if tonumber(k) == tonumber(players[name].currDoor) then
  106.             ui.removeTextArea(tAId, name)
  107.             ui.addTextArea(100, "", name, 220, 135, 362, 130, 0x010101, 0x010101, 1, true)
  108.             for i=1,4 do
  109.                 ui.addTextArea(tonumber(tAId-k+100+i), "<p align='center'><br><font color='#C2C2DA' face='aharoni' size='20'><a href='event:upArrow"..tostring(tonumber(tAId-k+100+i)).."'><b>∧</b></a></font><br><font color='#C2C2DA' face='aharoni' size='60'>0</font><br><font color='#C2C2DA' face='aharoni' size='20'><a href='event:downArrow"..tostring(tonumber(tAId-k+100+i)).."'><b>∨</b></a></font></p>", name, 225+80*(i-1)+11*(i-1), 140, 80, 120, 0xC51A05, 0x00000, 1, true)
  110.             end
  111.            
  112.         end
  113.     elseif cb:sub(0,7) == "upArrow" then
  114.         k = tAId-110-(players[name].pos-1)*10
  115.         if players[name]["cNumDoor"..players[name].currDoor][k] >= 0 and players[name]["cNumDoor"..players[name].currDoor][k] < 4 or players[name]["cNumDoor"..players[name].currDoor][k] >= 6 and players[name]["cNumDoor"..players[name].currDoor][k] < 9 then
  116.             players[name]["cNumDoor"..players[name].currDoor][k] = players[name]["cNumDoor"..players[name].currDoor][k]+1
  117.             ui.updateTextArea(tAId, "<p align='center'><br><font color='#C2C2DA' face='aharoni' size='20'><a href='event:upArrow"..tostring(tonumber(tAId)).."'><b>∧</b></a></font><br><font color='#C2C2DA' face='aharoni' size='60'>"..players[name]["cNumDoor"..players[name].currDoor][k].."</font><br><font color='#C2C2DA' face='aharoni' size='20'><a href='event:downArrow"..tostring(tonumber(tAId)).."'><b>∨</b></a></font></p>", name)
  118.         elseif players[name]["cNumDoor"..players[name].currDoor][k] == 4 then
  119.             players[name]["cNumDoor"..players[name].currDoor][k] = players[name]["cNumDoor"..players[name].currDoor][k]+1
  120.             ui.updateTextArea(tAId, "<p align='center'><br><font color='#C51A05' face='aharoni' size='20'><b>∧</b></font><br><font color='#C2C2DA' face='aharoni' size='60'>"..players[name]["cNumDoor"..players[name].currDoor][k].."</font><br><font color='#C2C2DA' face='aharoni' size='20'><a href='event:downArrow"..tostring(tonumber(tAId)).."'><b>∨</b></a></font></p>", name)
  121.         elseif players[name]["cNumDoor"..players[name].currDoor][k] == 9 then
  122.             players[name]["cNumDoor"..players[name].currDoor][k] = 0
  123.             ui.updateTextArea(tAId, "<p align='center'><br><font color='#C2C2DA' face='aharoni' size='20'><a href='event:upArrow"..tostring(tonumber(tAId)).."'><b>∧</b></a></font><br><font color='#C2C2DA' face='aharoni' size='60'>"..players[name]["cNumDoor"..players[name].currDoor][k].."</font><br><font color='#C2C2DA' face='aharoni' size='20'><a href='event:downArrow"..tostring(tonumber(tAId)).."'><b>∨</b></a></font></p>", name)
  124.         end
  125.         checkProgress(name, k, players[name]["cNumDoor"..players[name].currDoor][k], players[name].currDoor, tAId)
  126.     elseif cb:sub(0,9) == "downArrow" then
  127.         k = tAId-110-(players[name].pos-1)*10
  128.         if players[name]["cNumDoor"..players[name].currDoor][k] > 0 and players[name]["cNumDoor"..players[name].currDoor][k] <= 5 or players[name]["cNumDoor"..players[name].currDoor][k] > 7 and players[name]["cNumDoor"..players[name].currDoor][k] <= 9 then
  129.             players[name]["cNumDoor"..players[name].currDoor][k] = players[name]["cNumDoor"..players[name].currDoor][k]-1
  130.             ui.updateTextArea(tAId, "<p align='center'><br><font color='#C2C2DA' face='aharoni' size='20'><a href='event:upArrow"..tostring(tonumber(tAId)).."'><b>∧</b></a></font><br><font color='#C2C2DA' face='aharoni' size='60'>"..players[name]["cNumDoor"..players[name].currDoor][k].."</font><br><font color='#C2C2DA' face='aharoni' size='20'><a href='event:downArrow"..tostring(tonumber(tAId)).."'><b>∨</b></a></font></p>", name)
  131.         elseif players[name]["cNumDoor"..players[name].currDoor][k] == 7 then
  132.             players[name]["cNumDoor"..players[name].currDoor][k] = players[name]["cNumDoor"..players[name].currDoor][k]-1
  133.             ui.updateTextArea(tAId, "<p align='center'><br><font color='#C2C2DA' face='aharoni' size='20'><a href='event:upArrow"..tostring(tonumber(tAId)).."'><b>∧</b></a></font><br><font color='#C2C2DA' face='aharoni' size='60'>"..players[name]["cNumDoor"..players[name].currDoor][k].."</font><br><font color='#C51A05' face='aharoni' size='20'><b>∨</b></font></p>", name)
  134.         elseif players[name]["cNumDoor"..players[name].currDoor][k] == 0 then
  135.             players[name]["cNumDoor"..players[name].currDoor][k] = 9
  136.             ui.updateTextArea(tAId, "<p align='center'><br><font color='#C2C2DA' face='aharoni' size='20'><a href='event:upArrow"..tostring(tonumber(tAId)).."'><b>∧</b></a></font><br><font color='#C2C2DA' face='aharoni' size='60'>"..players[name]["cNumDoor"..players[name].currDoor][k].."</font><br><font color='#C2C2DA' face='aharoni' size='20'><a href='event:downArrow"..tostring(tonumber(tAId)).."'><b>∨</b></a></font></p>", name)
  137.         end
  138.         checkProgress(name, k, players[name]["cNumDoor"..players[name].currDoor][k], players[name].currDoor, tAId)
  139.     elseif cb:sub(0,10) == "unlockDoor" then
  140.         ui.removeTextArea(100, name)
  141.         ui.removeTextArea(101, name)
  142.         for i=1,4 do
  143.             ui.removeTextArea(tonumber(100+10*players[name].pos+i), name)
  144.         end
  145.         tfm.exec.removePhysicObject(tonumber(players[name].pos*10+players[name].currDoor))
  146.         players[name].currDoor = players[name].currDoor+1
  147.    
  148.     elseif cb == "openHelp" then
  149.         ui.removeTextArea(150, name)
  150.        
  151.         heightBase = 640
  152.         weightBase = 250
  153.         xBase = math.ceil((800-heightBase)/2)
  154.         yBase = math.ceil((400-weightBase)/2)
  155.        
  156.         ui.addTextArea(151, "", name, xBase, yBase, heightBase, weightBase, 0x2D211A, 0x2D211A, 0.8, true)
  157.         ui.addTextArea(152, "", name, tonumber(xBase+1), tonumber(yBase+1), tonumber(heightBase-2), tonumber(weightBase-2), 0x986742, 0x986742, 1, true)
  158.         ui.addTextArea(153, "", name, tonumber(xBase+4), tonumber(yBase+4), tonumber(heightBase-8), tonumber(weightBase-8), 0x171311, 0x171311, 1, true)
  159.         ui.addTextArea(154, "", name, tonumber(xBase+5), tonumber(yBase+5), tonumber(heightBase-10), tonumber(weightBase-10), 0x0C191C, 0x0C191C, 1, true)
  160.         ui.addTextArea(155, "", name, tonumber(xBase+6), tonumber(yBase+6), tonumber(heightBase-12), tonumber(weightBase-12), 0x24474D, 0x24474D, 1, true)
  161.         ui.addTextArea(156, "", name, tonumber(xBase+7), tonumber(yBase+7), tonumber(heightBase-14), tonumber(weightBase-14), 0x183337, 0x183337, 1, true)
  162.        
  163.         ui.addTextArea(157, "", name, tonumber(xBase+8), tonumber(yBase+8), tonumber(heightBase-16), tonumber(weightBase-16), 0x122528, 0x122528, 1, true)
  164.         ui.addTextArea(158, rules, name, tonumber(xBase+8), tonumber(yBase+8), tonumber(heightBase-16), tonumber(weightBase-50), 0, 0, 0, true)
  165.        
  166.         ui.addTextArea(159, "", name, tonumber(xBase+16), tonumber(yBase+weightBase-33), tonumber(heightBase-34), 18, 0x5D7D90, 0x5D7D90, 1, true)
  167.         ui.addTextArea(160, "", name, tonumber(xBase+18), tonumber(yBase+weightBase-31), tonumber(heightBase-34), 18, 0x11171C, 0x11171C, 1, true)
  168.         ui.addTextArea(161, "<p align='center'><font color='#C2C2DA' size='11'><a href='event:closeHelp'>Fermer cette fenêtre</a></font></p>", name, tonumber(xBase+17), tonumber(yBase+weightBase-32), tonumber(heightBase-34), 18, 0x3C5064, 0x3C5064, 1, true)
  169.        
  170.     elseif cb == "closeHelp" then
  171.         ui.addTextArea(150, "<p align='center'><font color='#C2C2DA' face='DejaVu Sans Mono' size='18'><a href='event:openHelp'><b>?</b></a></font></p>", nil, 775, 24, 25, weight, 0x6A7495, 0x6A7495, 1, true)
  172.         for i=151,161 do
  173.             ui.removeTextArea(i, name)
  174.         end
  175.     end
  176. end
  177.  
  178. function checkProgress(name, numCode, newVal, door, tAId)
  179.     if codes["c"..door.."Part"..numCode] == newVal then
  180.         if players[name]["cOkDoor"..door][numCode] == 0 then
  181.             ui.removeTextArea(tAId, name)
  182.             if newVal >= 0 and newVal <= 4 or newVal >= 7 and newVal <= 9 then
  183.                 ui.addTextArea(tAId, "<p align='center'><br><font color='#C2C2DA' face='aharoni' size='20'><a href='event:upArrow"..tostring(tonumber(tAId)).."'><b>∧</b></a></font><br><font color='#C2C2DA' face='aharoni' size='60'>"..newVal.."</font><br><font color='#C2C2DA' face='aharoni' size='20'><a href='event:downArrow"..tostring(tonumber(tAId)).."'><b>∨</b></a></font></p>", name, 225+80*(numCode-1)+11*(numCode-1), 140, 80, 120, 0x05C506, 0x00000, 1, true)
  184.             elseif newVal == 5 then
  185.                 ui.addTextArea(tAId, "<p align='center'><br><font color='#05C506' face='aharoni' size='20'><b>∧</b></font><br><font color='#C2C2DA' face='aharoni' size='60'>"..newVal.."</font><br><font color='#C2C2DA' face='aharoni' size='20'><a href='event:downArrow"..tostring(tonumber(tAId)).."'><b>∨</b></a></font></p>", name, 225+80*(numCode-1)+11*(numCode-1), 140, 80, 120, 0x05C506, 0x00000, 1, true)
  186.             elseif newVal == 6 then
  187.                 ui.addTextArea(tAId, "<p align='center'><br><font color='#C2C2DA' face='aharoni' size='20'><a href='event:upArrow"..tostring(tonumber(tAId)).."'><b>∧</b></a></font><br><font color='#C2C2DA' face='aharoni' size='60'>"..newVal.."</font><br><font color='#05C506' face='aharoni' size='20'><b>∨</b></font></p>", name, 225+80*(numCode-1)+11*(numCode-1), 140, 80, 120, 0x05C506, 0x00000, 1, true)
  188.             end
  189.             players[name]["cOkDoor"..door][numCode] = 1
  190.         end
  191.     else
  192.         if players[name]["cOkDoor"..door][numCode] == 1 then
  193.             ui.removeTextArea(tAId, name)
  194.             if newVal >= 0 and newVal <= 4 or newVal >= 7 and newVal <= 9 then
  195.                 ui.addTextArea(tAId, "<p align='center'><br><font color='#C2C2DA' face='aharoni' size='20'><a href='event:upArrow"..tostring(tonumber(tAId)).."'><b>∧</b></a></font><br><font color='#C2C2DA' face='aharoni' size='60'>"..newVal.."</font><br><font color='#C2C2DA' face='aharoni' size='20'><a href='event:downArrow"..tostring(tonumber(tAId)).."'><b>∨</b></a></font></p>", name, 225+80*(numCode-1)+11*(numCode-1), 140, 80, 120, 0xC51A05, 0x00000, 1, true)
  196.             elseif newVal == 5 then
  197.                 ui.addTextArea(tAId, "<p align='center'><br><font color='#C51A05' face='aharoni' size='20'><b>∧</b></font><br><font color='#C2C2DA' face='aharoni' size='60'>"..newVal.."</font><br><font color='#C2C2DA' face='aharoni' size='20'><a href='event:downArrow"..tostring(tonumber(tAId)).."'><b>∨</b></a></font></p>", name, 225+80*(numCode-1)+11*(numCode-1), 140, 80, 120, 0xC51A05, 0x00000, 1, true)
  198.             elseif newVal == 6 then
  199.                 ui.addTextArea(tAId, "<p align='center'><br><font color='#C2C2DA' face='aharoni' size='20'><a href='event:upArrow"..tostring(tonumber(tAId)).."'><b>∧</b></a></font><br><font color='#C2C2DA' face='aharoni' size='60'>"..newVal.."</font><br><font color='#C51A05' face='aharoni' size='20'><b>∨</b></font></p>", name, 225+80*(numCode-1)+11*(numCode-1), 140, 80, 120, 0xC51A05, 0x00000, 1, true)
  200.             end
  201.             players[name]["cOkDoor"..door][numCode] = 0
  202.         end
  203.     end
  204.     if players[name]["cOkDoor"..door][1] == 1 and players[name]["cOkDoor"..door][2] == 1 and players[name]["cOkDoor"..door][3] == 1 and players[name]["cOkDoor"..door][4] == 1 then
  205.         ui.addTextArea(101, "<p align='center'><br><font color='#C2C2DA' face='aharoni' size='20'><a href='event:unlockDoor"..tostring(door).."'><b>Déverrouiller !</b></a></font></p>", name, 220, 270, 362, 40, 0x010101, 0x010101, 1, true)
  206.     else
  207.         ui.removeTextArea(101, name)
  208.     end
  209. end
  210.  
  211. function eventLoop(t1, t2)
  212.     if tonumber(math.floor(t2/1000)) == 0 then
  213.         for i=10,145 do
  214.             ui.removeTextArea(i)
  215.         end
  216.         tfm.exec.newGame(map:sub(1,6)..bGs[math.random(#bGs)]..map:sub(7))
  217.     end
  218. end
  219.  
  220. tfm.exec.newGame(map:sub(1,6)..bGs[math.random(#bGs)]..map:sub(7))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement