Advertisement
minecraft_storm

tardim

Apr 29th, 2024 (edited)
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. local tardim = peripheral.find("digital_tardim_interface") or error("No tardim attached", 0)
  2. local modem = peripheral.find("modem") or error("No modem attached", 0)
  3.  
  4.  
  5. terminate = false;
  6. address = 0
  7. modem.open(address)
  8. password = "tardim-1"
  9.  
  10.  
  11.  
  12. function listen()
  13. while terminate == false do
  14. -- os.queueEvent("run", 2, "nil")
  15. local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  16. messageRecieved(side,channel,replyChannel,message,distance)
  17. -- local event, par1, par2, par3, par4, par5 = os.pullEvent()
  18. -- if event == "modem_message" then
  19. -- side = par1
  20. -- channel = par2
  21. -- replyChannel = parm3
  22. -- message = par4
  23. -- distance = par5
  24. -- messageRecieved(side,channel,replyChannel,message,distance)
  25. -- end
  26. -- sleep(0.1)
  27. end
  28. end
  29.  
  30.  
  31. function messageRecieved(side,channel,replyChannel,message,distance)
  32. print(message[1])
  33. print(message[2])
  34. if message[1] == "connect" then
  35. sleep(0.1)
  36. modem.open(replyChannel+1)
  37. modem.transmit(replyChannel,replyChannel+1,{"ok",replyChannel+1})
  38. address = replyChannel+1
  39. -- modem.close(address)
  40. end
  41. if message[1] == "pass" then
  42. if message[2] == password then
  43. sleep(0.1)
  44. modem.transmit(replyChannel,address,{"correct"})
  45. else
  46. modem.transmit(replyChannel,address,{"error"})
  47. end
  48. end
  49. if message[1] == "location" then
  50. tardim.setTravelLocation(message[2],message[3],message[4])
  51. sleep(0.1)
  52. modem.transmit(replyChannel,address,{"location_set"})
  53. end
  54. if message[1] == "demat" then
  55. if not tardim.isInFlight() then
  56. tardim.demat()
  57. sleep(0.1)
  58. modem.transmit(replyChannel,address,{"demat"})
  59. else
  60. sleep(0.1)
  61. modem.transmit(replyChannel,address,{"inFlight"})
  62. end
  63.  
  64. end
  65. if message[1] == "remat" then
  66. if tardim.isInFlight() then
  67. tardim.remat()
  68. sleep(0.1)
  69. modem.transmit(replyChannel,address,{"remat"})
  70. else
  71. sleep(0.1)
  72. modem.transmit(replyChannel,address,{"landed"})
  73. end
  74. end
  75. if message[1] == "status" then
  76. sleep(0.1)
  77. modem.transmit(replyChannel,address,{"status",tardim.isInFlight(),tardim.getFuel()})
  78. end
  79. end
  80.  
  81.  
  82. parallel.waitForAll(listen)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement