Guest User

mobs

a guest
Aug 13th, 2014
337
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.loadAPI("button")
  2. local m = peripheral.wrap("right")
  3. local rsOut = {}
  4. local c = peripheral.wrap("container_chest_0")
  5. local a = peripheral.wrap("tt_magnet_0")
  6. local s = peripheral.wrap("auto_spawner_2")
  7. m.clear()
  8. local mobArray = {}
  9. local buttonColors = {}
  10. local attractorStatus = ""
  11. local page = 1
  12. local pages = 0
  13. local currMob = ""
  14.    
  15. function fillMainTable()
  16.    getCurrMob()
  17.    checkExact()
  18.    getAttractorStatus()
  19.    m.clear()
  20.    button.clearTable()
  21.    button.setTable("Lights", lights, "", 4, 17, 2, 4)
  22.    button.setTable("Door", door, "", 20, 33, 2, 4)
  23.    button.setTable("Grinders", grinders, "", 4, 17, 6, 8)
  24.    button.setTable("DrawBridge", drawBridge, "", 20, 33, 6, 8)
  25.    button.setTable("Attractor", attractorToggle, "", 4, 17, 10, 12)
  26.    button.setTable(attractorStatus, togglePush, "", 20, 33, 10, 12)
  27.    button.setTable("Mob Selector", mobSelect, "", 20, 33, 14, 16)
  28.    button.setTable("Spawner", spawner, "", 4, 17, 14, 16)
  29.    --button.setTable("Refresh", refresh, "", 15, 35, 19, 19)
  30.    print("Filled")
  31.    button.screen()
  32.    for i,j in pairs(buttonColors) do
  33.       if not rsOut[j] then button.toggleButton(i) end
  34.    end
  35.    button.toggleButton("Attractor")
  36.    button.label(1, 19, "Current Mob: "..currMob)
  37.    button.label(30, 19, "Exact: "..currExact)
  38. end
  39.  
  40. function getAttractorStatus()
  41.    if a.isPulling() then
  42.       attractorStatus = "Pulling"
  43.    else
  44.       attractorStatus = "Pushing"
  45.    end
  46. end
  47.  
  48. function togglePush()
  49.    button.flash(attractorStatus)
  50.    a.setPulling(not a.isPulling())
  51.    fillMainTable()
  52. end
  53.  
  54. function fillTable()
  55.    checkMobs()
  56.    checkExact()
  57.    getCurrMob()
  58.    m.clear()
  59.    button.clearTable()
  60.    local totalrows = 0
  61.    local npp = 12 --names per page
  62.    local numNames = 0
  63.    local col = 2
  64.    local row = 12
  65.    local countRow = 1
  66.    local currName = 0
  67.    for i,j in pairs(mobArray) do
  68.       totalrows = totalrows+1
  69.    end
  70.    pages = math.ceil(totalrows/npp)
  71.    print(totalrows)
  72.    for name,slot in pairs(mobArray) do
  73.        currName = currName + 1
  74.        if currName > npp*(page-1) and currName < npp*page+1 then
  75.          row = 4+(countRow)
  76.          button.setTable(string.sub(name, 0, 17), insertMob, slot, col, col+17 , row, row)
  77.          if col == 21 then
  78.            col = 2
  79.            countRow = countRow + 2
  80.          else
  81.            col = col+19
  82.          end
  83.        end
  84.    end
  85.    button.setTable("Next Page", nextPage, "", 27, 38, 1, 1)
  86.    button.setTable("Prev Page", prevPage, "", 2, 13, 1, 1)
  87.    button.setTable("Main Menu", goMainMenu, "", 15, 25, 1, 1)
  88.    button.setTable("Exact: "..currExact, switchExact, "", 21, 38, 18, 19)
  89.    button.setTable("Remove Mob", removeMob, "", 2, 19, 18, 19)
  90.    button.screen()
  91.    button.label(15,3, "Page: "..tostring(page).." of "..tostring(pages))
  92.    button.label(12, 16, "Current Mob: "..currMob)
  93. end      
  94.  
  95. function getCurrMob()
  96.    data = s.getStackInSlot(1)
  97.    if data then
  98.       currMob = data.captured
  99.    else
  100.       currMob = "None"
  101.    end
  102. end
  103.  
  104. function goMainMenu()
  105.    fillMainTable()
  106. --   refresh()
  107. end
  108.  
  109. function checkExact()
  110.    if s.getSpawnExact() then
  111.       currExact = "Yes"
  112.    else
  113.       currExact = "No"
  114.    end
  115. end
  116.  
  117. function switchExact()
  118.    s.setSpawnExact(not s.getSpawnExact())
  119.    fillTable()
  120. end
  121.  
  122. function nextPage()
  123.    if page+1 <= pages then
  124.       page = page+1
  125.    end
  126.    fillTable()
  127.    sleep(0.25)
  128. end
  129.  
  130. function prevPage()
  131.    if page-1 >= 1 then page = page-1 end
  132.    fillTable()
  133.    sleep(0.25)
  134. end  
  135.                            
  136. function getMobs()
  137.    mobArray = {}
  138.    for i = 1,27  do
  139.       if c.getStackInSlot(i) then
  140.          data = c.getStackInSlot(i)
  141.          --print(i..":"..data.captured)
  142.          mobArray[data.captured] = i
  143.       end
  144.    end
  145. end
  146.  
  147. function findEmptySlot()
  148.    for i = 1,27 do
  149.       if not c.getStackInSlot(i) then
  150.          return(i)
  151.       end
  152.    end
  153. end
  154.  
  155. function removeMob()
  156.    local slot = findEmptySlot()
  157.    c.pullItem("down", 1, 1, slot)
  158. end
  159.  
  160. function insertMob(info)
  161.    removeMob()
  162.    c.pushItem("down", info, 1, 1)
  163.    fillTable()
  164. end
  165.  
  166. function checkMobs()
  167.    getMobs()
  168.    --fillTable()
  169. end
  170.  
  171. function initRS()
  172.    rsOut[colors.white] = false
  173.    rsOut[colors.orange] = true
  174.    rsOut[colors.magenta] = false
  175.    rsOut[colors.lightBlue] = true
  176.    rsOut[colors.yellow] = false
  177.    rsOut[colors.lime] = true
  178.    buttonColors["Lights"] = colors.white
  179.    buttonColors["Spawner"] = colors.orange
  180.    buttonColors["Grinders"] = colors.magenta
  181.    buttonColors["DrawBridge"] = colors.lightBlue
  182.    buttonColors["Attractor"] = colors.yellow
  183.    buttonColors["Door"] = colors.lime
  184. end
  185.  
  186. function setRS()
  187.    local colorOutput = 0
  188.    for i,j in pairs(rsOut) do
  189.       if j then colorOutput = colorOutput + i end
  190.     end
  191.     rs.setBundledOutput("left", colorOutput)
  192. end
  193.  
  194. function lights()
  195.    button.toggleButton("Lights")
  196.    rsOut[colors.white] = not rsOut[colors.white]
  197.    setRS()
  198. end
  199.  
  200. function door()
  201.    button.toggleButton("Door")
  202.    rsOut[colors.lime] = not rsOut[colors.lime]
  203.    setRS()
  204. end
  205.  
  206. function spawner()
  207.    button.toggleButton("Spawner")
  208.    rsOut[colors.orange] = not rsOut[colors.orange]
  209.    setRS()
  210. end
  211.  
  212. function grinders()
  213.    button.toggleButton("Grinders")
  214.    rsOut[colors.magenta] = not rsOut[colors.magenta]
  215.    setRS()
  216. end
  217.  
  218. function drawBridge()
  219.    button.toggleButton("DrawBridge")
  220.    rsOut[colors.lightBlue] = not rsOut[colors.lightBlue]
  221.    setRS()
  222. end
  223.  
  224. function attractorToggle()
  225.    button.toggleButton("Attractor")
  226.    rsOut[colors.yellow] = not rsOut[colors.yellow]
  227.    setRS()
  228. end
  229.  
  230. function mobSelect()
  231.    fillTable()
  232. --   refresh()
  233. --   getClick()
  234. end
  235.  
  236. function getClick()
  237.    local event,side,x,y = os.pullEvent()
  238.    if event=="monitor_touch" then
  239.      button.checkxy(x,y)
  240.    end
  241. end
  242.  
  243. function refresh()
  244.    m.clear()
  245.    print("Refreshed")
  246.    button.screen()
  247. end
  248.  
  249. initRS()
  250. setRS()
  251. fillMainTable()
  252. --refresh()
  253. while true do getClick() end
RAW Paste Data