View difference between Paste ID: k2wVeWXz and 7RRqbSMk
SHOW: | | - or go back to the newest paste.
1
--Variables --
2
local mouseWidth = 0
3
local mouseHeight = 0
4
5
local currentDestination = "None"
6
local currentPlayer = "None"
7
--Set turtle connection --
8
rednet.open("bottom")
9
10
--Setup sensor--
11
local sensor = peripheral.wrap('back')
12
13
local minX = -5 local maxX = 0
14
local minY = 0  local maxY = 10
15
local minZ = -5 local maxZ = 0
16
17
--Set monitor properties
18
local monitor = peripheral.wrap("left")
19
monitor.clear()
20
21
22
23
function setCurrentPlayername(name)
24
	if(name=="None") then
25
		currentPlayer="None"
26
		currentDestination="None"
27
		sendTurtleMessage("Stop")
28
		setcurrentDestinationData()
29
		
30
		monitor.setCursorPos(2,2)
31
		monitor.setBackgroundColor((colors.blue))
32
		monitor.write(" No players detected ")
33
	elseif(name==currentPlayer) then
34
		-- Do nothing --
35
	else
36
		currentPlayer=name
37
		
38
		monitor.setCursorPos(2,2)
39
		monitor.setBackgroundColor((colors.blue))
40
		monitor.write(" Hello ")
41
		
42
		monitor.setCursorPos(9,2)
43
		monitor.setBackgroundColor((colors.blue))
44
		if(string.len(name) < 15) then
45
			monitor.write(" " .. EnlargeName(name,15))
46
		else
47
			monitor.write(" " .. string.sub(name,0,11) .. ".. ")
48
		end
49
	end
50
end
51
52
function setcurrentDestinationData()
53
--Write first list of destinations
54
	monitor.setCursorPos(2,6)
55
	if currentDestination == "MachineRoom" then
56
		monitor.setBackgroundColor((colors.green))
57
	else
58
		monitor.setBackgroundColor((colors.red))
59
	end
60
	monitor.write("  Machine Room         ")
61
62
	monitor.setCursorPos(2,8)
63
	if currentDestination == "AppliedEnergistics" then
64
		monitor.setBackgroundColor((colors.green))
65
	else
66
		monitor.setBackgroundColor((colors.red))
67
	end
68
	monitor.write("  Applied Energistics  ")
69
70
	monitor.setCursorPos(2,10)
71
	if currentDestination == "Destination 3" then
72
		monitor.setBackgroundColor((colors.green))
73
		else
74
		monitor.setBackgroundColor((colors.red))
75
	end
76
	monitor.write("  Destination 3  ")
77
78
	monitor.setCursorPos(2,12)
79
	if currentDestination == "None" then
80
		monitor.setBackgroundColor((colors.green))
81
		else
82
		monitor.setBackgroundColor((colors.red))
83
	end
84
	monitor.write("  None           ")
85
86
	monitor.setCursorPos(2,14)
87
	if currentDestination == "None" then
88
		monitor.setBackgroundColor((colors.green))
89
		else
90
		monitor.setBackgroundColor((colors.red))
91
	end
92
	monitor.write("  None           ")
93
end
94
95
-- Perform clicked action --
96
function checkClickPosition()
97
	-- 1st Row --
98
	if(mouseWidth > 1 and mouseWidth < 20 and mouseHeight == 6) then
99
		currentDestination = "MachineRoom"
100
		setcurrentDestinationData()		
101
		sendTurtleMessage(1)
102
	-- 2nd Row --
103
	elseif(mouseWidth > 1 and mouseWidth < 20 and mouseHeight == 8) then
104
		currentDestination = "AppliedEnergistics"
105
		setcurrentDestinationData()
106
		sendTurtleMessage(2)	
107
	-- 3rd Row --
108
	elseif(mouseWidth > 1 and mouseWidth < 20 and mouseHeight == 10) then
109
		currentDestination = "Destination 3"
110
		setcurrentDestinationData()	
111
		sendTurtleMessage(3)		
112
	-- 4th Row --
113
	elseif(mouseWidth > 1 and mouseWidth < 20 and mouseHeight == 12) then
114
		currentDestination = "None"
115
		setcurrentDestinationData()	
116
		sendTurtleMessage(4)	
117
	-- 5th Row --
118
	elseif(mouseWidth > 1 and mouseWidth < 20 and mouseHeight == 14) then
119
		currentDestination = "None"
120
		setcurrentDestinationData()
121
		sendTurtleMessage(5)
122
	end
123
end
124
125
function EnlargeName(name,size)
126
	nameLength = string.len(name)
127
	
128
	if(nameLength < size) then
129
		local temp = name
130
		for variable = 0,size - nameLength,1 do
131
			temp = temp .. " "
132
		end
133
		return temp
134
	end
135
end
136
137
-- Send message --
138
function sendTurtleMessage(Message)
139
	if(Message == "Stop") then
140
		rednet.broadcast(Message,"TravelhubTurtle")
141-
	elseif(currentPlayer == "Roktarok") then
141+
142
		rednet.broadcast(Message,"TravelhubTurtle")
143
	end
144-
		rednet.broadcast(16,"TravelhubTurtle")
144+
145
146
--First time data setup --
147
setcurrentDestinationData()
148
149
150
function SensorActivities()
151
	players = sensor.getPlayerNames()
152
        -- Don't do checks if there are no players.
153
        if #players == 0 then
154
			setCurrentPlayername("None")
155
		    sleep(0.5)
156
        else -- There are players
157
			for _, name in pairs(players) do
158
				info = sensor.getPlayerData(name)
159
				pos = info.position
160
				setCurrentPlayername(name)
161
				break;
162
			end
163
		end
164
end
165
166
function monitorActivities()
167
	event,p1,p2,p3 = os.pullEvent()
168
	if event == "monitor_touch" then
169
		mouseWidth = p2
170
		mouseHeight = p3
171
		checkClickPosition()
172
	end		
173
end
174
	
175
while true do
176
	parallel.waitForAll(SensorActivities, monitorActivities)
177
end