Advertisement
massacring

WishingWell

Oct 1st, 2024 (edited)
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.02 KB | None | 0 0
  1. local barrelName = "sophisticatedstorage:barrel_"
  2.  
  3. local chatBox = peripheral.find("chatBox")
  4. if (chatBox == nil) then
  5.     error("No Chat Box peripheral connected.", 0)
  6. end
  7.  
  8. local storage = peripheral.wrap(barrelName .. 0)
  9. local input = peripheral.wrap(barrelName .. 1)
  10. local output = peripheral.wrap(barrelName .. 2)
  11.  
  12. local inputItem
  13.  
  14. local gold_nugget_slot
  15. local gold_slot, diamond_slot
  16. local small_coin_slot, medium_coin_slot
  17. local gold_block_slot, diamond_block_slot
  18. local small_coin_block_slot, medium_coin_block_slot
  19.  
  20. local function OutOfPrizes(message)
  21.     chatBox.sendMessage(message, "&cMassaWish Inc", "[]", "&8", 30)
  22.     input.pushItems(peripheral.getName(output), 1)
  23.     sleep(15)
  24.     os.reboot()
  25. end
  26.  
  27. local function getItemSlot(inventory, name)
  28.     for i = 1,inventory.size(),1 do
  29.         local item = inventory.getItemDetail(i)
  30.         if item == nil then goto continue end
  31.         if (item.name == name) then return i end
  32.         ::continue::
  33.     end
  34.     OutOfPrizes("Out of prizes. Contact massacring.")
  35. end
  36.  
  37. local function generateSlot(slot, name)
  38.     if (slot == nil) or (slot < 1) or (storage.getItemDetail(slot).name ~= name) then
  39.         return getItemSlot(storage, name)
  40.     end
  41. end
  42.  
  43. local function generateSlots()
  44.     gold_nugget_slot = generateSlot(gold_nugget_slot, "minecraft:gold_nugget")
  45.     gold_slot = generateSlot(gold_slot, "minecraft:gold_ingot")
  46.     diamond_slot = generateSlot(diamond_slot, "minecraft:diamond")
  47.     small_coin_slot = generateSlot(small_coin_slot, "kubejs:small_coin")
  48.     medium_coin_slot = generateSlot(medium_coin_slot, "kubejs:medium_coin")
  49.     gold_block_slot = generateSlot(gold_block_slot, "minecraft:gold_block")
  50.     diamond_block_slot = generateSlot(diamond_block_slot, "minecraft:diamond_block")
  51.     small_coin_block_slot = generateSlot(small_coin_block_slot, "kubejs:small_coin_block")
  52.     medium_coin_block_slot = generateSlot(medium_coin_block_slot, "kubejs:medium_coin_block")
  53. end
  54.  
  55. local function sendItem(storageSlot, amount)
  56.     storage.pushItems(peripheral.getName(output), storageSlot, amount)
  57.     if (storage.getItemDetail(storageSlot) == nil) then
  58.         OutOfPrizes("Ran out of prizes. Contact massacring.")
  59.     end
  60. end
  61.  
  62. local function getRewardSlot(tier)
  63.     local inputName = inputItem.name
  64.     if tier == 0 then
  65.         return getItemSlot(storage, inputName)
  66.     elseif tier == 1 then
  67.         if inputName == "kubejs:small_coin" then return small_coin_block_slot
  68.         elseif inputName == "minecraft:diamond" then return diamond_block_slot
  69.         elseif inputName == "minecraft:gold_ingot" then return gold_block_slot
  70.         elseif inputName == "kubejs:medium_coin" then return medium_coin_block_slot end
  71.     elseif tier == -1 then
  72.         if inputName == "kubejs:small_coin" then return gold_slot
  73.         elseif inputName == "minecraft:diamond" then return gold_slot
  74.         elseif inputName == "minecraft:gold_ingot" then return gold_nugget_slot
  75.         elseif inputName == "kubejs:medium_coin" then return small_coin_slot end
  76.     end
  77. end
  78.  
  79. local function MakeAWish()
  80.     input.pushItems(peripheral.getName(storage), 1, 1)
  81.     local rng = math.random(0, 99)
  82.     if rng < 40 then
  83.         redstone.setAnalogOutput("back", 1)
  84.     elseif rng < 60 then
  85.         redstone.setAnalogOutput("back", 2)
  86.         sendItem(getRewardSlot(-1), 1)
  87.     elseif rng < 75 then
  88.         redstone.setAnalogOutput("back", 3)
  89.         sendItem(getRewardSlot(0), 1)
  90.     elseif rng < 90 then
  91.         redstone.setAnalogOutput("back", 4)
  92.         sendItem(getRewardSlot(0), 2)
  93.     elseif rng < 98 then
  94.         redstone.setAnalogOutput("back", 5)
  95.         sendItem(getRewardSlot(0), 3)
  96.     else
  97.         redstone.setAnalogOutput("back", 6)
  98.         sendItem(getRewardSlot(1), 1)
  99.         chatBox.sendMessage("JACKPOT! Congratulations!", "&aMassaWish Inc", "[]", "&8", 30)
  100.     end
  101. end
  102.  
  103. while true do
  104.     redstone.setAnalogOutput("back", 0)
  105.     inputItem = input.getItemDetail(1)
  106.     generateSlots()
  107.     if (inputItem ~= nil) then MakeAWish() end
  108.     sleep(0.05)
  109. end
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement