Sectly_Playz

ComputerCraft + Create Minecraft Elevator Script

Apr 3rd, 2022 (edited)
526
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.84 KB | None | 0 0
  1. -- // https://pastebin.com/wBYvYFFv
  2.  
  3. os.pullEvent = os.pullEventRaw
  4.  
  5. local modemside = "back"
  6. local elevatorfloorinputside = "right"
  7. local elevatorclutchoutputside = "top"
  8. local elevatordownoutputside = "left"
  9.  
  10. local inputbase
  11.  
  12. local floornumber = 0
  13. local gotofloor = 0
  14. local targetpcid
  15.  
  16. local Ismovingup = nil
  17.  
  18. print("Script Made By: TEC_NO")
  19.  
  20. term.clear()
  21.  
  22. print("-----------------------------------")
  23. write('Host PC ID: ')
  24. targetpcid = read()
  25. print("Script Made By: TEC_NO")
  26. print("-----------------------------------")
  27. inputbase = read()
  28.  
  29. term.clear()
  30.  
  31. print("-----------------------------------")
  32. print("Host PC Id: "..targetpcid)
  33. print("This PC Id: "..os.getComputerID())
  34. print("Script Made By: TEC_NO")
  35. print("-----------------------------------")
  36. inputbase = read()
  37.  
  38. rednet.open(modemside)
  39.  
  40. while true do
  41.   sleep(0.048)
  42.  
  43.   local currentstatus = "?"
  44.  
  45.   if Ismovingup == nil then
  46.     senderid, floortext = rednet.receive()
  47.  
  48.     currentstatus = "got message from: "..senderid.." with message: "..floortext
  49.  
  50.     if tonumber(senderid) == tonumber(targetpcid) then
  51.        currentstatus = "correct senderid"
  52.        if tonumber(floortext) ~= tonumber(floornumber) then
  53.           currentstatus = "floor is not same number"
  54.           gotofloor = tonumber(floortext)
  55.           currentstatus = "floor is set to: "..floortext..":"..gotofloor
  56.        end
  57.     end
  58.   end
  59.  
  60.   if rs.getInput(elevatorfloorinputside) == true then
  61.     if Ismovingup ~= nil then
  62.       if Ismovingup == true then
  63.         floornumber = floornumber + 1
  64.       elseif Ismovingup == false then
  65.         floornumber = floornumber - 1
  66.       end
  67.     end
  68.   end
  69.  
  70.   if Ismovingup ~= nil then
  71.     rs.setOutput(elevatordownoutputside, Ismovingup)
  72.   end
  73.  
  74.   term.clear()
  75.  
  76.   print("-----------------------------------")
  77.   print("ElevatorOS.exe")
  78.   print("Script Made By: TEC_NO")
  79.   print("-----------------------------------")
  80.  
  81.   local dummysatusIsmovingup = "nil"
  82.  
  83.   if Ismovingup ~= nil then
  84.     if Ismovingup == true then
  85.       dummysatusIsmovingup = "true"
  86.     elseif Ismovingup == false then
  87.       dummysatusIsmovingup = "false"
  88.     else
  89.       dummysatusIsmovingup = "?"
  90.     end
  91.   end
  92.  
  93.   print("gotofloor: "..gotofloor.." | floornumber:"..floornumber.." | currentstatus:"..currentstatus.." | Ismovingup :"..dummysatusIsmovingup.." | targetpcid:"..targetpcid.." | id:"..os.getComputerID().." | event:"..math.random())
  94.  
  95.   if tonumber(gotofloor) ~= tonumber(floornumber) then
  96.     if tonumber(floornumber) < tonumber(gotofloor) then
  97.         Ismovingup = true
  98.         rs.setOutput(elevatorclutchoutputside, true)
  99.     elseif tonumber(floornumber) > tonumber(gotofloor) then
  100.         Ismovingup = false
  101.         rs.setOutput(elevatorclutchoutputside, true)
  102.     end
  103.   else
  104.     rs.setOutput(elevatorclutchoutputside, false)
  105.     Ismovingup = nil
  106.   end
  107. end
Add Comment
Please, Sign In to add comment