Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Destination selector for Railcraft and OpenPeripheral Ticket Machine.
- --Simple extract the ticket from Ticket Machine and insert into Locomotive with (Adv.) Item Loader.
- --Redstone pulse will be emitted through the defined side(below) of Computer upon selecting destination. Can for example be used to dispense train, emit sound(Note Block) etc.
- --List of names of stations and correlating Routing dest's are loaded from separate script. Each station are then chosen among the list upon starting this script the first time. Each station updates automatically to new added stations upon reload of script.
- --Attach Advanced Monitors and Ticket Machine by either wired modems or placed directly against any side of the Computer. Width/height of monitor depends on number of stations and length of names, though a 2x3 is a good estimate.
- --For custom stations make a copy of http://pastebin.com/0FTF2FU3 and change url below.
- --Url of list of stations.
- local stationURL = "tFC4W3H4"
- --Side of redstone output
- local redstoneside = "bottom"
- --Device side detection function
- function detectDevice(DeviceName)
- DeviceSide="none"
- for k,v in pairs(redstone.getSides()) do
- if peripheral.getType(v) and string.find(peripheral.getType(v), DeviceName) then
- DeviceSide = v
- break
- --end
- end
- end
- return(DeviceSide)
- end
- --Get list of devices
- monitor = "none"
- ticket = "none"
- local peripheralList = peripheral.getNames()
- --Detect monitor
- MonitorSide=detectDevice("monitor")
- if MonitorSide~="none" then
- monitor=peripheral.wrap(MonitorSide)
- print ("Monitor on the " .. MonitorSide .. " connected.")
- else
- for Index = 1, #peripheralList do
- if string.find(peripheralList[Index], "monitor") then
- monitor=peripheral.wrap(peripheralList[Index])
- print ("Monitor on wired modem: "..peripheralList[Index].." connected.")
- end
- end --for
- if monitor == "none" then
- print ("Warning - No Monitor attached, halting script!")
- return
- end
- end
- w,h=monitor.getSize()
- print("Monitor dimensions: w: "..w..", h: "..h)
- --Detect ticketmachine
- TicketSide=detectDevice("ticketmachine")
- if TicketSide~="none" then
- ticket=peripheral.wrap(TicketSide)
- print ("Ticket Machine on the " .. TicketSide .. " connected.")
- else
- for Index = 1, #peripheralList do
- if string.find(peripheralList[Index], "ticketmachine") then
- ticket=peripheral.wrap(peripheralList[Index])
- print ("Ticket Machine on wired modem: "..peripheralList[Index].." connected.")
- end
- end --for
- if ticket == "none" then
- print ("Warning - No Ticket machine attached, halting script!")
- return
- end
- end
- --Download station file
- if (fs.exists("stationFile") == true) then
- shell.run("delete stationFile")
- end
- shell.run("pastebin", "get", stationURL, "stationFile")
- --Load station file and save to variable
- os.loadAPI("stationFile")
- local stationList = stationFile.stationList
- local stationDest = stationFile.stationDest
- --first time run, pick station from station list. Saving to file to make script reboot friendly
- if (fs.exists("thisstation") == false) then
- while true do
- for i=1, #stationList do
- print(i..". "..stationList[i])
- end
- print("Which station is this?")
- local answer = read()
- if tonumber(answer)==nill then
- print("Wrong answer, input not a number")
- else
- local answerv = tonumber(string.format("%." .. 0 .. "f", answer))
- if (0 < answerv and answerv <= #stationList) then
- local file = fs.open("thisstation","w")
- file.writeLine(stationList[answerv])
- file.close()
- break
- else
- print("Wrong answer, input does not match number of stations")
- end
- end
- end
- end
- --load station name from file
- local file = fs.open("thisstation","r")
- local thisstation = file.readLine()
- file.close()
- print("Setting station as: "..thisstation)
- --This stations number on the list
- for i=1, #stationList do
- if string.find(stationList[i], thisstation) then
- thisstationnum = i
- print("Number "..thisstationnum.." on list of stations")
- end
- end
- --Write buttons on monitor
- monitor.clear()
- monitor.setBackgroundColour((colours.blue))
- monitor.setCursorPos(1,1)
- monitor.write(" Destination: ")
- for i=1, thisstationnum-1 do
- monitor.setCursorPos(1,i*2+1)
- monitor.setBackgroundColour((colours.green))
- monitor.write(" "..stationList[i].." ")
- end
- for i=thisstationnum+1, #stationList do
- monitor.setCursorPos(1,i*2-1)
- monitor.setBackgroundColour((colours.green))
- monitor.write(" "..stationList[i].." ")
- end
- monitor.setBackgroundColour((colours.black))
- --Click checking function, printing tickets
- function checkClickPosition()
- for i=1, thisstationnum-1 do
- if mouseHeight == i*2+1 then
- ticket.createTicket(stationDest[i], 1)
- sleep(0.5)
- redstone.setOutput(redstoneside, true)
- sleep(0.5)
- redstone.setOutput(redstoneside, false)
- sleep(0.5)
- end
- end
- for i=thisstationnum+1, #stationList do
- if mouseHeight == i*2-1 then
- ticket.createTicket(stationDest[i], 1)
- sleep(0.5)
- redstone.setOutput(redstoneside, true)
- sleep(0.5)
- redstone.setOutput(redstoneside, false)
- sleep(0.5)
- end
- end
- end
- --Check for clicks
- repeat
- event,p1,p2,p3 = os.pullEvent()
- if event=="monitor_touch" then
- mouseWidth = p2 -- sets mouseWidth
- mouseHeight = p3 -- and mouseHeight
- checkClickPosition() -- this runs our function
- end
- until event=="char" and p1==("x")
Add Comment
Please, Sign In to add comment