Advertisement
Rakmaar

Untitled

Jul 22nd, 2019
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.12 KB | None | 0 0
  1. -- tous crédits de code d'origine à Adsl_Houba
  2. -- https://www.youtube.com/user/MrAdslHouba/
  3. -- adaptations faites pour la commande de spawners par Rakmaar
  4. -- commentaires par Rakmaar
  5.  
  6. term=peripheral.find('monitor') -- cherche les moniteurs adjacents
  7. term.setBackgroundColor(colors.black) -- couleur de fond des moniteurs
  8. term.clear() -- vide le terminal
  9.  
  10. premierX=1 -- Premier X                 --
  11. premierY=1 -- Premier Y                 --
  12. largeur=9  -- Largeur bouton            -- definit les variable de positionnement de boutons
  13. hauteur=5  -- Hauteur bouton            -- ne modifier qu'en cas de mauvais alignement
  14. ligneY=3 -- hauteur du texte            --
  15. marge=1    -- Marge entre deux boutons  --
  16. coteRed="front"
  17.  
  18.  
  19. liste={                                 -- definit les boutons: nom affiché et couleur du canal redstone cible
  20.     {
  21.         nom='Endermen',
  22.         color=colors.yellow,
  23.         choix=true
  24.     },
  25.     {
  26.         nom='Emeraude',
  27.         color=colors.blue,
  28.         choix=true
  29.     },
  30.     {
  31.         nom='Moutons',
  32.         color=colors.white,
  33.         choix=true
  34.     },
  35.     {
  36.         nom='Wither',
  37.         color=colors.red,
  38.         choix=true
  39.     },
  40. }
  41.  
  42. function actuWin(i)                                     -- fonction d'actualisation des moniteurs sur clic
  43.     if liste[i].choix then
  44.         liste[i].win.setBackgroundColor(colors.red)     -- couleur quand signal redstone envoyé
  45.     else                                                --          = spawner off
  46.         liste[i].win.setBackgroundColor(colors.green)   -- couleur quand pas de signal redstone sortant
  47.     end                                                 --          = spawner on
  48.     liste[i].win.clear()
  49.     liste[i].win.setCursorPos(1+math.floor((largeur-string.len(liste[i].nom))/2),ligneY)
  50.     liste[i].win.write(liste[i].nom)
  51. end
  52. function actuRed()                                      -- controle d'etat, ne pas toucher
  53.     redsTous=0                                          -- si vous ne savez pas ce que vous faites
  54.     table.foreach(liste,function(i,data)
  55.         if liste[i].choix==false then
  56.             redsTous=redsTous+liste[i].color
  57.         end
  58.     end)
  59.     redstone.setBundledOutput(coteRed,redsTous)
  60. end
  61. table.foreach(liste,function(i,data)
  62.     file=fs.open(tostring(i),"r")
  63.     if file~=nil then
  64.         if file.readLine()=='true' then
  65.             liste[i].choix=true
  66.         else
  67.             liste[i].choix=false
  68.         end
  69.         file.close()
  70.     else
  71.         file=fs.open(tostring(i),"w")
  72.         file.write(liste[i].choix)
  73.         file.close()
  74.     end
  75.     liste[i].win=window.create(term,premierX+((i-1)*(largeur+marge)),premierY,largeur,hauteur,true)
  76.     actuWin(i)
  77. end)
  78. actuRed()
  79.  
  80. while true do                                                   -- controle du clic tactile
  81.     event, side, xPos, yPos = os.pullEvent("monitor_touch")     -- si le tactile est décalé
  82.     if (xPos-premierX)%(largeur+marge)<largeur then             -- préférer bouger les variables en tete de fichier
  83.         u=math.floor((xPos-premierX)/(largeur+marge))+1
  84.         if liste[u] then
  85.             if liste[u].choix then
  86.                 liste[u].choix=false
  87.             else
  88.                 liste[u].choix=true
  89.             end
  90.             file=fs.open(tostring(u),"w")
  91.             file.write(liste[u].choix)
  92.             file.close()
  93.             actuWin(u)
  94.             actuRed()
  95.         end
  96.     end
  97. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement