Advertisement
ecco7777

CC filler controler + resupply station

May 29th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.91 KB | None | 0 0
  1. file="bild"
  2. r=peripheral.wrap("right")
  3. r.link()
  4. slot={}
  5. chars={}
  6. slot[" "]=12
  7. slot["0"]=1
  8. slot["1"]=2
  9. slot["2"]=3
  10. slot["3"]=4
  11. slot["4"]=5
  12. slot["5"]=6
  13. slot["6"]=7
  14. slot["7"]=8
  15. slot["8"]=9
  16. slot["9"]=10
  17. slot["a"]=11
  18. slot["b"]=12
  19. slot["c"]=13
  20. slot["d"]=14
  21. slot["e"]=15
  22. slot["f"]=16
  23.  
  24. function getCharCount(str,char)
  25. charnum=0
  26. for i=1, #str do
  27. if string.sub(str,i,i)==char then
  28. charnum=charnum+1
  29. end
  30. end
  31. return(charnum)
  32. end
  33.  
  34. function fileToTable(file)
  35. if fs.exists(file)~=true then
  36. print("file"..file.." not found")
  37. return(false)
  38. end
  39. fp=fs.open(file,"r")
  40. line={}
  41. i=1
  42. line[i]=fp.readLine()
  43. if line[i]==nil then return(false) end
  44. while line[i]~=nil do
  45. i=i+1
  46. line[i]=fp.readLine()
  47. end
  48. return(line)
  49. end
  50.  
  51. img=fileToTable(file)
  52.  
  53. i=1
  54. i2=1
  55. i3=1
  56. while img[i]~=nil do
  57. for i2=1, #img[i] do
  58. chars[i3]=string.sub(img[1],i2,i2)
  59. i3=i3+1
  60. end
  61. i=i+1
  62. end
  63.  
  64. onechar=""
  65. for i=1, #img do
  66. onechar=onechar..img[i]
  67. end
  68. term.clear()
  69. term.setCursorPos(1,1)
  70. term.write("Slot1 weiß: "..tostring(getCharCount(onechar,"0")))term.setCursorPos(1,2)
  71. term.write("Slot2 orange: "..tostring(getCharCount(onechar,"1")))term.setCursorPos(1,3)
  72. term.write("Slot3 magenta: "..tostring(getCharCount(onechar,"2")))term.setCursorPos(1,4)
  73. term.write("Slot4 hellblau: "..tostring(getCharCount(onechar,"3")))term.setCursorPos(1,5)
  74. term.write("Slot5 gelb: "..tostring(getCharCount(onechar,"4")))term.setCursorPos(1,6)
  75. term.write("Slot6 hellgrün: "..tostring(getCharCount(onechar,"5")))term.setCursorPos(1,7)
  76. term.write("Slot7 pink: "..tostring(getCharCount(onechar,"6")))term.setCursorPos(1,8)
  77. term.write("Slot8 grau: "..tostring(getCharCount(onechar,"7")))term.setCursorPos(21,1)
  78. term.write("Slot9 hellgrau: "..tostring(getCharCount(onechar,"8")))term.setCursorPos(21,2)
  79. term.write("Slot10 cyan: "..tostring(getCharCount(onechar,"9")))term.setCursorPos(21,3)
  80. term.write("Slot11 lila: "..tostring(getCharCount(onechar,"a")))term.setCursorPos(21,4)
  81. term.write("Slot12 blau: "..tostring(getCharCount(onechar," ")+getCharCount(onechar,"b")))term.setCursorPos(21,5)
  82. term.write("Slot13 braun: "..tostring(getCharCount(onechar,"c")))term.setCursorPos(21,6)
  83. term.write("Slot14 grün: "..tostring(getCharCount(onechar,"d")))term.setCursorPos(21,7)
  84. term.write("Slot15 rot: "..tostring(getCharCount(onechar,"e")))term.setCursorPos(21,8)
  85. term.write("Slot16 schwarz: "..tostring(getCharCount(onechar,"f")))term.setCursorPos(1,9)
  86.  
  87.  
  88. print("Höhe: "..tostring(#img))
  89. print("Breite: "..tostring(#img[1]))
  90. e,key=os.pullEvent("key")
  91. while key~=28 do
  92. e,key=os.pullEvent("key")
  93. end
  94.  
  95. for i=1, #chars do
  96. turtle.select(slot[string.sub(onechar,i,i)])
  97. if turtle.getItemCount(slot[string.sub(onechar,i,i)])>1 then
  98. turtle.drop(1)
  99. else
  100. if r.resupply(slot[string.sub(onechar,i,i)])==false then term.write("Bitte Material nachfüllen und Taste drücken")
  101. e,key=os.pullEvent("key")
  102. while key~=28 do
  103. e,key=os.pullEvent("key")
  104. end
  105. end
  106. turtle.drop(1)
  107. end
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement