Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ====== DETECTION AUTO DU MONITEUR ======
- local mon = peripheral.find("monitor")
- if not mon then
- error("Aucun moniteur détecté. Branche un écran (monitor) sur le computer.")
- end
- -- Commande de summon
- 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\"}"
- -- ====== INIT MONITEUR ======
- mon.setTextScale(1)
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.white)
- mon.clear()
- local w, h = mon.getSize()
- -- Définition du bouton
- local btn = {
- x1 = math.floor(w/2 - 6),
- y1 = math.floor(h/2 - 1),
- x2 = math.floor(w/2 + 6),
- y2 = math.floor(h/2 + 1),
- label = "Ouvrir la porte"
- }
- local function drawButton(active)
- local bg = active and colors.green or colors.blue
- mon.setBackgroundColor(bg)
- mon.setTextColor(colors.white)
- for y = btn.y1, btn.y2 do
- mon.setCursorPos(btn.x1, y)
- mon.write(string.rep(" ", btn.x2 - btn.x1 + 1))
- end
- local textX = btn.x1 + math.floor((btn.x2 - btn.x1 + 1 - #btn.label) / 2)
- local textY = btn.y1 + math.floor((btn.y2 - btn.y1) / 2)
- mon.setCursorPos(textX, textY)
- mon.write(btn.label)
- end
- local function inButton(x, y)
- return x >= btn.x1 and x <= btn.x2 and y >= btn.y1 and y <= btn.y2
- end
- -- Dessin initial
- drawButton(false)
- -- ====== BOUCLE D'ÉCOUTE ======
- while true do
- local event, side, x, y = os.pullEvent("monitor_touch")
- -- On ne check plus le "side", on prend n'importe quel monitor_touch
- if inButton(x, y) then
- -- Animation "pressée"
- drawButton(true)
- local ok, out = commands.exec(summonCmd)
- -- Retour visuel
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.white)
- mon.clear()
- mon.setCursorPos(1, 1)
- if ok then
- mon.write("Timedoor invoquee !")
- else
- mon.write("Echec commande :")
- mon.setCursorPos(1, 2)
- mon.write(textutils.serialize(out))
- end
- sleep(1.5)
- mon.clear()
- drawButton(false)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment