Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("=================================================")
- print("====== Train Client ======")
- print("====== Created by NoxiaZ ======")
- print("====== ======")
- print("====== Inspired by OminousPenguin ======")
- print("====== Version 0.1A ======")
- print("=================================================")
- computerID = os.getComputerID()
- print("ComputerID: ",computerID)
- function preparetable(t)
- setmetatable(t,{__newindex=function(self,k,v) rawset(self,v,true) end})
- end
- function compare(a,b)
- return a[1] < b[1]
- end
- function explode(inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- t={} ; i=1
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- t[i] = str
- i = i + 1
- end
- return t
- end
- function insert(gpsY,id,name)
- local value = id .. explodeChar .. name
- gpsY = tonumber(gpsY)
- if find(gpsY) then
- else
- table.insert(stationList,gpsY,value)
- end
- end
- function find(key)
- if (stationList[key] == nil) then
- return false
- else
- return true
- end
- end
- function getColorNumber(color)
- for key,value in pairs(colors) do
- if key == color then
- return value
- end
- end
- return 0
- end
- function removeBundleColor(color)
- activeBundles = activeBundles - getColorNumber(color)
- setBundle()
- end
- function addBundleColor(color)
- activeBundles = activeBundles + getColorNumber(color)
- setBundle()
- end
- function trackOn()
- if (isTrackOn == false) then
- isTrackOn = true
- print("Turn on elevatortrack")
- addBundleColor(elevatorTrack)
- end
- end
- function trackOff()
- if (isTrackOn == true) then
- isTrackOn = false
- print("Turn off elevatortrack")
- removeBundleColor(elevatorTrack)
- end
- end
- function releaseCart()
- addBundleColor(boardingTrack)
- sleep(0.5)
- removeBundleColor(boardingTrack)
- end
- function setBundle()
- redstone.setBundledOutput(bundle,activeBundles)
- end
- function clearMonitor()
- monitor.clear()
- monitor.setCursorPos(1,1)
- end
- function writeMonitor()
- clearMonitor()
- monitor.write("Pick your place:")
- table.sort(stationList, compare)
- for i, v in pairs(stationList) do
- local cX,cY = monitor.getCursorPos()
- monitor.setCursorPos(1,cY+1)
- local data = explode(v,explodeChar)
- monitor.write(data[2])
- end
- end
- isTrackOn = false
- serverID = -1
- bundle = "bottom"
- elevatorTrack = "orange"
- boardingTrack = "white"
- modem = "back"
- monitorPlace="top"
- explodeChar="\31"
- activeBundles = 0
- stationList={}
- pageIndex = 0
- pageCount = 5
- preparetable(stationList)
- monitor = peripheral.wrap(monitorPlace)
- monitor.clear()
- rednet.open(modem)
- setBundle()
- clearMonitor()
- local senderId, message, distance
- local keepRunning = true;
- while (keepRunning) do
- rednet.broadcast("who")
- senderId, message, distance = rednet.receive(5)
- if (message == "server") then
- keepRunning = false
- end
- end
- serverID = tonumber(senderId)
- print("Found server ID: ",senderId)
- write("Enter your Y GPS coordinate: ")
- local y = read()
- write("Enter name of floor: ")
- local n = read()
- rednet.send(senderId,"add " .. explodeChar .. " " .. y .. explodeChar .. computerID .. explodeChar .. n)
- local run = true
- while run do
- local event = {os.pullEvent()}
- if (event[1] == "rednet_message") then
- local senderID = event[2]
- local message = event[3]
- print("Message: ", message)
- local array = explode(message, " ")
- local command = array[1]
- if (command == "true") then
- trackOn()
- elseif (command == "false") then
- trackOff()
- elseif (command =="release") then
- releaseCart()
- elseif (command == "update") then
- shell.run("delete","startup")
- shell.run("pastebin","get","GRxRhE4X","startup")
- shell.run("reboot")
- elseif (command == "station") then
- local data = explode(array[3],array[2])
- data = explode(array[3],array[2])
- local gpsY = data[1]
- local id = data[2]
- local name = data[3]
- insert(gpsY,id,name)
- writeMonitor()
- end
- elseif (event[1] == "redstone") then
- elseif (event[2] == "q") then
- run = false
- elseif (event[1] == "monitor_touch") then
- local x = tonumber(event[3])
- local y = tonumber(event[4])
- local nY = y-1
- write(" X: ")
- write(x)
- write(" Y: ")
- write(y)
- write(" nY: ")
- print(nY)
- i = 1
- for k, v in pairs(stationList) do
- if (i == nY) then
- local data = explode(v,explodeChar)
- print("Going to: ", data[2])
- rednet.send(serverID,"travel " .. data[1])
- break
- end
- i = i +1
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment