Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function startup()
- term.clear()
- sleep(0.1)
- rednet.open("back")
- readingOutput = {}
- blinkIsOn = true
- posData = {}
- scrollmenuLen={}
- scrollmenuInfos={}
- dropdown = {}
- dropdown["loaded"] = {}
- dropdown["loaded"]["len"] = 0
- os.startTimer(0.1)
- repeat
- rednet.send(935,"getPlayers")
- timer=os.startTimer(0.2)
- info1,info2,info3,info4 = os.pullEvent()
- os.cancelTimer(timer)
- until info1=="rednet_message" and info3["action"] == "sendingPlayers" and type(info3["players"]) == "table" or info1 == "timer"
- if info1 == "timer" then
- createDropdownMenu("players",{},3,6,18)
- createDropdownMenu("menuOptions",{"Home","Teleport"},3,4,16)
- else
- createDropdownMenu("players",info3["players"],3,6,18)
- knowsOnlinePlayers = true
- readPlayerPosData()
- if fs.exists("playerPos") then
- createDropdownMenu("menuOptions",{"Home","Teleport","Online Players"},3,4,16)
- else
- createDropdownMenu("menuOptions",{"Home","Teleport"},3,4,16)
- end
- end
- readPlayerPosData()
- end
- function main()
- while true do
- info1,info2,info3,info4 = os.pullEvent()
- overwriteDropdown()
- if dropdownMenuCheck("menuOptions") == "changed" then
- info1 = nil
- if dropdown["menuOptions"]["option1"] == "Home" then
- homeMenu()
- end
- if dropdown["menuOptions"]["option1"] == "Teleport" then
- teleportMenu()
- end
- if dropdown["menuOptions"]["option1"] == "Online Players" then
- onlinePlayersMenu()
- end
- end
- if info1 == "rednet_message" then
- if type(info3) == "table" then
- if info3["action"] == "sendingPosData" then
- for k,v in pairs(info3["posData"]) do
- file = fs.open("playerPos/"..info3["posData"][k]["day"].."/"..info3["posData"][k]["time"].."/"..info3["posData"][k]["player"],"w")
- file.writeLine(info3["posData"][k]["x"])
- file.writeLine(info3["posData"][k]["y"])
- file.writeLine(info3["posData"][k]["z"])
- file.write(info3["posData"][k]["dim"])
- file.flush()
- file.close()
- if type(posData[info3["posData"][k]["player"]]) ~= "table" then
- posData[info3["posData"][k]["player"]] = {}
- end
- posData[info3["posData"][k]["player"]][table.maxn(posData[info3["posData"][k]["player"]])+1] = info3["posData"][k]
- end
- printMenu(curEnv)
- end
- if info3["action"] == "sendingPlayers" and type(info3["players"]) == "table" then
- createDropdownMenu("players",info3["players"],3,6,18)
- if fs.exists("playerPos") then
- createDropdownMenu("menuOptions",{"Home","Teleport","Online Players"},3,4,16)
- end
- printMenu(curEnv)
- end
- end
- if type(info3) == "string" then
- if info3 == "ping" then
- rednet.send(info2,"pong")
- end
- end
- end
- if curEnv == "onlinePlayersMenu" then
- scrollOutput = checkScrollmenu("playerData")
- if scrollOutput ~= nil then
- if type(scrollOutput) == "number" then
- inspectPosDataMenu(dropdown["players"]["option1"],table.maxn(posData[dropdown["players"]["option1"]])-scrollOutput)
- end
- end
- if dropdownMenuCheck("players") == "changed" then
- onlinePlayersMenu()
- end
- end
- if curEnv == "inspectPosDataMenu" then
- if buttonCheck(46,17,51,19) then
- onlinePlayersMenu()
- end
- end
- end
- end
- function homeMenu()
- curEnv = "homeMenu"
- term.clear()
- closeDropdownMenus()
- loadDropdownMenu("menuOptions")
- end
- function teleportMenu()
- curEnv = "teleportMenu"
- term.clear()
- closeDropdownMenus()
- loadDropdownMenu("menuOptions")
- end
- function onlinePlayersMenu()
- term.setBackgroundColor(colors.black)
- curEnv = "onlinePlayersMenu"
- term.clear()
- closeDropdownMenus()
- loadDropdownMenu("menuOptions")
- loadDropdownMenu("players")
- scrollText = {}
- for k,v in pairs(posData[dropdown["players"]["option1"]]) do
- scrollText[k] = ""
- if os.day("local")-posData[dropdown["players"]["option1"]][k]["day"] == 0 then
- scrollText[k] = scrollText[k] .. "Today: "
- elseif os.day("local")-posData[dropdown["players"]["option1"]][k]["day"] == 1 then
- scrollText[k] = scrollText[k] .. os.day("local")-posData[dropdown["players"]["option1"]][k]["day"] .. " Day Ago: "
- else
- scrollText[k] = scrollText[k] .. os.day("local")-posData[dropdown["players"]["option1"]][k]["day"] .. " Days Ago: "
- end
- scrollText[k] = scrollText[k] .. posData[dropdown["players"]["option1"]][k]["x"] .. " " .. posData[dropdown["players"]["option1"]][k]["y"] .. " " .. posData[dropdown["players"]["option1"]][k]["z"]
- end
- tableLen = table.maxn(scrollText)
- saveScrollText = {}
- for i=1,tableLen do
- saveScrollText[tableLen-i+1] = scrollText[i-1]
- end
- scrollText = saveScrollText
- createScrollmenu("playerData",22,1,51,19,scrollText,0)
- printScrollmenu("playerData")
- end
- function readPlayerPosData()
- if fs.exists("playerPos") then
- for k1,v1 in pairs(fs.list("playerPos")) do
- curDay = fs.list("playerPos")[k1]
- for k2,v2 in pairs(fs.list("playerPos/"..curDay)) do
- curTime = fs.list("playerPos/"..curDay)[k2]
- for k3,v3 in pairs(fs.list("playerPos/"..curDay.."/"..curTime)) do
- curPlayer = fs.list("playerPos/"..curDay.."/"..curTime)[k3]
- if fs.exists("playerPos/"..curDay.."/"..curTime.."/"..curPlayer) then
- file = fs.open("playerPos/"..curDay.."/"..curTime.."/"..curPlayer,"r")
- curPosData = {}
- curPosData["day"]=curDay
- curPosData["time"]=curTime
- curPosData["x"]=file.readLine()
- curPosData["y"]=file.readLine()
- curPosData["z"]=file.readLine()
- curPosData["dim"]=file.readLine()
- file.close()
- if type(posData[curPlayer]) ~= "table" then
- posData[curPlayer] = {}
- posData[curPlayer][1] = curPosData
- else
- posData[curPlayer][table.maxn(posData[curPlayer])+1] = curPosData
- end
- end
- end
- end
- end
- end
- end
- function inspectPosDataMenu(player,number)
- term.setBackgroundColor(colors.black)
- term.clear()
- closeDropdownMenus()
- curEnv = "inspectPosDataMenu"
- headline(player)
- button("Back",46,17,51,19)
- term.setCursorPos(1,4)
- term.setTextColor(colors.green)
- term.write("Day: ")
- term.setTextColor(colors.white)
- print(posData[player][number]["day"])
- term.setTextColor(colors.green)
- term.write("Time: ")
- term.setTextColor(colors.white)
- print(posData[player][number]["time"])
- print("")
- term.setTextColor(colors.green)
- term.write("Dim: ")
- term.setTextColor(colors.white)
- print(posData[player][number]["dim"])
- print("")
- term.setTextColor(colors.green)
- term.write("X: ")
- term.setTextColor(colors.white)
- print(posData[player][number]["x"])
- term.setTextColor(colors.green)
- term.write("Y: ")
- term.setTextColor(colors.white)
- print(posData[player][number]["y"])
- term.setTextColor(colors.green)
- term.write("Z: ")
- term.setTextColor(colors.white)
- print(posData[player][number]["z"])
- end
- -- buttons and all that stuff
- function betterRead(isBlacklist,filter)
- if curReading ~= nil then
- if curReadingPosX == nil then
- curReadingPosX = readingPosX+string.len(readingOutput[curReading])
- end
- if cursorBlinkTimer == nil then
- cursorBlinkTimer = os.startTimer(0.5)
- end
- if info1 == "char" then
- isBlacklisted = not isBlacklist
- for k,v in pairs(filter) do
- if info2 == filter[k] then
- isBlacklisted = isBlacklist
- end
- end
- if not isBlacklisted then
- if readingOutput[curReading] == nil then
- readingOutput[curReading] = ""
- end
- readingOutput[curReading] = readingOutput[curReading] .. info2
- term.setCursorPos(curReadingPosX,readingPosY)
- term.write(info2)
- curReadingPosX = curReadingPosX+1
- if blinkIsOn then
- term.write("_")
- end
- end
- end
- if info1 == "key" and info2 == 259 and curReadingPosX > readingPosX then
- curReadingPosX = curReadingPosX-1
- term.setCursorPos(curReadingPosX+1,readingPosY)
- term.write(" ")
- term.setCursorPos(curReadingPosX,readingPosY)
- if blinkIsOn then
- term.write("_")
- else
- term.write(" ")
- end
- readSave = readingOutput[curReading]
- readingOutput[curReading] = ""
- for i=1,string.len(readSave)-1 do
- readingOutput[curReading] = readingOutput[curReading] .. string.char(string.byte(readSave,i))
- end
- end
- if info1 == "timer" and info2 == cursorBlinkTimer then
- if blinkIsOn then
- term.setCursorPos(curReadingPosX,readingPosY)
- term.write("_")
- else
- term.setCursorPos(curReadingPosX,readingPosY)
- term.write(" ")
- end
- cursorBlinkTimer = os.startTimer(0.5)
- blinkIsOn = (not blinkIsOn)
- end
- end
- end
- function changeReading(readingName,xPos,yPos)
- if type(curReadingPosX) == "number" and type(readingPosY) == "number" then
- term.setCursorPos(curReadingPosX,readingPosY)
- term.write(" ")
- end
- blinkIsOn = true
- curReading = readingName
- readingPosX = xPos
- readingPosY = yPos
- curReadingPosX = nil
- cursorBlinkTimer = os.startTimer(0.05)
- end
- function stopReading()
- term.setCursorPos(curReadingPosX,readingPosY)
- term.write(" ")
- curReading = nil
- cursorBlinkTimer = nil
- end
- function resetEvent()
- info1 = nil
- end
- function createScrollmenu(name,x1,y1,x2,y2,content,position)
- scrollmenuLen[name]=0
- scrollmenuInfos[name]={["x1"]=x1,["y1"]=y1,["x2"]=x2,["y2"]=y2,["content"]=content,["position"]=position}
- for k,v in pairs(content) do
- if content[k] ~= nil then
- scrollmenuLen[name]=scrollmenuLen[name]+1
- else
- for i=1,table.maxn(content)-scrollmenuLen[name] do
- content[scrollmenuLen[name]+i] = content[scrollmenuLen[name]+1+i]
- end
- end
- end
- end
- function printScrollmenu(name)
- for i=1,math.min(scrollmenuLen[name],scrollmenuInfos[name]["y2"]-scrollmenuInfos[name]["y1"]+1) do
- if (i+scrollmenuInfos[name]["position"])%2==0 then
- term.setBackgroundColor(colors.gray)
- else
- term.setBackgroundColor(colors.black)
- end
- term.setCursorPos(scrollmenuInfos[name]["x1"],scrollmenuInfos[name]["y1"]+i-1)
- term.write(scrollmenuInfos[name]["content"][i+scrollmenuInfos[name]["position"]])
- for i2=1,scrollmenuInfos[name]["x2"]-scrollmenuInfos[name]["x1"]+1-string.len(scrollmenuInfos[name]["content"][i+scrollmenuInfos[name]["position"]]) do
- term.write(" ")
- end
- end
- end
- function checkScrollmenu(name)
- if info1 == "mouse_click" and info3 > scrollmenuInfos[name]["x1"]-1 and info3 < scrollmenuInfos[name]["x2"]+1 and info4 > scrollmenuInfos[name]["y1"]-1 and info4 < scrollmenuInfos[name]["y2"]+1 then
- resetEvent()
- return scrollmenuInfos[name]["position"]+info4-scrollmenuInfos[name]["y1"]+1
- end
- if info1 == "mouse_scroll" and not (scrollmenuInfos[name]["position"]+info2 > scrollmenuLen[name]-(scrollmenuInfos[name]["y2"]-scrollmenuInfos[name]["y1"]+1)) and not (scrollmenuInfos[name]["position"]+info2 < 0) then
- scrollmenuInfos[name]["position"] = scrollmenuInfos[name]["position"] + info2
- printScrollmenu(name)
- end
- end
- function headline(headline)
- width = term.getSize()
- headline_lenght=string.len(" "..headline.." ")
- headline_pos=(width/2)-(headline_lenght/2)+1
- term.setCursorPos(headline_pos,1)
- term.setBackgroundColor(colors.yellow)
- term.setTextColor(colors.blue)
- term.write(" "..headline.." ")
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- function button(button_text,button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,button_color)
- term.setTextColor(colors.green)
- if button_color~=nil then
- term.setTextColor(button_color)
- end
- square(button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,colors.black,"-","|")
- term.setCursorPos(math.ceil(button_pos_x1-string.len(button_text)/2+(button_pos_x2-button_pos_x1)/2),button_pos_y1+(button_pos_y2-button_pos_y1)/2)
- term.write(button_text)
- end
- function buttonCheck(b_check_x1,b_check_y1,b_check_x2,b_check_y2)
- if info1=="mouse_click" and info3 > b_check_x1-1 and info3 < b_check_x2+1 and info4 > b_check_y1-1 and info4 < b_check_y2+1 then
- resetEvent()
- return true
- else
- return false
- end
- end
- function square(x1,y1,x2,y2,back_color_square,symbol_square_x,symbol_square_y,text_color)
- x_1=x1
- y_1=y1
- x_2=x2
- y_2=y2
- while x_1~=x2+1 do
- term.setBackgroundColor(back_color_square)
- term.setCursorPos(x_1,y_1)
- if text_color~=nil then
- term.setTextColor(text_color)
- end
- term.write(symbol_square_x)
- x_1=x_1+1
- end
- while y_1~=y2-1 do
- term.setCursorPos(x_1-1,y_1+1)
- term.write(symbol_square_y)
- y_1=y_1+1
- end
- x2=x2-1
- while x_2~=x1-1 do
- term.setCursorPos(x_2,y_2)
- term.write(symbol_square_x)
- x_2=x_2-1
- end
- while y_2~=y1+1 do
- term.setCursorPos(x_2+1,y_2-1)
- term.write(symbol_square_y)
- y_2=y_2-1
- end
- term.setBackgroundColor(colors.black)
- end
- function overwriteDropdown()
- for i=1,dropdown["loaded"]["len"] do
- if not dropdown[dropdown["loaded"][i]]["is_open"] then
- if info1=="mouse_click" and info3 < dropdown[dropdown["loaded"][i]]["pos_x2"]+1 and info3 > dropdown[dropdown["loaded"][i]]["pos_x1"]-1 and info4==dropdown[dropdown["loaded"][i]]["pos_y"] then
- info1 = "dropdown_menu"
- end
- else
- if info1=="mouse_click" and info3 < dropdown[dropdown["loaded"][i]]["pos_x2"]+1 and info3 > dropdown[dropdown["loaded"][i]]["pos_x1"]-1 and info4 < dropdown[dropdown["loaded"][i]]["pos_y"]+dropdown[dropdown["loaded"][i]]["len"] and info4 > dropdown[dropdown["loaded"][i]]["pos_y"]-1 then
- info1 = "dropdown_menu"
- end
- end
- end
- end
- function closeDropdownMenus()
- dropdown["loaded"]["len"]=0
- end
- function createDropdownMenu(name,options,pos_x1,pos_y,pos_x2)
- dropdown[name] = {}
- dropdown[name]["pos_x1"] = pos_x1
- dropdown[name]["pos_x2"] = pos_x2
- dropdown[name]["pos_y"] = pos_y
- dropdown[name]["is_open"] = false
- dropdown[name]["len"] = 0
- i=1
- while options[i]~= nil do
- dropdown[name]["len"] = dropdown[name]["len"]+1
- dropdown[name]["option"..i] = options[i]
- i=i+1
- end
- end
- function printDropdownMenu(name)
- for i=1,dropdown[name]["len"] do
- term.setCursorPos(dropdown[name]["pos_x1"],dropdown[name]["pos_y"]+i-1)
- if not (i%2==0) then
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- else
- term.setBackgroundColor(colors.lightGray)
- term.setTextColor(colors.black)
- end
- if dropdown[name]["is_open"] or i==1 then
- term.write(dropdown[name]["option"..i])
- for i1=1,(dropdown[name]["pos_x2"]-dropdown[name]["pos_x1"])-string.len(dropdown[name]["option"..i])+1 do
- term.write(" ")
- end
- end
- end
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- function dropdownMenuCheck(name)
- if dropdown[name]["is_open"] then
- if info1=="dropdown_menu" and info3 < dropdown[name]["pos_x2"]+1 and info3 > dropdown[name]["pos_x1"]-1 and info4==dropdown[name]["pos_y"] then
- dropdown[name]["is_open"]=false
- printMenu(curEnv)
- return "closed"
- end
- if info1=="dropdown_menu" and info3 < dropdown[name]["pos_x2"]+1 and info3 > dropdown[name]["pos_x1"]-1 and info4 < dropdown[name]["pos_y"]+dropdown[name]["len"]+1 and info4 > dropdown[name]["pos_y"] then
- option_save = dropdown[name]["option"..1]
- dropdown[name]["option"..1] = dropdown[name]["option"..info4-dropdown[name]["pos_y"]+1]
- dropdown[name]["option"..info4-dropdown[name]["pos_y"]+1] = option_save
- dropdown[name]["is_open"]=false
- printMenu(curEnv)
- return "changed"
- end
- else
- if info1=="dropdown_menu" and info3 < dropdown[name]["pos_x2"]+1 and info3 > dropdown[name]["pos_x1"]-1 and info4==dropdown[name]["pos_y"] then
- dropdown[name]["is_open"]=true
- printDropdownMenu(name)
- return "opened"
- end
- end
- end
- function loadDropdownMenu(name)
- dropdown["loaded"]["len"] = dropdown["loaded"]["len"]+1
- dropdown["loaded"][dropdown["loaded"]["len"]] = name
- printDropdownMenu(name)
- end
- function printMenu(env)
- if env=="homeMenu" then
- homeMenu()
- end
- if env=="teleportMenu" then
- teleportMenu()
- end
- if env=="onlinePlayersMenu" then
- onlinePlayersMenu()
- end
- end
- function filled_square(fill_x1,fill_y1,fill_x2,fill_y2,fill_color)
- term.setBackgroundColor(fill_color)
- curr_fill_pos_x=fill_x1
- curr_fill_pos_y=fill_y1
- while curr_fill_pos_y~=fill_y2+1 do
- while curr_fill_pos_x~=fill_x2+1 do
- term.setCursorPos(curr_fill_pos_x,curr_fill_pos_y)
- term.write(" ")
- curr_fill_pos_x=curr_fill_pos_x+1
- end
- curr_fill_pos_x=fill_x1
- curr_fill_pos_y=curr_fill_pos_y+1
- end
- term.setBackgroundColor(colors.black)
- end
- function lineCheck(y)
- if info1 == "mouse_click" and info4 == y then
- return true
- else
- return false
- end
- end
- -------------------------------------------------
- startup()
- homeMenu()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement