Advertisement
itsjstn

Elev Control PC

Jun 24th, 2024 (edited)
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.99 KB | Gaming | 0 0
  1. local utils = require 'itsjstnutils'
  2.  
  3. local commands = {
  4.     {
  5.         type = "raise",
  6.         handler = function(sender, req)
  7.             redstone.setOutput("top", true)
  8.             rednet.send(sender, {
  9.                 success = true
  10.             }, "elev_op")
  11.         end
  12.     },
  13.     {
  14.         type = "lower",
  15.         handler = function(sender, req)
  16.             redstone.setOutput("top", false)
  17.             rednet.send(sender, {
  18.                 success = true
  19.             }, "elev_op")
  20.         end
  21.     }
  22. }
  23.  
  24. rednet.open('back')
  25. if rednet.isOpen('back') then
  26.     rednet.host("elev_op", "server")
  27.  
  28.     while true do
  29.         print("Waiting for command...")
  30.         local sender, req = rednet.receive("elev_op");
  31.         print("Command received: " .. req.type)
  32.         for i, v in ipairs(commands) do
  33.             if v.type == req.type then
  34.                 v.handler(sender, req.body)
  35.             end
  36.         end
  37.     end
  38. else
  39.     print('Failed to activate the attached modem.')
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement