Advertisement
dexman545

DexPI

Dec 27th, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. --DexPI by dexman545 (kev12east)
  2.  
  3. --FS API
  4. --This will read/write a table of "text" to "file"
  5. --to use do text = "<text to be written>"
  6. function fWrite(f)
  7. local file = fs.open(f, "w")
  8. dbs = textutils.serialize(text)
  9. file.write(dbs)
  10. file.close()
  11. end
  12.  
  13. function fRead(f)
  14. local file = fs.open(f, "r")
  15. text = textutils.unserialize(file.readAll())
  16. return text
  17. end
  18.  
  19. --Returns list of peripherals matching pname conected with networking cables
  20. function listPer(pname)
  21. local pers = peripheral.getNames()
  22. local perList = {}
  23. for i,v in pairs(pers) do
  24. if string.find(v, pname) then
  25. table.insert(perList, v)
  26. end
  27. end
  28. return perList
  29. end
  30.  
  31. --finds a monitor next to the computer
  32. function getMon()
  33. for i,s in ipairs(redstone.getSides()) do
  34. mon = peripheral.wrap(s)
  35. if mon then break end
  36. end
  37. end
  38.  
  39. --clears text, sets cursor position to x, y
  40. function clear(x, y)
  41. term.clear()
  42. term.setCursorPos(x,y)
  43. end
  44.  
  45. --gets computers location via a GPS tower
  46. function getLoc()
  47. x, y, z = gps.locate(2, true)
  48. return x, y, z
  49. end
  50.  
  51. --turtle movement without fuel
  52. function forward(t, s)
  53. for i = 1, t do
  54. if turtle.getFuelLevel() < 10 then
  55. turtle.select(s)
  56. turtle.refuel()
  57. turtle.forward()
  58. else turtle.forward()
  59. if turtle.forward() == true then
  60. return true
  61. else return false
  62. end
  63. end
  64. end
  65. end
  66.  
  67. --Dials a Stargate from Lanteacraft or SGCraft
  68. function dial(addr, t, side)
  69. sg.connect(addr)
  70. clear(1,1)
  71. repeat
  72. print("Gate is dialling...")
  73. sleep(1)
  74. clear(1,1)
  75. until not sg.isDialing()
  76. if side == nil then
  77. for i = t, 1, -1 do
  78. print("Closing gate in ".. i .." seconds")
  79. sleep(1)
  80. clear(1,1)
  81. end
  82. print("Stargate disconnecting from ".. addr)
  83. sg.disconnect()
  84. sleep(1)
  85. clear(1,1)
  86. else rs.setOutput(side, true)
  87. for i = t, 1, -1 do
  88. print("Closing gate in ".. i .." seconds")
  89. sleep(1)
  90. clear(1,1)
  91. end
  92. print("Stargate disconnecting from ".. addr)
  93. sg.disconnect()
  94. rs.setOutput(side, false)
  95. sleep(1)
  96. clear(1,1)
  97. end
  98. end
  99.  
  100. --run to functions in parallel
  101. function sync(func1, func2)
  102. parallel.waitForAll(func1, func2)
  103. end
  104.  
  105. --monitor API by gunpowder1234321 and dexman545
  106. function setSide(side)
  107. mon = peripheral.wrap(tostring(side))
  108. end
  109.  
  110. function mClear(x,y)
  111. mon.clear()
  112. mon.setCursorPos(tonumber(x),(y))
  113. end
  114.  
  115. function mPrint(String)
  116. local l, h = mon.getSize()
  117. local mX,mY = mon.getCursorPos()
  118. mon.write(tostring(String))
  119. mon.setCursorPos(1,mY+1)
  120. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement