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