Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Credit to Mikeemoo for creating OpenPeripheral
- --API written by Bubba
- local function load()
- if not os.loadAPI("ocs/apis/sensor") then
- print("This program requires an OpenCCSensor to run.")
- return false
- end
- local prox
- local bridge
- for k,v in pairs(rs.getSides()) do
- if peripheral.getType(v) == "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 or not bridge then
- print("Ending program...")
- return
- end
- scaleFactor = 3.0
- screenX, screenY = 480, 255
- mouseX, mouseY = 0,0
- local allTargets = {}
- local function checkPlayer(name)
- local target = prox.getTargetDetails(name)
- if not target then
- return false
- end
- return target.IsSneaking,
- (scaleFactor * (target.Yaw - allTargets[name].Yaw)/180), -- X percentage
- (scaleFactor * (target.Pitch - allTargets[name].Pitch)/90) -- Y percentage
- end
- local mouseOBJ
- function startMouse(size, color, opacity, scale)
- for name, data in pairs(prox.getTargets()) do
- allTargets[name] = prox.getTargetDetails(name)
- end
- mouseOBJ = bridge.addBox(1, 1, size,size, color, opacity)
- scaleFactor = scale or scaleFactor
- return true
- end
- function resetMouse()
- for name, data in pairs(prox.getTargets()) do
- allTargets[name] = prox.getTargetDetails(name)
- end
- end
- function setScreenSize(width, height)
- screenX,screenY = width, height
- end
- function setScaleFactor(scale)
- scaleFactor = scale
- end
- function waitForClick(username)
- 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)
- for name, target in pairs(prox.getTargets()) do
- allTargets[name] = prox.getTargetDetails(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