N2AZ

test_commands

Nov 18th, 2025 (edited)
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.23 KB | None | 0 0
  1. -- ====== DETECTION AUTO DU MONITEUR ======
  2. local mon = peripheral.find("monitor")
  3. if not mon then
  4.   error("Aucun moniteur détecté. Branche un écran (monitor) sur le computer.")
  5. end
  6.  
  7. -- Commande de summon
  8. local summonCmd = "/summon tempad:timedoor ~ ~1 ~ {LinkedPortalId:\"62f4b1cc-fc98-452d-8eb3-e81d5a26d94c\",ClosingTime:170,TargetAngle:0.0f,IsOriginal:1b,Color:\"#8e00ff\",PortalCooldown:0,PlacementSettings:{type:\"tempad:default\"},Rotation:[344.8514f,0.0f],IsGlitching:0b,CustomName:'\"CMDOOR\"',TargetPos:[6.5d,100.5d,9.5d],TargetDimension:\"minecraft:overworld\"}"
  9.  
  10. -- ====== INIT MONITEUR ======
  11. mon.setTextScale(1)
  12. mon.setBackgroundColor(colors.black)
  13. mon.setTextColor(colors.white)
  14. mon.clear()
  15.  
  16. local w, h = mon.getSize()
  17.  
  18. -- Définition du bouton
  19. local btn = {
  20.   x1 = math.floor(w/2 - 6),
  21.   y1 = math.floor(h/2 - 1),
  22.   x2 = math.floor(w/2 + 6),
  23.   y2 = math.floor(h/2 + 1),
  24.   label = "Ouvrir la porte"
  25. }
  26.  
  27. local function drawButton(active)
  28.   local bg = active and colors.green or colors.blue
  29.   mon.setBackgroundColor(bg)
  30.   mon.setTextColor(colors.white)
  31.  
  32.   for y = btn.y1, btn.y2 do
  33.     mon.setCursorPos(btn.x1, y)
  34.     mon.write(string.rep(" ", btn.x2 - btn.x1 + 1))
  35.   end
  36.  
  37.   local textX = btn.x1 + math.floor((btn.x2 - btn.x1 + 1 - #btn.label) / 2)
  38.   local textY = btn.y1 + math.floor((btn.y2 - btn.y1) / 2)
  39.  
  40.   mon.setCursorPos(textX, textY)
  41.   mon.write(btn.label)
  42. end
  43.  
  44. local function inButton(x, y)
  45.   return x >= btn.x1 and x <= btn.x2 and y >= btn.y1 and y <= btn.y2
  46. end
  47.  
  48. -- Dessin initial
  49. drawButton(false)
  50.  
  51. -- ====== BOUCLE D'ÉCOUTE ======
  52. while true do
  53.   local event, side, x, y = os.pullEvent("monitor_touch")
  54.  
  55.   -- On ne check plus le "side", on prend n'importe quel monitor_touch
  56.   if inButton(x, y) then
  57.     -- Animation "pressée"
  58.     drawButton(true)
  59.  
  60.     local ok, out = commands.exec(summonCmd)
  61.  
  62.     -- Retour visuel
  63.     mon.setBackgroundColor(colors.black)
  64.     mon.setTextColor(colors.white)
  65.     mon.clear()
  66.     mon.setCursorPos(1, 1)
  67.     if ok then
  68.       mon.write("Timedoor invoquee !")
  69.     else
  70.       mon.write("Echec commande :")
  71.       mon.setCursorPos(1, 2)
  72.       mon.write(textutils.serialize(out))
  73.     end
  74.  
  75.     sleep(1.5)
  76.     mon.clear()
  77.     drawButton(false)
  78.   end
  79. end
Advertisement
Add Comment
Please, Sign In to add comment