Advertisement
ccraftersanonmoose

More Peripherals xp bottler control script

Feb 16th, 2023 (edited)
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.01 KB | Gaming | 0 0
  1. -- Script to control and eventually also monitor the xp bottler and xp collector from More Peripherals
  2. -- Script by craftersanonmoose
  3. -- Version history
  4. -- version 0.1 2/16/23
  5. -- adding controls
  6. -- version 0.1.1 2/16/23
  7. -- added button and display functionality
  8. -- version 0.1.2 2/16/23
  9. -- added error handling to allow script to run even if bottles run out in storage
  10. -- want to add in informational area for below the two buttons to show how much XP is in each colector
  11.  
  12. ---------------------------
  13. os.loadAPI("button")
  14. mon = peripheral.find("monitor")
  15. mon.clear()
  16.  
  17. -- change the name of peripheral if needed
  18. bottler = peripheral.wrap("xp_bottler_2")
  19. c0 = peripheral.wrap("xp_collector_8")
  20. c1 = peripheral.wrap("xp_collector_6")
  21.  
  22. function fillTable()
  23.     button.setTable("Collector1", bottle1, 4,14,3,5)
  24.     button.setTable("Collector2", bottle2, 17,27,3,5)
  25.     button.screen()
  26. end
  27.  
  28. function getClick()
  29.     event,side,x,y = os.pullEvent("monitor_touch")
  30.     button.checkxy(x,y)
  31. end
  32.  
  33.  
  34. -- I used a diamond crate for this, change the name based on your storgae method
  35. function bottle1()
  36.     button.flash("Collector1")
  37.     local success, err = pcall(function()
  38.        bottler.bottleXP("bettercrates:diamond_crate_6", "bettercrates:diamond_crate_6", "xp_collector_8")
  39.     end)
  40.     if not success then
  41.         print("Error occured:", err)
  42.     end
  43. end
  44.  
  45. function bottle2()
  46.     button.flash("Collector2")
  47.     local success, err = pcall(function()
  48.        bottler.bottleXP("bettercrates:diamond_crate_6", "bettercrates:diamond_crate_6", "xp_collector_6")
  49.     end)
  50.     if not success then
  51.         print("Error occured:", err)
  52.     end
  53. end
  54.  
  55. function showLevel()
  56.     mon.setCursorPos(4,7)
  57.     mon.write("XP Level")
  58.     mon.setCursorPos(4,8)
  59.     mon.clearLine()
  60.     mon.write(c0.getCurrentXP())
  61.     mon.setCursorPos(17,7)
  62.     mon.write("XP Level")
  63.     mon.setCursorPos(17,8)
  64.     mon.write(c1.getCurrentXP())
  65. end
  66.  
  67. fillTable()
  68. button.heading("XP Bottler")
  69.  
  70. while true do
  71.     showLevel()
  72.     getClick()
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement