Guest User

Create Stock Network Item Counter

a guest
Aug 11th, 2026
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. -- You need to connect the computer to a stock ticker and a display link from Create before you start it
  2. -- Put this into startup.lua so it automatically starts when the computer starts (or the chunks are loaded)
  3.  
  4. -- Format the number in a shorter format
  5. function format(num)
  6. if num >= 10 ^ 6 then
  7. return string.format("%.1fm", num / 10 ^ 6)
  8. elseif num >= 10 ^ 3 then
  9. return string.format("%.1fk", num / 10 ^ 3)
  10. else
  11. return tostring(num)
  12. end
  13. end
  14.  
  15. local ticker = peripheral.find("Create_StockTicker")
  16. local link = peripheral.find("Create_DisplayLink")
  17.  
  18. while true do
  19. -- Wait in the beginning so the surrounding chunks are loaded
  20. os.sleep(5)
  21.  
  22. -- Get the stock of the network
  23. local stock = ticker.stock()
  24. local count = 0
  25.  
  26. -- Count all items in the network
  27. -- If you want to do anything with the specific item types, this is the loop you need to change
  28. for _, entry in ipairs(stock) do
  29. count = count + entry.count
  30. end
  31.  
  32. local writableCount = format(count)
  33.  
  34. -- debug logging
  35. print(count)
  36. print(writableCount)
  37.  
  38. -- Write to the display link
  39. link.clear()
  40. link.setCursorPos(1, 1)
  41. link.write(writableCount .. " Items")
  42. link.update()
  43. end
  44.  
Advertisement
Add Comment
Please, Sign In to add comment