Guest User

railserver10

a guest
Oct 1st, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.26 KB | None | 0 0
  1. rednet.open("top")
  2.  
  3. -- RailServer v.1.9 --
  4. ----------------------
  5.  
  6. -- Variables Input
  7.  
  8. -- Insert the name of your train in quotation marks.
  9. -- 18 Characters please, if name less than 18 chars
  10. -- insert spaces to make up difference
  11. local trainname = "Test Train 3      "
  12.  
  13. -- Set the Train Departure Time
  14. -- note time is number format eg. 18.30 = 18.5
  15. local traintime = 23
  16.  
  17. -- Set the Train Destination
  18. -- all lowercase no caps
  19. local destination = destination1
  20.  
  21. -- Set the Train Destination Name
  22. local destinationname = "Destination 1"
  23. -- Set the Platform (north, south, east, west)
  24. local platform = south
  25.  
  26. -- Input Platform Number (platforms 3-6)
  27. local platformnumber = 3
  28.  
  29. -- Input length of time train to sit on platform
  30. -- eg 1.5 = an hour and a half mc gametime
  31. local platformdelay = 1
  32.  
  33. -- and in real world seconds
  34. local platformdelaysecs = 48
  35.  
  36. --- Total Creation Time (important Variable)
  37. --- Time for 7 carts at current variables is 1.5
  38. local creationtime = 1.5
  39.  
  40. -- Select req. Carts (all lowercase no spaces)
  41. local cart1 = passenger
  42. local cart2 = passenger
  43. local cart3 = passenger
  44. local cart4 = none
  45. local cart5 = none
  46. local cart6 = none
  47. local cart7 = anchor
  48.  
  49. --Speed Variables
  50.  
  51. --Time for Locomotive in secs
  52. local locotime = 35
  53. --Time between carts secs
  54. local carttime = 5
  55. --Number of carts intrain
  56. local cartnumber = 7
  57. --Time after last cart before platform deselect
  58. local endtime = 5
  59.  
  60. ---Redstone Connections (construction notes)
  61. --- right - bundled Cable to platform selectors
  62. --- bottom - system will only operate if a redstone signal is active
  63.  
  64.  
  65. -- Functions
  66.  
  67. function cartFreq(comp1,comp2,name)
  68.   print(name.." Cart")
  69.   rednet.send(comp1, "pulse")
  70.   rednet.send(comp2, "pulse")
  71. end
  72.  
  73. function cartFreq2(comp1,name)
  74.   rednet.send(comp1, "pulse")
  75.   print(name.." Cart")
  76. end
  77.  
  78. function passenger()
  79.    cartFreq2(229, "Passenger")
  80. end
  81.  
  82. function storage()
  83.    cartFreq2(230, "Storage")
  84. end
  85.  
  86. function anchor()
  87.    cartFreq2(231, "Anchor")
  88. end
  89.  
  90. function work()
  91.    cartFreq2(232, "Work")
  92. end
  93.  
  94. function undercutter()
  95.    cartFreq2(233, "Undercutter")
  96. end
  97.  
  98. ---Liquid Table Functions
  99. function water()
  100.    cartFreq(167, 160, "Water")
  101. end
  102.  
  103. function lava()
  104.    cartFreq(165, 171, "Lava")
  105. end
  106.  
  107. function creosote()
  108.    cartFreq(168, 172, "Creosote")
  109. end
  110.  
  111. function biofuel()
  112.    cartFreq(169, 173, "Biofuel")
  113. end
  114.  
  115. function oil()
  116.    cartFreq(170, 174, "Oil")
  117. end
  118.  
  119. function fuel()
  120.    cartFreq(166, 175, "Fuel")
  121. end
  122.  
  123. ---Blocks Table Functions
  124. function cobble()
  125.    cartFreq(178, 179, "Cobble")
  126. end
  127.  
  128. function stone()
  129.    cartFreq(180, 181, "Stone")
  130. end
  131.  
  132. function stoneslab()
  133.    cartFreq(182, 183, "Stone Slab")
  134. end
  135.  
  136. function stonebrick()
  137.    cartFreq(184, 185, "Stone Brick")
  138. end
  139.  
  140. function dirt()
  141.    cartFreq(186, 187, "Dirt")
  142. end
  143.  
  144. function gravel()
  145.    cartFreq(188, 189, "Gravel")
  146. end
  147.  
  148. function oakwood()
  149.    cartFreq(190, 191, "Oak Wood")
  150. end
  151.  
  152. function glass()
  153.    cartFreq(192, 193, "Glass")
  154. end
  155.  
  156. function sandstone()
  157.    cartFreq(194, 195, "Sandstone")
  158. end
  159.  
  160. function csandstone()
  161.    cartFreq(196, 197, "C Sandstone")
  162. end
  163.  
  164. function sand()
  165.    cartFreq(198, 199, "Sand")
  166. end
  167.  
  168. function basalt()
  169.    cartFreq(200, 201, "Basalt")
  170. end
  171.  
  172. function marble()
  173.    cartFreq(202, 203, "Marble")
  174. end
  175.  
  176. function obsidian()
  177.    cartFreq(204, 205, "Obsidian")
  178. end
  179.  
  180. ---Fuel Table Functions
  181. function blazerod()
  182.    cartFreq(206, 207, "Blaze Rod")
  183. end
  184.  
  185. function charcoal()
  186.    cartFreq(208, 209, "Charcoal")
  187. end
  188.  
  189. function coalcoke()
  190.    cartFreq(210, 211, "Coal Coke")
  191. end
  192.  
  193. function electricity()
  194.    cartFreq(176, 177, "Electricity")
  195. end
  196.  
  197. ---Destination Functions
  198. function destination1()
  199.    cartFreq2(212, "Destination 1")
  200. end
  201.  
  202. function destination2()
  203.    cartFreq2(213, "Destination 2")
  204. end
  205.  
  206. function destination3()
  207.    cartFreq2(214, "Destination 3")
  208. end
  209.  
  210. function destination4()
  211.    cartFreq2(215, "Destination 4")
  212. end
  213.  
  214. function destination5()
  215.    cartFreq2(216, "Destination 5")
  216. end
  217.  
  218. function destination6()
  219.    cartFreq2(217, "Destination 6")
  220. end
  221.  
  222. function destination7()
  223.    cartFreq2(161, "Destination 7")
  224. end
  225.  
  226. function destination8()
  227.    cartFreq2(218, "Destination 8")
  228. end
  229.  
  230. function destination9()
  231.    cartFreq2(219, "Destination 9")
  232. end
  233.  
  234. function destination10()
  235.    cartFreq2(220, "Destination 10")
  236. end
  237.  
  238. function destination11()
  239.    cartFreq2(221, "Destination 11")
  240. end
  241.  
  242. function destination12()
  243.    cartFreq2(222, "Destination 12")
  244. end
  245.  
  246. function destination13()
  247.    cartFreq2(213, "Destination 13")
  248. end
  249.  
  250. function destination14()
  251.    cartFreq2(214, "Destination 14")
  252. end
  253.  
  254. function destination15()
  255.    cartFreq2(215, "Destination 15")
  256. end
  257.  
  258. function destination16()
  259.    cartFreq2(216, "Destination 16")
  260. end
  261.  
  262. function destination17()
  263.    cartFreq2(217, "Destination 17")
  264. end
  265.  
  266. function destination18()
  267.    cartFreq2(212, "Destination 18")
  268. end
  269.  
  270. function none()
  271. print("No Cart Selected....Moving On...")
  272. end
  273.  
  274.  
  275. -- Cartpulse Function
  276. function cartpulse(carttype,platform)
  277. carttype()
  278. end
  279.  
  280. -- Destinationpulse Function
  281. function destinationpulse(destination,platform)
  282. destination()
  283. end
  284.  
  285. function platformselect(platform)
  286. if platform == south
  287. then
  288. rs.setBundledOutput("right",colors.blue)
  289. print("Platform 3 Selected")
  290. elseif platform == east
  291. then
  292. rs.setBundledOutput("right", colors.green)
  293. print("Platform 4 Selected")
  294. elseif platform == north
  295. then
  296. rs.setBundledOutput("right", colors.red)
  297. print("Platform 5 Selected")
  298. else
  299. print("Platform 6 Selected")
  300. end
  301. end
  302.  
  303. function platformdeselect()
  304. rs.setBundledOutput("right",0)
  305. end
  306.  
  307. function redcheckfalse()
  308. print("Automatic trains are being held!")
  309. print("This computer will reboot in 30 seconds")
  310. sleep(30)
  311. os.reboot()
  312. end
  313.  
  314. function redcheck()
  315. if rs.getInput("bottom")  == true then
  316. redcheckfalse()
  317. else
  318. print("Automatic trains are not currently being held")
  319. end
  320. end
  321.  
  322. local totalcarttime = carttime*cartnumber
  323. local totalwaittime = totalcarttime+locotime+endtime
  324. local totaltime = totalwaittime+platformdelaysecs
  325. local traincreatetime = traintime-platformdelay-creationtime
  326. local traintimeactual = os.setAlarm(traincreatetime)
  327.  
  328. while true do
  329. local event, arg = os.pullEvent("alarm")
  330. if arg == traintimeactual then
  331. redcheck()
  332. print("Train Creation in Progress")
  333. rednet.send(242, trainname.."    Platform "..platformnumber.."   "..destinationname.."  "..textutils.formatTime(traintime,true))
  334. print("Data Sent to Departures Board")
  335. print(trainname)
  336. platformselect(platform)
  337. print("Time to deselection"..totalwaittime.."secs")
  338. print("Time to train departure"..totaltime.."secs")
  339. destinationpulse(destination,platform)
  340. sleep(locotime)
  341. cartpulse(cart1,platform)
  342. sleep(carttime)
  343. cartpulse(cart2,platform)
  344. sleep(carttime)
  345. cartpulse(cart3,platform)
  346. sleep(carttime)
  347. cartpulse(cart4,platform)
  348. sleep(carttime)
  349. cartpulse(cart5,platform)
  350. sleep(carttime)
  351. cartpulse(cart6,platform)
  352. sleep(carttime)
  353. cartpulse(cart7,platform)
  354. sleep(carttime)
  355. sleep(endtime)
  356. print("Ready to Board")
  357. platformdeselect()
  358. print("Platform Deselected")
  359. sleep(platformdelaysecs)
  360. print("Train Departing for "..destinationname)
  361. sleep(2)
  362. print("This Computer Will reboot in 10 secs")
  363. print("Thank you for using Megatech RailServer v1.8")
  364. sleep(10)
  365. os.reboot()
  366. end
  367. end
Advertisement
Add Comment
Please, Sign In to add comment