Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Variables --
- local mouseWidth = 0
- local mouseHeight = 0
- local currentDestination = "None"
- local currentPlayer = "None"
- --Set turtle connection --
- rednet.open("bottom")
- --Setup sensor--
- local sensor = peripheral.wrap('back')
- local minX = -5 local maxX = 0
- local minY = 0 local maxY = 10
- local minZ = -5 local maxZ = 0
- --Set monitor properties
- local monitor = peripheral.wrap("left")
- monitor.clear()
- function setCurrentPlayername(name)
- if(name=="None") then
- currentPlayer="None"
- currentDestination="None"
- sendTurtleMessage("Stop")
- setcurrentDestinationData()
- monitor.setCursorPos(2,2)
- monitor.setBackgroundColor((colors.blue))
- monitor.write(" No players detected ")
- elseif(name==currentPlayer) then
- -- Do nothing --
- else
- currentPlayer=name
- monitor.setCursorPos(2,2)
- monitor.setBackgroundColor((colors.blue))
- monitor.write(" Hello ")
- monitor.setCursorPos(9,2)
- monitor.setBackgroundColor((colors.blue))
- if(string.len(name) < 15) then
- monitor.write(" " .. EnlargeName(name,15))
- else
- monitor.write(" " .. string.sub(name,0,11) .. ".. ")
- end
- end
- end
- function setcurrentDestinationData()
- --Write first list of destinations
- monitor.setCursorPos(2,6)
- if currentDestination == "MachineRoom" then
- monitor.setBackgroundColor((colors.green))
- else
- monitor.setBackgroundColor((colors.red))
- end
- monitor.write(" Machine Room ")
- monitor.setCursorPos(2,8)
- if currentDestination == "AppliedEnergistics" then
- monitor.setBackgroundColor((colors.green))
- else
- monitor.setBackgroundColor((colors.red))
- end
- monitor.write(" Applied Energistics ")
- monitor.setCursorPos(2,10)
- if currentDestination == "Destination 3" then
- monitor.setBackgroundColor((colors.green))
- else
- monitor.setBackgroundColor((colors.red))
- end
- monitor.write(" Destination 3 ")
- monitor.setCursorPos(2,12)
- if currentDestination == "None" then
- monitor.setBackgroundColor((colors.green))
- else
- monitor.setBackgroundColor((colors.red))
- end
- monitor.write(" None ")
- monitor.setCursorPos(2,14)
- if currentDestination == "None" then
- monitor.setBackgroundColor((colors.green))
- else
- monitor.setBackgroundColor((colors.red))
- end
- monitor.write(" None ")
- end
- -- Perform clicked action --
- function checkClickPosition()
- -- 1st Row --
- if(mouseWidth > 1 and mouseWidth < 20 and mouseHeight == 6) then
- currentDestination = "MachineRoom"
- setcurrentDestinationData()
- sendTurtleMessage(1)
- -- 2nd Row --
- elseif(mouseWidth > 1 and mouseWidth < 20 and mouseHeight == 8) then
- currentDestination = "AppliedEnergistics"
- setcurrentDestinationData()
- sendTurtleMessage(2)
- -- 3rd Row --
- elseif(mouseWidth > 1 and mouseWidth < 20 and mouseHeight == 10) then
- currentDestination = "Destination 3"
- setcurrentDestinationData()
- sendTurtleMessage(3)
- -- 4th Row --
- elseif(mouseWidth > 1 and mouseWidth < 20 and mouseHeight == 12) then
- currentDestination = "None"
- setcurrentDestinationData()
- sendTurtleMessage(4)
- -- 5th Row --
- elseif(mouseWidth > 1 and mouseWidth < 20 and mouseHeight == 14) then
- currentDestination = "None"
- setcurrentDestinationData()
- sendTurtleMessage(5)
- end
- end
- function EnlargeName(name,size)
- nameLength = string.len(name)
- if(nameLength < size) then
- local temp = name
- for variable = 0,size - nameLength,1 do
- temp = temp .. " "
- end
- return temp
- end
- end
- -- Send message --
- function sendTurtleMessage(Message)
- if(Message == "Stop") then
- rednet.broadcast(Message,"TravelhubTurtle")
- else
- rednet.broadcast(Message,"TravelhubTurtle")
- end
- end
- --First time data setup --
- setcurrentDestinationData()
- function SensorActivities()
- players = sensor.getPlayerNames()
- -- Don't do checks if there are no players.
- if #players == 0 then
- setCurrentPlayername("None")
- sleep(0.5)
- else -- There are players
- for _, name in pairs(players) do
- info = sensor.getPlayerData(name)
- pos = info.position
- setCurrentPlayername(name)
- break;
- end
- end
- end
- function monitorActivities()
- event,p1,p2,p3 = os.pullEvent()
- if event == "monitor_touch" then
- mouseWidth = p2
- mouseHeight = p3
- checkClickPosition()
- end
- end
- while true do
- parallel.waitForAll(SensorActivities, monitorActivities)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement