Advertisement
An93l0fD3ath

MineDepot Cart Control

Mar 5th, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.80 KB | None | 0 0
  1. -- MineDepot Cart Control Script
  2. -- Script Made By Xilandro
  3.  
  4. local component = require("component")
  5. local sides = require("sides")
  6. local event = require("event")
  7. local colors = require("colors")
  8.  
  9.  
  10. local md = component.modem
  11. local rs = component.redstone
  12.  
  13. local char_space = string.byte(" ")
  14. local running = true
  15. local carts = 0
  16. local railport = 1234 -- Change this to whatever port you're broadcasting train status stuff on
  17.  
  18. md.open(railport)
  19.  
  20. local function rsTest() -- checks if a cart passed over
  21.   if rs.getBundledInput(sides.north, colors.blue) > 0 then
  22.     --rs.setBundledOutput(sides.north, colors.yellow, 250)  -- Added By Angel
  23.     return true
  24.   else return false
  25.   end
  26. end
  27.  
  28. local function unknownEvent()
  29. end
  30.  
  31. local myEventHandlers = setmetatable({}, { __index = function() return unknownEvent end})
  32.  
  33. function myEventHandlers.key_down(adress, char, code, playerName)
  34.   if (char == char_space) then
  35.     rs.setBundledOutput(sides.north, colors.yellow, 250)
  36.     running = false
  37.   end
  38. end
  39.  
  40. function handleEvent(eventID, ...)
  41.   if (eventID) then
  42.     myEventHandlers[eventID](...)
  43.   end
  44. end
  45.  
  46.  
  47. while running do
  48. handleEvent(event.pull())
  49.   if (carts == 5) then
  50.     rs.setBundledOutput(sides.north, colors.yellow, 0)
  51.     md.broadcast(railport, "Change this to whatever you want your network message to be")
  52.     carts = carts - 5   -- Added by Angel
  53.   end
  54.  
  55.   if (rsTest()) then    -- Let's check for the directional detector track to have a signal. ++
  56.     carts = carts + 1
  57.     print(tostring(carts)) -- Debug Output
  58.   end
  59.  
  60.  
  61.   os.sleep(0.2) -- Adding this so you can Ctrl+Alt+C out of your program. There are cleaner ways of doing this,
  62.               -- such as pressing 'space' to exit but you would have to code an event handler, or use
  63.               -- one that Kodos wrote
  64. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement