Advertisement
GiantNuker

premote(Or P-Remote)

Apr 3rd, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.46 KB | None | 0 0
  1. -- P-Remote
  2. -- An api to help use remote peripherals
  3. -- Created by GiantNuker
  4.  
  5. -- Gets the side your wired modem is on
  6. function getModemSide()
  7.     side = ""
  8.     if peripheral.isPresent("front") then
  9.         if peripheral.getType("front")
  10.             side = "front"
  11.         end
  12.     else if peripheral.isPresent("back") then
  13.         if peripheral.getType("back")
  14.             side = "back"
  15.         end
  16.     else if peripheral.isPresent("up") then
  17.         if peripheral.getType("up")
  18.             side = "up"
  19.         end
  20.     else if peripheral.isPresent("down") then
  21.         if peripheral.getType("down")
  22.             side = "down"
  23.         end
  24.     else if peripheral.isPresent("left") then
  25.         if peripheral.getType("left")
  26.             side = "left"
  27.         end
  28.     else if peripheral.isPresent("right") then
  29.         if peripheral.getType("right")
  30.             side = "right"
  31.         end
  32.     return side
  33. end
  34.  
  35. -- Returns a modem object based on the above
  36. function getModem()
  37.     return peripheral.wrap(getModemSide())
  38. end
  39.  
  40. -- Gets the names of the peripherals using getNamesRemote()
  41. function getRemotePeripherals()
  42.     return getModem().getNamesRemote()
  43. end
  44.  
  45. -- Gets the methods of the peripherals using getMethodsRemote(peripheral)
  46. function getPeripheralMethods(peripheral)
  47.     return getModem().getMethodsRemote(peripheral)
  48. end
  49.  
  50. -- Checks if a certain peripheral is connected
  51. function hasRemotePeripheral(peripheral)
  52.     return getModem().isPresentRemote(peripheral)
  53. end
  54.  
  55. -- Calls a function of a selected peripheral
  56. function callRemoteMethod(peripheral, method)
  57.     return callRemote(peripheral, method)
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement