Advertisement
GravityCube

ClanTracker

Mar 2nd, 2018 (edited)
2,743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.12 KB | None | 0 0
  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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement