Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------------------------------------------
- -- run this program on a turtle with on the right a disk drive and the back of the turtle a chest
- -- This program is made for my slotmachiene and futere games.
- -- to use this install this under the name startup
- ------------------------------------------------------------------
- -- manual
- --
- -- place a turtle with on the left a disk drive en behind a chest
- -- (you can place any block above the chest to stop people from opening it)
- -- you can also change te fee for when people withdraw there diamonds
- -- here you can also change flopp's to Mcards
- -------------------------------------------------------------------
- local collectorFee = 10 --how many credits you want as fee when people collect there dia
- ---------------------------------------
- local final_count = 0
- local current_count = 0
- local credsPerDia = 20
- local creds_rtrn = 0
- ----------------------------------
- function writeCard()
- if not fs.exists("disk/creds.lua") then
- os.reboot()
- end
- local Card = fs.open("disk/creds.lua", "w")
- data = (tostring(math.random(1, 163456)).."11066011"..tostring(creds).."11077011"..tostring(math.random(1, 163456)))
- Card.write(tostring(data))
- Card.close()
- disk.setLabel("right", tostring(creds).."$")
- end
- function Pkey()
- local event, key = os.pullEvent("key")
- if key == keys.enter then
- conf = true
- end
- end
- function wait()
- sleep(1)
- end
- function turn()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- function readCard()
- if not fs.exists("disk/") then
- os.reboot()
- end
- if not fs.exists("disk/creds.lua") then
- term.setCursorPos(10, 7)
- print("This isn't a Mcard")
- term.setCursorPos(8, 8)
- print("Do you wan't to make it a Mcard?")
- term.setCursorPos(12, 10)
- write(" Yes >No<")
- confi = false
- while confi == false do
- term.setCursorPos(12, 10)
- local event, key, isHeld = os.pullEvent("key")
- if key == keys.left then
- write(">Yes< No ")
- confirm = true
- elseif key == keys.right then
- write(" Yes >No<")
- confirm = false
- elseif key == keys.enter then
- confi = true
- end
- end
- term.clear()
- if confirm == true then
- local Card = fs.open("disk/creds.lua", "w")
- Card.write("0987498011066011011077011")
- Card.close()
- disk.setLabel("right", "0$")
- else
- term.setCursorPos(8, 8)
- while fs.exists("disk/") do
- term.setCursorPos(8, 8)
- write("please remove your disk")
- sleep(0,5)
- end
- end
- end
- local Card = fs.open("disk/creds.lua", "r")
- data = Card.readAll()
- Card.close()
- a, b = string.find(data, "11066011")
- c, d = string.find(data, "11077011")
- creds = tonumber(string.sub(data, b+1, c-1))
- end
- function insert_card()
- paintutils.drawFilledBox(1, 1, 39, 13, colors.green)
- while not fs.exists("disk/") do
- term.clear()
- paintutils.drawFilledBox(1, 1, 39, 13, colors.green)
- term.setCursorPos(10, 6)
- term.write("{please insert card}")
- sleep(1)
- end
- term.clear()
- end
- function count_dia()
- current_count = 0
- for i=1,16 do
- if turtle.getItemCount(i) > 0 then
- local slot = turtle.getItemDetail(i)
- if slot.name == "minecraft:diamond" then
- current_count = current_count + slot.count
- end
- end
- end
- final_count = current_count
- for i=1,16 do
- if turtle.getItemCount(i) > 0 then
- local slot = turtle.getItemDetail(i)
- if slot.name ~= "minecraft:diamond" then
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- creds_rtrn = final_count * credsPerDia
- end
- function wdORdp()
- local action = "deposit"
- enter = false
- term.setCursorPos(8, 10)
- term.clear()
- write(" withdraw >deposit<")
- while enter == false do
- term.setCursorPos(9, 8)
- term.write("you currently have: "..creds.."$")
- term.setCursorPos(8, 10)
- local event, key, isHeld = os.pullEvent("key")
- if not fs.exists("disk/creds.lua") then
- os.reboot()
- end
- if key == keys.left then
- write(">withdraw< deposit ")
- action = "withdraw"
- elseif key == keys.right then
- write(" withdraw >deposit<")
- action = "deposit"
- end
- if key == keys.enter then
- enter = true
- return action;
- end
- end
- end
- function transaction()
- term.clear()
- if action == "deposit" then
- conf = false
- while conf == false do
- if not fs.exists("disk/creds.lua") then
- os.reboot()
- end
- count_dia()
- term.clear()
- term.setCursorPos(10, 4)
- term.write("do you want to deposit")
- term.setCursorPos(10, 6)
- term.write("|"..final_count.."| dia")
- term.setCursorPos(10, 8)
- term.write("for")
- term.setCursorPos(10,10)
- term.write("|"..creds_rtrn.."| creds?")
- parallel.waitForAny(Pkey, wait)
- end
- turn()
- current_count = 0
- for i=1,16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- local slot = turtle.getItemDetail(i)
- if slot.name == "minecraft:diamond" then
- current_count = current_count + slot.count
- end
- end
- turtle.drop()
- end
- turn()
- final_count = current_count
- creds_rtrn = final_count * credsPerDia
- creds = creds + creds_rtrn
- writeCard()
- end
- if action == "withdraw" then
- paintutils.drawFilledBox(1, 1, 51, 19, colors.green)
- local diawit = 0
- local creds_rtrn = diawit * credsPerDia
- term.clear()
- term.setCursorPos(10, 4)
- term.write("do you want to withdraw")
- term.setCursorPos(10, 6)
- term.write("|"..diawit.."| dia")
- term.setCursorPos(10, 8)
- term.write("for")
- term.setCursorPos(10,10)
- term.write("|"..creds_rtrn.."| creds")
- conf = false
- while conf == false do
- local creds_rtrn = diawit * credsPerDia
- local event, key = os.pullEvent("key")
- if key == keys.up and creds_rtrn < creds then
- diawit = diawit + 1
- if ((diawit * credsPerDia) + collectorFee) > creds then
- diawit = diawit -1
- end
- term.clear()
- term.setCursorPos(10, 4)
- term.write("do you want to withdraw")
- term.setCursorPos(10, 6)
- term.write("|"..diawit.."| dia")
- term.setCursorPos(10, 8)
- term.write("for")
- term.setCursorPos(10,10)
- term.write("|"..diawit * credsPerDia.."| creds")
- elseif key == keys.down and creds_rtrn > 0 then
- diawit = diawit - 1
- term.clear()
- term.setCursorPos(10, 4)
- term.write("do you want to withdraw")
- term.setCursorPos(10, 6)
- term.write("|"..diawit.."| dia")
- term.setCursorPos(10, 8)
- term.write("for")
- term.setCursorPos(10,10)
- term.write("|"..diawit * credsPerDia.."| creds")
- elseif key == keys.enter then
- conf = true
- end
- end
- local creds_rtrn = diawit * credsPerDia
- local beforecreds = creds
- creds = creds - creds_rtrn - collectorFee
- term.clear()
- term.setCursorPos(10, 6)
- term.write("See you soon!")
- writeCard()
- turn()
- turtle.select(1)
- stacks = diawit / 64
- while stacks >= 1 do
- turtle.suck(64)
- stacks = stacks-1
- end
- local succes = turtle.suck(stacks*64)
- if succes == false then
- for i=1,16 do
- turtle.select(i)
- turtle.drop()
- end
- turn()
- creds = beforecreds
- writeCard()
- term.clear()
- term.setCursorPos(5, 6)
- term.write("There don't have enough diamonds")
- term.setCursorPos(7, 8)
- term.write("please come back later")
- sleep(2)
- elseif succes == true then
- turn()
- for i=1,16 do
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- end
- while 1 do
- insert_card()
- readCard()
- while fs.exists("disk/creds.lua") do
- readCard()
- action = wdORdp()
- transaction()
- end
- end
Add Comment
Please, Sign In to add comment