SHOW:
|
|
- or go back to the newest paste.
| 1 | --Credit to Mikeemoo for creating OpenPeripheral | |
| 2 | --API written by Bubba | |
| 3 | ||
| 4 | - | local function load() |
| 4 | + | local function load() --This function will automatically wrap the peripherals required for it to run |
| 5 | - | if not os.loadAPI("ocs/apis/sensor") then
|
| 5 | + | if not os.loadAPI("ocs/apis/sensor") then
|
| 6 | - | print("This program requires an OpenCCSensor to run.")
|
| 6 | + | print("This program requires an OpenCCSensor to run.")
|
| 7 | - | return false |
| 7 | + | return false |
| 8 | - | end |
| 8 | + | end |
| 9 | - | local prox |
| 9 | + | local prox |
| 10 | - | local bridge |
| 10 | + | local bridge |
| 11 | - | for k,v in pairs(rs.getSides()) do |
| 11 | + | for k,v in pairs(rs.getSides()) do |
| 12 | - | if peripheral.getType(v) == "sensor" then |
| 12 | + | if peripheral.getType(v) == "sensor" then |
| 13 | - | prox = sensor.wrap(v) |
| 13 | + | prox = sensor.wrap(v) |
| 14 | - | elseif peripheral.getType(v) and string.match(peripheral.getType(v),"bridge") then |
| 14 | + | elseif peripheral.getType(v) and string.match(peripheral.getType(v),"bridge") then |
| 15 | - | bridge = peripheral.wrap(v) |
| 15 | + | bridge = peripheral.wrap(v) |
| 16 | - | end |
| 16 | + | end |
| 17 | - | end |
| 17 | + | end |
| 18 | - | return prox, bridge |
| 18 | + | return prox, bridge |
| 19 | end | |
| 20 | ||
| 21 | local prox, bridge = load() | |
| 22 | - | if not prox or not bridge then |
| 22 | + | if not prox then |
| 23 | - | print("Ending program...")
|
| 23 | + | print("This program requires an OpenCCSensor with a proximity card in order to run")
|
| 24 | - | return |
| 24 | + | return |
| 25 | end | |
| 26 | if not bridge then | |
| 27 | - | scaleFactor = 3.0 |
| 27 | + | print("This program requires a terminal glasses bridge in order to run")
|
| 28 | - | screenX, screenY = 480, 255 |
| 28 | + | return |
| 29 | - | mouseX, mouseY = 0,0 |
| 29 | + | |
| 30 | ||
| 31 | - | local allTargets = {}
|
| 31 | + | scaleFactor = 3.0 --This variable controls the speed of the mouse. A higher number indicates a faster speed. |
| 32 | 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 | |
| 33 | - | local function checkPlayer(name) |
| 33 | + | mouseX, mouseY = 0,0 --These variables keep track of the mouse position as it moves. |
| 34 | - | local target = prox.getTargetDetails(name) |
| 34 | + | |
| 35 | - | if not target then |
| 35 | + | local allTargets = {} --This will store the initial Yaw of the player so that the mouse can be centered on the screen
|
| 36 | - | return false |
| 36 | + | |
| 37 | - | end |
| 37 | + | local function checkPlayer(name) --This function returns the distance from the left side of the screen as a percentage value |
| 38 | local target = prox.getTargetDetails(name) | |
| 39 | - | return target.IsSneaking, |
| 39 | + | if not target then |
| 40 | - | (scaleFactor * (target.Yaw - allTargets[name].Yaw)/180), -- X percentage |
| 40 | + | return false |
| 41 | - | (scaleFactor * (target.Pitch - allTargets[name].Pitch)/90) -- Y percentage |
| 41 | + | end |
| 42 | ||
| 43 | return target.IsSneaking, | |
| 44 | - | local mouseOBJ |
| 44 | + | (scaleFactor * (target.Yaw - allTargets[name].Yaw)/180), -- X percentage |
| 45 | (scaleFactor * (target.Pitch/90) -- Y percentage | |
| 46 | - | function startMouse(size, color, opacity, scale) |
| 46 | + | |
| 47 | - | for name, data in pairs(prox.getTargets()) do |
| 47 | + | |
| 48 | - | allTargets[name] = prox.getTargetDetails(name) |
| 48 | + | local mouseOBJ --This is where we create our mouse box |
| 49 | - | end |
| 49 | + | |
| 50 | - | mouseOBJ = bridge.addBox(1, 1, size,size, color, opacity) |
| 50 | + | function startMouse(size, color, opacity, scale) --This populates the allTargets table and creates the mouse box |
| 51 | - | scaleFactor = scale or scaleFactor |
| 51 | + | for name, data in pairs(prox.getTargets()) do |
| 52 | - | return true |
| 52 | + | allTargets[name] = prox.getTargetDetails(name) |
| 53 | end | |
| 54 | mouseOBJ = bridge.addBox(1, 1, size,size, color, opacity) | |
| 55 | - | function resetMouse() |
| 55 | + | scaleFactor = scale or scaleFactor |
| 56 | - | for name, data in pairs(prox.getTargets()) do |
| 56 | + | return true |
| 57 | - | allTargets[name] = prox.getTargetDetails(name) |
| 57 | + | |
| 58 | - | end |
| 58 | + | |
| 59 | function resetMouse() --This recenters the mouse | |
| 60 | for name, data in pairs(prox.getTargets()) do | |
| 61 | - | function setScreenSize(width, height) |
| 61 | + | allTargets[name] = prox.getTargetDetails(name) |
| 62 | - | screenX,screenY = width, height |
| 62 | + | end |
| 63 | end | |
| 64 | ||
| 65 | - | function setScaleFactor(scale) |
| 65 | + | function setScreenSize(width, height) --Sets the screen size variables |
| 66 | - | scaleFactor = scale |
| 66 | + | screenX,screenY = width, height |
| 67 | end | |
| 68 | ||
| 69 | - | function waitForClick(username) |
| 69 | + | function setScaleFactor(scale) --Sets the mouse speed |
| 70 | - | if not mouseOBJ then |
| 70 | + | scaleFactor = scale |
| 71 | - | return false |
| 71 | + | |
| 72 | - | end |
| 72 | + | |
| 73 | - | while true do |
| 73 | + | function waitForClick(username) --Draws/Updates the mouse and when the player sneaks returns their x/y coordinates |
| 74 | - | local isClicked, mX, mY = checkPlayer(username) |
| 74 | + | if not mouseOBJ then |
| 75 | - | mouseX = math.floor(screenX/2) + math.floor(mX*screenX/2) |
| 75 | + | return false |
| 76 | - | mouseY = math.floor(screenY/2) + math.floor(mY*screenY/2) |
| 76 | + | end |
| 77 | - | if isClicked then |
| 77 | + | while true do |
| 78 | - | return mouseX, mouseY |
| 78 | + | local isClicked, mX, mY = checkPlayer(username) |
| 79 | - | end |
| 79 | + | mouseX = math.floor(screenX/2) + math.floor(mX*screenX/2) |
| 80 | - | mouseOBJ.setX(mouseX) |
| 80 | + | mouseY = math.floor(screenY/2) + math.floor(mY*screenY/2) |
| 81 | - | mouseOBJ.setY(mouseY) |
| 81 | + | if isClicked then |
| 82 | - | end |
| 82 | + | return mouseX, mouseY |
| 83 | end | |
| 84 | mouseOBJ.setX(mouseX) | |
| 85 | - | function getScreenSize(username) |
| 85 | + | mouseOBJ.setY(mouseY) |
| 86 | - | for name, target in pairs(prox.getTargets()) do |
| 86 | + | end |
| 87 | - | allTargets[name] = prox.getTargetDetails(name) |
| 87 | + | |
| 88 | - | end |
| 88 | + | |
| 89 | function getScreenSize(username) --Creates a red box that moves along with the mouse in order to get the screen size easily. | |
| 90 | - | local sX, sY = 1,1 |
| 90 | + | for name, target in pairs(prox.getTargets()) do |
| 91 | - | local screenObject = bridge.addBox(0,0,sX, sY, 0xCC0000, 0.4) |
| 91 | + | allTargets[name] = prox.getTargetDetails(name) |
| 92 | - | while true do |
| 92 | + | end |
| 93 | - | local isClicked, sfX, sfY = checkPlayer(username) |
| 93 | + | |
| 94 | - | sX = math.floor(sfX*700) |
| 94 | + | local sX, sY = 1,1 |
| 95 | - | sY = math.floor(sfY*400) |
| 95 | + | local screenObject = bridge.addBox(0,0,sX, sY, 0xCC0000, 0.4) |
| 96 | while true do | |
| 97 | - | screenObject.setWidth(sX) |
| 97 | + | local isClicked, sfX, sfY = checkPlayer(username) |
| 98 | - | screenObject.setHeight(sY) |
| 98 | + | sX = math.floor(sfX*700) |
| 99 | - | if isClicked then |
| 99 | + | sY = math.floor(sfY*400) |
| 100 | - | screenObject.delete() |
| 100 | + | |
| 101 | - | return sX, sY |
| 101 | + | screenObject.setWidth(sX) |
| 102 | - | end |
| 102 | + | screenObject.setHeight(sY) |
| 103 | - | end |
| 103 | + | if isClicked then |
| 104 | screenObject.delete() | |
| 105 | return sX, sY | |
| 106 | end | |
| 107 | end | |
| 108 | end |