Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- What can I say...
- I guess I finally decided to clean this code up.
- ]]--
- coords = {}
- players = {}
- --Kept this because why the hell not.
- username = "Herro"
- loc = 1
- bacon = true
- --Beginning of functions section (What, I like to have it all in one file...)
- --Gets the charge. Just an attempt to keep my code more clean
- function getcharge()
- if data.heldItem.energyStored ~= nil then
- charge = math.ceil((data.heldItem.energyStored / data.heldItem.maxEnergyStored) * 100)
- elseif data.heldItem.electric ~= nil then
- charge = math.ceil((data.heldItem.electric.charge / data.heldItem.electric.maxCharge) * 100)
- else
- charge = "N/A"
- end
- if charge ~= "N/A" then
- charge = charge.."%"
- end
- return charge
- end
- -- Adds Freaking Magical Boxes (Slowly adds gradient boxes for added effect)
- function addmagicalBox(x,y,width,height,color,opacity,colorend,opacityend, direction)
- name = terminal.addGradientBox(x,y,1,height,color,opacity,colorend,opacityend,direction)
- for newidth=1,width do
- sleep(0.01)
- name.setWidth(newidth)
- end
- end
- --This is just incase CC derps on me.
- for i = 1,10 do
- table.remove(players, i)
- end
- --If the coordinates don't exist, it gets the coordinates.
- existingcoords = fs.exists("sensorlocation")
- if existingcoords == false then
- term.clear()
- term.setCursorPos(1,1)
- term.write("X: ")
- x = read()
- term.setCursorPos(1,2)
- term.write("Y: ")
- y = read()
- term.setCursorPos(1,3)
- term.write("Z: ")
- z = read()
- coords.x = x
- coords.y = y
- coords.z = z
- output = textutils.serialize(coords)
- handle = assert(fs.open("sensorlocation", "w"), "Couldn't save vars")
- handle.write(output)
- handle.close()
- end
- --Loads the coordinates from the file
- handle = assert(fs.open("sensorlocation", "r"), "Couldn't load vars")
- input = handle.readAll()
- coords = textutils.unserialize(input)
- locx = coords.x
- locy = coords.y
- locz = coords.z
- for k, v in pairs(peripheral.getNames()) do
- type = peripheral.getType(v)
- if type == "openperipheral_sensor" then
- sensor = peripheral.wrap(v)
- print("sensor wrapped as sensor on side: "..v)
- elseif type == "openperipheral_glassesbridge" then
- terminal = peripheral.wrap(v)
- print("Bridge wrapped as terminal on side: "..v)
- end
- end
- -- Adds Freaking Magical Boxes
- function addmagicalBox(x,y,width,height,color,opacity,colorend,opacityend, direction)
- name = terminal.addGradientBox(x,y,1,height,color,opacity,colorend,opacityend,direction)
- for newidth=1,width do
- sleep(0.01)
- name.setWidth(newidth)
- end
- end
- --Adds the boxes and text
- function initialize()
- sleep(2)
- terminal.clear()
- text = terminal.addText(12,15, "Loading...", 0xFFFFFF)
- text.setScale(0.5)
- xtext = terminal.addText(12,35, "Loading...", 0xFFFFFF)
- xtext.setScale(0.5)
- ytext = terminal.addText(12,55, "Loading...", 0xFFFFFF)
- ytext.setScale(0.5)
- ztext = terminal.addText(12,75,"Loading...",0xFFFFFF)
- ztext.setScale(0.5)
- dirtext = terminal.addText(242,40,"Loading...",0xFFFFFF)
- dirtext.setScale(0.5)
- healthtext = terminal.addText(42,35, "Loading...",0xFFFFFF)
- healthtext.setScale(0.5)
- holdingtext = terminal.addText(42,55, "Loading...",0xFFFFFF)
- holdingtext.setScale(0.5)
- chargetext = terminal.addText(42,75, "Loading...",0xFFFFFF)
- chargetext.setScale(0.5)
- addmagicalBox(10,10,100,10,0x00FFFF,0.5, 0x336699, 0, 1)
- addmagicalBox(10,30,25,10,0x00FFFF,0.5, 0x336699, 0, 1)
- addmagicalBox(10,50,25,10,0x00FFFF,0.5, 0x336699, 0, 1)
- addmagicalBox(10,70,25,10,0x00FFFF,0.5, 0x336699, 0, 1)
- addmagicalBox(240,35,50,10,0x00FFFF,0.5, 0x336699, 0, 1)
- addmagicalBox(40,30,70,10,0x00FFFF,0.5,0x336699,0,1)
- addmagicalBox(40,50,70,10,0x00FFFF,0.5,0x336699,0,1)
- addmagicalBox(40,70,70,10,0x00FFFF,0.5,0x336699,0,1)
- end
- --Functions for user input while still displaying dynamic data (Harder than one might think)
- --Accepts user input
- function two()
- e, msg, b, c, a = os.pullEvent("chat_command")
- --Will fetch username
- if msg == "next" then
- print("Next!")
- if players[loc + 1] ~= nil then
- loc = loc + 1
- username = players[loc]
- print(username.." : "..tostring(loc))
- else
- loc = 1
- end
- end
- if string.find(msg, "add") then
- print("ADD!")
- subloc = string.find(msg, " ")
- username = string.sub(msg, subloc + 1)
- table.insert(players, username)
- end
- end
- --Just cuz sleeping is fun
- function three()
- sleep(1)
- end
- --Adds players currently using glasses to the table.
- for k, v in pairs(terminal.getUsers()) do
- table.insert(players, v)
- end
- --End of the functions section.
- --Just running functions...
- initialize()
- --For debugging purposes
- print(loc)
- print(players[loc])
- --Creating coroutines. (This shit is advanced man)
- --DONT QUESTION MY NAMING CONVENTIONS BITCH
- local uinput = coroutine.create(two)
- local sleepin = coroutine.create(three)
- while true do
- --dynamic data
- username = players[loc]
- data = sensor.getPlayerData(username)
- --[[You see, the sensor calculates x y and z as the distance from the sensor. So adding the location of the sensor
- to the distance rectifies this issue.
- That's why I have the "calibration"
- ]]--
- x = data.position.x + locx
- y = data.position.y + locy
- z = data.position.z + locz
- --calculates direction based on yaw
- yaw = data.yaw
- if yaw<225 and yaw>135 then
- direction = "North"
- elseif yaw>223 and yaw<311 then
- direction = "East"
- elseif yaw>309 then
- direction = "South"
- elseif yaw<46 then
- direction = "South"
- elseif yaw>44 and yaw<135 then
- direction = "West"
- else
- direction = "N/A"
- end
- --Updates the gui with the data
- chargetext.setText("Charge: "..getcharge())
- healthtext.setText("Health: "..math.ceil(tostring(math.ceil(data.health)) / tostring(math.ceil(data.maxHealth)) * 100).."%")
- holdingtext.setText("Holding: "..data.heldItem.name)
- dirtext.setText("Facing: "..direction)
- xtext.setText("X: "..math.floor(x))
- ytext.setText("Y: "..math.floor(y))
- ztext.setText("Z: "..math.floor(z))
- text.setText("Username: "..username)
- parallel.waitForAny(two, three)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement