Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Credit to Mikeemoo for creating OpenPeripheral + OpenPeripheralAddons
- --API written by Bubba
- local function load() --This function will automatically wrap the peripherals required for it to run
- local prox
- local bridge
- for k,v in pairs(rs.getSides()) do
- if peripheral.getType(v) == "openperipheral_sensor" then
- prox = sensor.wrap(v)
- elseif peripheral.getType(v) and string.match(peripheral.getType(v),"bridge") then
- bridge = peripheral.wrap(v)
- end
- end
- return prox, bridge
- end
- local prox, bridge = load()
- if not prox then
- print("This program requires an OpenPeripheral-Sensor in order to run")
- return
- end
- if not bridge then
- print("This program requires a terminal glasses bridge in order to run")
- return
- end
- scaleFactor = 3.0 --This variable controls the speed of the mouse. A higher number indicates a faster speed.
- screenX, screenY = 480, 255 --This is the size of your screen. You can adjust this manually or you can use the built-in function, getScreenSize
- mouseX, mouseY = 0,0 --These variables keep track of the mouse position as it moves.
- local allTargets = {} --This will store the initial Yaw of the player so that the mouse can be centered on the screen
- local function checkPlayer(name) --This function returns the distance from the left side of the screen as a percentage value
- local target = prox.getPlayerData(name)
- if not target then
- return false
- end
- return target.IsSneaking,
- (scaleFactor * (target.Yaw - allTargets[name].Yaw)/180), -- X percentage
- (scaleFactor * (target.Pitch/90)) -- Y percentage
- end
- local mouseOBJ --This is where we create our mouse box
- function startMouse(size, color, opacity, scale) --This populates the allTargets table and creates the mouse box
- for name, data in pairs(prox.getTargets()) do
- allTargets[name] = prox.getPlayerData(name)
- end
- mouseOBJ = bridge.addBox(1, 1, size,size, color, opacity)
- scaleFactor = scale or scaleFactor
- return true
- end
- function resetMouse() --This recenters the mouse
- for name, data in pairs(prox.getPlayerNames()) do
- allTargets[name] = prox.getPlayerData(name)
- end
- end
- function setScreenSize(width, height) --Sets the screen size variables
- screenX,screenY = width, height
- end
- function setScaleFactor(scale) --Sets the mouse speed
- scaleFactor = scale
- end
- function waitForClick(username) --Draws/Updates the mouse and when the player sneaks returns their x/y coordinates
- if not mouseOBJ then
- return false
- end
- while true do
- local isClicked, mX, mY = checkPlayer(username)
- mouseX = math.floor(screenX/2) + math.floor(mX*screenX/2)
- mouseY = math.floor(screenY/2) + math.floor(mY*screenY/2)
- if isClicked then
- return mouseX, mouseY
- end
- mouseOBJ.setX(mouseX)
- mouseOBJ.setY(mouseY)
- end
- end
- function getScreenSize(username) --Creates a red box that moves along with the mouse in order to get the screen size easily.
- for name, target in pairs(prox.getPlayerNames()) do
- allTargets[name] = prox.getPlayerData(name)
- end
- local sX, sY = 1,1
- local screenObject = bridge.addBox(0,0,sX, sY, 0xCC0000, 0.4)
- while true do
- local isClicked, sfX, sfY = checkPlayer(username)
- sX = math.floor(sfX*700)
- sY = math.floor(sfY*400)
- screenObject.setWidth(sX)
- screenObject.setHeight(sY)
- if isClicked then
- screenObject.delete()
- return sX, sY
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement