View difference between Paste ID: mR4JV4HA and JB6AbEN9
SHOW: | | - or go back to the newest paste.
1-
os.loadAPI("gcapi")print("NOTICE: The computer is not storing data of any kind so the player using it is not breaking the rules of the server. Regarding the tracking of players the program doesn't track staff players listed on craftersland forum.")mon=peripheral.find("monitor")mon.setTextScale(1)sensor=peripheral.find("openperipheral_sensor")scrollInt=0;max_x=0;max_y=0;highlights={}currentTable={}config={}function readConfigFile(b)local c=gcapi.getListFromFile("/config.cfg")for d,e in pairs(c)do b[d]=e end;return b end;function saveConfigFile(b)gcapi.saveListToFile("/config.cfg",b)end;config=readConfigFile(config)if sensor and config.sensor_position==nil then local f={}print("Where is the sensor?")write("X: ")f.x=read():gsub(' ','')write("Y: ")f.y=read():gsub(' ','')write("Z: ")f.z=read():gsub(' ','')config.sensor_position=f;saveConfigFile(config)end;config=readConfigFile(config)function getMaxLength(g,h)length=0;for i,j in pairs(g)do if length<string.len(j[h])then length=string.len(j[h])end end;return length end;function totalLength(lengths)tLength=0;for k,l in pairs(lengths)do tLength=tLength+l end;return tLength end;function getColumns(g)return{"name","x","y","z","world"}end;function printTable(g)max_x_table=max_x-6;columnsName=getColumns(g)lengths={}lengths[0]=0;for m,h in pairs(columnsName)do lengths[m]=getMaxLength(g,h)end;a=1;while totalLength(lengths)<max_x_table do if a>5 then a=1 end;lengths[a]=lengths[a]+1;a=a+1 end;mon.setBackgroundColor(colors.white)mon.setTextColor(colors.black)for n=2,max_y-1,1 do playerData=getPlayerData(g,n,scrollInt)if playerData~=nil then name=playerData["name"]if(n+scrollInt)%2==0 then mon.setBackgroundColor(0x0100)end;if isHighlight(name)then mon.setBackgroundColor(colors.orange)end;for o=1,max_x,1 do mon.setCursorPos(o,n)mon.write(" ")end;x_pos=2;for m,h in pairs(columnsName)do x_pos=x_pos+lengths[m-1]+1;mon.setCursorPos(x_pos,n)mon.write(tostring(playerData[h]))end;mon.setBackgroundColor(colors.white)end end;currentTable=g end;function getPlayerData(g,n,scrollInt)local m=n-1+scrollInt;return g[m]end;function isHighlight(name)for m,p in pairs(highlights)do if name==p then return true,m end end;return false end;function printInterface()mon.setBackgroundColor(colors.white)mon.setTextColor(colors.black)mon.clear()max_x,max_y=mon.getSize()mon.setCursorPos(1,1)mon.setBackgroundColor(colors.yellow)for o=1,max_x,1 do mon.setCursorPos(o,1)mon.write(" ")end;name="Tracker for clan"mon.setCursorPos((max_x-string.len(name))/2,1)mon.write(name)mon.setBackgroundColor(colors.yellow)for o=1,max_x,1 do mon.setCursorPos(o,max_y)mon.write(" ")end;printButtons()end;function printButtons(q,r)mon.setCursorPos(max_x-12,max_y)if q then mon.setBackgroundColor(colors.red)else mon.setBackgroundColor(colors.green)end;mon.write(" UP ")mon.setBackgroundColor(colors.yellow)mon.write(" ")if r then mon.setBackgroundColor(colors.red)else mon.setBackgroundColor(colors.green)end;mon.write(" Down ")mon.setCursorPos(3,max_y)if q then mon.setBackgroundColor(colors.red)else mon.setBackgroundColor(colors.green)end;mon.write(" UP ")mon.setBackgroundColor(colors.yellow)mon.write(" ")if r then mon.setBackgroundColor(colors.red)else mon.setBackgroundColor(colors.green)end;mon.write(" Down ")end;updatingGUI=false;function updateGUI(dataPlayers)if updatingGUI then sleep(0.2)updateGUI()else updatingGUI=true;printInterface()printTable(dataPlayers)updatingGUI=false end end;function updateTableWithSensor(dataPlayers)local s=config.sensor_position.x;local t=config.sensor_position.y;local u=config.sensor_position.z;for m=1,#dataPlayers do player_data=dataPlayers[m]player_name=player_data["name"]sensor_data=sensor.getPlayerData(player_name)if sensor_data then dataPlayers[m].x=math.floor(s+sensor_data.position.x)dataPlayers[m].y=math.floor(t+sensor_data.position.y)dataPlayers[m].z=math.floor(u+sensor_data.position.z)dataPlayers[m].world="world"dataPlayers[m].updated_at="Updated now"end end;return dataPlayers end;function chatUpdater()local v=gcapi.getStaffList()while true do dataPlayers,ok,err=gcapi.getPosPlayers(v)if ok then if sensor then dataPlayers=updateTableWithSensor(dataPlayers)end;updateGUI(dataPlayers)end;sleep(3.1)end end;function clickListener()while true do tEvent={os.pullEvent()}if tEvent[1]=="monitor_touch"then local o=tEvent[3]local n=tEvent[4]local m=n-1+scrollInt;if n==max_y then if o>max_x-13 or o<13 then if o<max_x-7 and o>max_x-13 or o<13 and o<6 then scrollInt=scrollInt+1;printButtons(true,false)else scrollInt=scrollInt-1;printButtons(false,true)end;sleep(0.1)updateGUI(currentTable)end elseif currentTable[m]~=nil then tarjetPlayer=currentTable[m]["name"]if tarjetPlayer~=nil then actualHighlight,m=isHighlight(tarjetPlayer)if actualHighlight then highlights[m]=nil else table.insert(highlights,tarjetPlayer)end;updateGUI(currentTable)end end end end end;function getCenter(w,x)if not x then x=""end;if w-string.len(x)%2==0 then return math.floor((w-string.len(x))/2)end;return math.floor((w-string.len(x))/2)+1 end;function customPrint(y)term.clear()local max_x,max_y=term.getSize()term.setCursorPos(getCenter(max_x,y),getCenter(max_y))print(y)end;function listeners()parallel.waitForAny(clickListener)end;parallel.waitForAny(chatUpdater,listeners)error()
1+
if not os.loadAPI("gcapi") then
2
    shell.run("pastebin get A9D2dev0 gcapi")
3
    os.loadAPI("gcapi")
4
else
5
    os.loadAPI("gcapi")
6
end
7
8
9
print(
10
    "NOTICE: The computer is not storing data of any kind so the player using it is not breaking the rules of the server. Regarding the tracking of players the program doesn't track staff players listed on craftersland forum."
11
)
12
mon = peripheral.find("monitor")
13
mon.setTextScale(1)
14
sensor = peripheral.find("openperipheral_sensor")
15
scrollInt = 0
16
max_x = 0
17
max_y = 0
18
highlights = {}
19
currentTable = {}
20
config = {}
21
function readConfigFile(b)
22
    local c = gcapi.getListFromFile("/config.cfg")
23
    for d, e in pairs(c) do
24
        b[d] = e
25
    end
26
    return b
27
end
28
function saveConfigFile(b)
29
    gcapi.saveListToFile("/config.cfg", b)
30
end
31
config = readConfigFile(config)
32
if sensor and config.sensor_position == nil then
33
    local f = {}
34
    print("Where is the sensor?")
35
    write("X: ")
36
    f.x = read():gsub(" ", "")
37
    write("Y: ")
38
    f.y = read():gsub(" ", "")
39
    write("Z: ")
40
    f.z = read():gsub(" ", "")
41
    config.sensor_position = f
42
    saveConfigFile(config)
43
end
44
config = readConfigFile(config)
45
function getMaxLength(g, h)
46
    length = 0
47
    for i, j in pairs(g) do
48
        if length < string.len(j[h]) then
49
            length = string.len(j[h])
50
        end
51
    end
52
    return length
53
end
54
function totalLength(lengths)
55
    tLength = 0
56
    for k, l in pairs(lengths) do
57
        tLength = tLength + l
58
    end
59
    return tLength
60
end
61
function getColumns(g)
62
    return {"name", "x", "y", "z", "world"}
63
end
64
function printTable(g)
65
    max_x_table = max_x - 6
66
    columnsName = getColumns(g)
67
    lengths = {}
68
    lengths[0] = 0
69
    for m, h in pairs(columnsName) do
70
        lengths[m] = getMaxLength(g, h)
71
    end
72
    a = 1
73
    while totalLength(lengths) < max_x_table do
74
        if a > 5 then
75
            a = 1
76
        end
77
        lengths[a] = lengths[a] + 1
78
        a = a + 1
79
    end
80
    mon.setBackgroundColor(colors.white)
81
    mon.setTextColor(colors.black)
82
    for n = 2, max_y - 1, 1 do
83
        playerData = getPlayerData(g, n, scrollInt)
84
        if playerData ~= nil then
85
            name = playerData["name"]
86
            if (n + scrollInt) % 2 == 0 then
87
                mon.setBackgroundColor(0x0100)
88
            end
89
            if isHighlight(name) then
90
                mon.setBackgroundColor(colors.orange)
91
            end
92
            for o = 1, max_x, 1 do
93
                mon.setCursorPos(o, n)
94
                mon.write(" ")
95
            end
96
            x_pos = 2
97
            for m, h in pairs(columnsName) do
98
                x_pos = x_pos + lengths[m - 1] + 1
99
                mon.setCursorPos(x_pos, n)
100
                mon.write(tostring(playerData[h]))
101
            end
102
            mon.setBackgroundColor(colors.white)
103
        end
104
    end
105
    currentTable = g
106
end
107
function getPlayerData(g, n, scrollInt)
108
    local m = n - 1 + scrollInt
109
    return g[m]
110
end
111
function isHighlight(name)
112
    for m, p in pairs(highlights) do
113
        if name == p then
114
            return true, m
115
        end
116
    end
117
    return false
118
end
119
function printInterface()
120
    mon.setBackgroundColor(colors.white)
121
    mon.setTextColor(colors.black)
122
    mon.clear()
123
    max_x, max_y = mon.getSize()
124
    mon.setCursorPos(1, 1)
125
    mon.setBackgroundColor(colors.yellow)
126
    for o = 1, max_x, 1 do
127
        mon.setCursorPos(o, 1)
128
        mon.write(" ")
129
    end
130
    name = "Tracker for clan"
131
    mon.setCursorPos((max_x - string.len(name)) / 2, 1)
132
    mon.write(name)
133
    mon.setBackgroundColor(colors.yellow)
134
    for o = 1, max_x, 1 do
135
        mon.setCursorPos(o, max_y)
136
        mon.write(" ")
137
    end
138
    printButtons()
139
end
140
function printButtons(q, r)
141
    mon.setCursorPos(max_x - 12, max_y)
142
    if q then
143
        mon.setBackgroundColor(colors.red)
144
    else
145
        mon.setBackgroundColor(colors.green)
146
    end
147
    mon.write(" UP ")
148
    mon.setBackgroundColor(colors.yellow)
149
    mon.write(" ")
150
    if r then
151
        mon.setBackgroundColor(colors.red)
152
    else
153
        mon.setBackgroundColor(colors.green)
154
    end
155
    mon.write(" Down ")
156
    mon.setCursorPos(3, max_y)
157
    if q then
158
        mon.setBackgroundColor(colors.red)
159
    else
160
        mon.setBackgroundColor(colors.green)
161
    end
162
    mon.write(" UP ")
163
    mon.setBackgroundColor(colors.yellow)
164
    mon.write(" ")
165
    if r then
166
        mon.setBackgroundColor(colors.red)
167
    else
168
        mon.setBackgroundColor(colors.green)
169
    end
170
    mon.write(" Down ")
171
end
172
updatingGUI = false
173
function updateGUI(dataPlayers)
174
    if updatingGUI then
175
        sleep(0.2)
176
        updateGUI()
177
    else
178
        updatingGUI = true
179
        printInterface()
180
        printTable(dataPlayers)
181
        updatingGUI = false
182
    end
183
end
184
function updateTableWithSensor(dataPlayers)
185
    local s = config.sensor_position.x
186
    local t = config.sensor_position.y
187
    local u = config.sensor_position.z
188
    for m = 1, #dataPlayers do
189
        player_data = dataPlayers[m]
190
        player_name = player_data["name"]
191
        sensor_data = sensor.getPlayerData(player_name)
192
        if sensor_data then
193
            dataPlayers[m].x = math.floor(s + sensor_data.position.x)
194
            dataPlayers[m].y = math.floor(t + sensor_data.position.y)
195
            dataPlayers[m].z = math.floor(u + sensor_data.position.z)
196
            dataPlayers[m].world = "world"
197
            dataPlayers[m].updated_at = "Updated now"
198
        end
199
    end
200
    return dataPlayers
201
end
202
function chatUpdater()
203
    local v = gcapi.getStaffList()
204
    while true do
205
        dataPlayers, ok, err = gcapi.getPosPlayers(v)
206
        if ok then
207
            if sensor then
208
                dataPlayers = updateTableWithSensor(dataPlayers)
209
            end
210
            updateGUI(dataPlayers)
211
        end
212
        sleep(3.1)
213
    end
214
end
215
function clickListener()
216
    while true do
217
        tEvent = {os.pullEvent()}
218
        if tEvent[1] == "monitor_touch" then
219
            local o = tEvent[3]
220
            local n = tEvent[4]
221
            local m = n - 1 + scrollInt
222
            if n == max_y then
223
                if o > max_x - 13 or o < 13 then
224
                    if o < max_x - 7 and o > max_x - 13 or o < 13 and o < 6 then
225
                        scrollInt = scrollInt + 1
226
                        printButtons(true, false)
227
                    else
228
                        scrollInt = scrollInt - 1
229
                        printButtons(false, true)
230
                    end
231
                    sleep(0.1)
232
                    updateGUI(currentTable)
233
                end
234
            elseif currentTable[m] ~= nil then
235
                tarjetPlayer = currentTable[m]["name"]
236
                if tarjetPlayer ~= nil then
237
                    actualHighlight, m = isHighlight(tarjetPlayer)
238
                    if actualHighlight then
239
                        highlights[m] = nil
240
                    else
241
                        table.insert(highlights, tarjetPlayer)
242
                    end
243
                    updateGUI(currentTable)
244
                end
245
            end
246
        end
247
    end
248
end
249
function getCenter(w, x)
250
    if not x then
251
        x = ""
252
    end
253
    if w - string.len(x) % 2 == 0 then
254
        return math.floor((w - string.len(x)) / 2)
255
    end
256
    return math.floor((w - string.len(x)) / 2) + 1
257
end
258
function customPrint(y)
259
    term.clear()
260
    local max_x, max_y = term.getSize()
261
    term.setCursorPos(getCenter(max_x, y), getCenter(max_y))
262
    print(y)
263
end
264
function listeners()
265
    parallel.waitForAny(clickListener)
266
end
267
parallel.waitForAny(chatUpdater, listeners)
268
error()
269