Advertisement
cyber_Ahn

OS_API

Apr 1st, 2015
928
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.22 KB | None | 0 0
  1. local monitor_number = "monitor_1"
  2. local found = fs.exists("config/monitor.cfg")
  3. if found == true then
  4. file = fs.open("config/monitor.cfg","r")
  5. local fileData = {}
  6. local line = file.readLine()
  7. repeat
  8. table.insert(fileData,line)
  9. line = file.readLine()
  10. until line == nil
  11. file.close()
  12. monitor_number = fileData[1]
  13. end
  14. local mon = peripheral.wrap(monitor_number)
  15. --
  16. function getTime()
  17. local time_f
  18. time = os.time()
  19. time_f = textutils.formatTime(time, true)
  20. return time_f
  21. end
  22. --
  23. function numToSegCol(number)
  24. local color_set = colors.black
  25. if number == "1" then
  26. color_set = color_set + colors.white
  27. color_set = color_set + colors.orange
  28. end
  29. if number == "2" then
  30. color_set = color_set + colors.lime
  31. color_set = color_set + colors.white
  32. color_set = color_set + colors.pink
  33. color_set = color_set + colors.lightBlue
  34. color_set = color_set + colors.magenta
  35. end
  36. if number == "3" then
  37. color_set = color_set + colors.lime
  38. color_set = color_set + colors.white
  39. color_set = color_set + colors.pink
  40. color_set = color_set + colors.orange
  41. color_set = color_set + colors.magenta
  42. end
  43. if number == "4" then
  44. color_set = color_set + colors.yellow
  45. color_set = color_set + colors.white
  46. color_set = color_set + colors.pink
  47. color_set = color_set + colors.orange
  48. end
  49. if number == "5" then
  50. color_set = color_set + colors.lime
  51. color_set = color_set + colors.yellow
  52. color_set = color_set + colors.pink
  53. color_set = color_set + colors.orange
  54. color_set = color_set + colors.magenta
  55. end
  56. if number == "6" then
  57. color_set = color_set + colors.lime
  58. color_set = color_set + colors.yellow
  59. color_set = color_set + colors.pink
  60. color_set = color_set + colors.lightBlue
  61. color_set = color_set + colors.magenta
  62. color_set = color_set + colors.orange
  63. end
  64. if number == "7" then
  65. color_set = color_set + colors.lime
  66. color_set = color_set + colors.white
  67. color_set = color_set + colors.orange
  68. end
  69. if number == "8" then
  70. color_set = color_set + colors.lime
  71. color_set = color_set + colors.white
  72. color_set = color_set + colors.yellow
  73. color_set = color_set + colors.pink
  74. color_set = color_set + colors.lightBlue
  75. color_set = color_set + colors.orange
  76. color_set = color_set + colors.magenta
  77. end
  78. if number == "9" then
  79. color_set = color_set + colors.lime
  80. color_set = color_set + colors.white
  81. color_set = color_set + colors.yellow
  82. color_set = color_set + colors.pink
  83. color_set = color_set + colors.orange
  84. color_set = color_set + colors.magenta
  85. end
  86. if number == "0" then
  87. color_set = color_set + colors.lime
  88. color_set = color_set + colors.white
  89. color_set = color_set + colors.yellow
  90. color_set = color_set + colors.lightBlue
  91. color_set = color_set + colors.orange
  92. color_set = color_set + colors.magenta
  93. end
  94. return color_set
  95. end
  96. --
  97. function chat(msg)
  98. local chB_mum = "chatBox_0"
  99. file = fs.open("config/per_plus_plus.cfg","r")
  100. local fileData = {}
  101. local line = file.readLine()
  102. repeat
  103. table.insert(fileData,line)
  104. line = file.readLine()
  105. until line == nil
  106. file.close()
  107. if chB_num ~= "chat_box_off" then
  108. chB_num = fileData[2]
  109. local chB = peripheral.wrap(chB_num)
  110. chB.say(msg)
  111. end
  112. end
  113. --
  114. function speaker(msg)
  115. local sp_num = "speaker_0"
  116. file = fs.open("config/per_plus_plus.cfg","r")
  117. local fileData = {}
  118. local line = file.readLine()
  119. repeat
  120. table.insert(fileData,line)
  121. line = file.readLine()
  122. until line == nil
  123. file.close()
  124. sp_num = fileData[1]
  125. if sp_num ~= "speaker_off" then
  126. local sp = peripheral.wrap(sp_num)
  127. sp.speak(msg)
  128. end
  129. end
  130. --
  131. function sound(inst,note)
  132. local no_num = "iron_noteblock_0"
  133. file = fs.open("config/per_plus_plus.cfg","r")
  134. local fileData = {}
  135. local line = file.readLine()
  136. repeat
  137. table.insert(fileData,line)
  138. line = file.readLine()
  139. until line == nil
  140. file.close()
  141. no_num = fileData[3]
  142. if no_num ~= "iron_noteblock_off" then
  143. local no = peripheral.wrap(no_num)
  144. no.playNote(inst,note)
  145. end
  146. end
  147. --
  148. function lamp(color)
  149. local no_num = "colorful_lamp_0"
  150. file = fs.open("config/per_plus_plus.cfg","r")
  151. local fileData = {}
  152. local line = file.readLine()
  153. repeat
  154. table.insert(fileData,line)
  155. line = file.readLine()
  156. until line == nil
  157. file.close()
  158. lam_num = fileData[4]
  159. if lam_num ~= "colorful_lamp_off" then
  160. local la = peripheral.wrap(lam_num)
  161. la.setLampColor(color)
  162. end
  163. end
  164. --
  165. function ini_peripheralPlusPlus()
  166. local sp_num = "speaker_0"
  167. local chB_mum = "chatBox_0"
  168. local found = fs.exists("config/per_plus_plus.cfg")
  169. if found == false then
  170. local file = fs.open("config/per_plus_plus.cfg","w")
  171. speaker_hw = get_hardware("speaker")
  172. chat_hw = get_hardware("chat_box")
  173. note_hw = get_hardware("iron_noteblock")
  174. lamp_hw = get_hardware("colorful_lamp")
  175. file.writeLine(speaker_hw)
  176. file.writeLine(chat_hw)
  177. file.writeLine(note_hw)
  178. file.writeLine(lamp_hw)
  179. file.close()
  180. end
  181. file = fs.open("config/per_plus_plus.cfg","r")
  182. local fileData = {}
  183. local line = file.readLine()
  184. repeat
  185. table.insert(fileData,line)
  186. line = file.readLine()
  187. until line == nil
  188. file.close()
  189. sp_num = fileData[1]
  190. chB_num = fileData[2]
  191. if chB_num ~= "chat_box_off" then
  192. local sp = peripheral.wrap(sp_num)
  193. local chB = peripheral.wrap(chB_num)
  194. chB.say("Chatbox on")
  195. sleep(2)
  196. chB.say("Speaker on")
  197. end
  198. end
  199. --
  200. function detectDivice(DeviceName)
  201. DeviceSide="none"
  202. for k,v in pairs(redstone.getSides()) do
  203. if peripheral.getType(v)==DeviceName then
  204. DeviceSide = v
  205. break
  206. end
  207. end
  208. return(DeviceSide)
  209. end
  210. --
  211. function get_hardware(name)
  212. hw = "off"
  213. local periList = peripheral.getNames()
  214. for i = 1, #periList do
  215. if peripheral.getType(periList[i]) == name then
  216. hw = periList[i]
  217. end
  218. end
  219. if hw == "off" then
  220. hw = name.."_"..hw
  221. end
  222. return(hw)
  223. end
  224. --
  225. function split(pString,pPattern)
  226. local Table = {}
  227. local fpat = "(.-)"..pPattern
  228. local last_end = 1
  229. local s,e,cap = pString:find(fpat,1)
  230. while s do
  231. if s ~= 1 or cap ~= "" then
  232. table.insert(Table,cap)
  233. end
  234. last_end = e+1
  235. s,e,cap = pString:find(fpat,last_end)
  236. end
  237. if last_end <= #pString then
  238. cap = pString:sub(last_end)
  239. table.insert(Table,cap)
  240. end
  241. return Table
  242. end
  243. --
  244. function icon(x,y)
  245. local monitor_number = "monitor_1"
  246. local found = fs.exists("config/monitor.cfg")
  247. if found == true then
  248. file = fs.open("config/monitor.cfg","r")
  249. local fileData = {}
  250. local line = file.readLine()
  251. repeat
  252. table.insert(fileData,line)
  253. line = file.readLine()
  254. until line == nil
  255. file.close()
  256. monitor_number = fileData[1]
  257. end
  258. local mon = peripheral.wrap(monitor_number)
  259. icon = paintutils.loadImage("images/icon")
  260. paintutils.drawImage(icon, x, y)
  261. mon.setBackgroundColor(8)
  262. end
  263. --
  264. function in_table(table, element)
  265. for _, value in pairs(table) do
  266. if value == element then
  267. return true
  268. end
  269. end
  270. return false
  271. end
  272. --
  273. function toboolean(str)
  274. if str == "true" then
  275. return true
  276. else
  277. return false
  278. end
  279. end
  280. --
  281. function round(num, idp, pointless)
  282. if not pointless then pointless = false end
  283. local mult = 10^(idp or 0)
  284. local erg = math.floor(num * mult + 0.5) / mult
  285. if pointless then
  286. erg = string.sub(erg, 1)
  287. end
  288. return erg
  289. end
  290. --
  291. function loadFile(target)
  292. file = fs.open(target,"r")
  293. local IdData = {}
  294. local line = file.readLine()
  295. repeat
  296. table.insert(IdData,line)
  297. line = file.readLine()
  298. until line == nil
  299. file.close()
  300. return IdData
  301. end
  302. --
  303. function AtoB(search,dataList)
  304. back = search
  305. for MCid, MCdata in pairs(dataList) do
  306. idC = caAPI.split(MCdata,"=")
  307. if idC[1] == search then
  308. back = idC[2]
  309. end
  310. end
  311. return back
  312. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement