Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Turtle-Programm für cc:tweaked
- -- Konfiguration
- local INPUT_CHEST = "right" -- Deposit box
- local DEPOT_CHEST = "bottom" -- Depot kit
- local PRICE_CHEST = "back" -- Investigations
- local OUTPUT_CHEST = "left" -- Payout box
- local MAX_ITEMS = 16 -- Maximum number of prizes per transaction
- -- Advanced peripherals for chat messages
- local chat = peripheral.find("chatBox")
- -- Auxiliary functions
- local function selectItem(name)
- for i = 1, 16 do
- turtle.select(i)
- local detail = turtle.getItemDetail()
- if detail and detail.name == name then
- return true
- end
- end
- return false
- end
- local function dropAll(direction)
- for i = 1, 16 do
- turtle.select(i)
- if direction == "up" then
- turtle.dropUp()
- elseif direction == "down" then
- turtle.dropDown()
- elseif direction == "forward" then
- turtle.drop()
- end
- end
- end
- local function countItems(itemName)
- local count = 0
- for i = 1, 16 do
- local detail = turtle.getItemDetail(i)
- if detail and detail.name == itemName then
- count = count + detail.count
- end
- end
- return count
- end
- local function sendMessage(message)
- if chat then
- chat.sendMessage(message)
- else
- print(message)
- end
- end
- -- Main logic
- local function processTransaction()
- turtle.turnRight()
- while turtle.suck() do
- -- As long as there are items in the deposit box, collect
- end
- local diamonds = countItems("minecraft:diamond")
- local emeralds = countItems("minecraft:emerald")
- local totalItems = diamonds + emeralds
- if totalItems > 0 then
- -- Put diamonds and emeralds in the depot
- if diamonds > 0 then
- selectItem("minecraft:diamond")
- dropAll("down")
- end
- if emeralds > 0 then
- selectItem("minecraft:emerald")
- dropAll("down")
- end
- sendMessage("There were " .. totalItems .. " Diamonds/Emeralds deposited.")
- -- Remove prizes from prize box and place them in payout box
- local itemsToGive = math.min(totalItems, MAX_ITEMS)
- turtle.turnRight()
- for i = 1, itemsToGive do
- if not turtle.suck() then
- sendMessage("Prize box is empty. Not enough prizes could be provided.")
- break
- end
- end
- turtle.turnRight()
- dropAll("forward")
- sendMessage("The prizes were placed in the payout box.")
- turtle.turnRight()
- else
- -- Move incorrect items to the depot
- sendMessage("No valid items found. Move faulty items to the depot..")
- dropAll("down")
- redstone.setOutput("front", true)
- sleep(0.5)
- redstone.setOutput("front", false)
- turtle.turnLeft()
- end
- sendMessage("Thank you for your trust - gambling can be addictive!")
- end
- -- Event Listener for Redstone Signal
- while true do
- if redstone.getInput("top") then
- processTransaction()
- while redstone.getInput("top") do
- sleep(0.1) -- Wait until the pulse ends
- end
- end
- sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement