Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- securityId = 0
- diskDrive = peripheral.wrap("bottom")
- monitor = peripheral.wrap("top")
- modem = peripheral.wrap("right")
- radar = peripheral.wrap("left")
- file = fs.open("reward","r")
- if file then
- reward = file.readAll()
- file.close()
- else
- reward = "minecraft:coal"
- end
- file = fs.open("token","r")
- if file then
- token = file.readAll()
- file.close()
- else
- token = "minecraft:coal"
- end
- file = fs.open("tokenCount","r")
- if file then
- tokenCount = file.readAll()
- file.close()
- else
- tokenCount = 0
- end
- --orientation
- while turtle.inspect() do
- turtle.turnRight()
- end
- local rewardCount = 0
- playSide = "left"
- winRate = .4
- winAmount = 2
- adminScreen = false
- monitor.setTextScale(.5)
- local function checkRewards()
- file = fs.open("rewardCount","w")
- turtle.turnRight()
- chest = peripheral.find("ironchest:crystal_chest")
- items = chest.list()
- for _, item in ipairs(items) do
- if item.name == reward then
- rewardCount = rewardCount + item.count
- end
- end
- print("rewards: "..rewardCount)
- file.write(rewardCount)
- file.close()
- turtle.turnLeft()
- end
- checkRewards()
- local function checkWins(values)
- local wins = 0
- for i=1,3 do
- if (values[i] == "X" and values[i+3] == "X" and values[i+6] == "X") then
- wins = wins + 1
- end
- end
- return wins
- end
- local function doDisplay(values, win, credits)
- monitor.clear()
- monitor.setCursorPos(5,1)
- if win then
- monitor.write("You Win!")
- boardShowsWin = false
- else
- monitor.write("You Lose")
- boardShowsWin = true
- end
- local valuePool = {"O","O","O","O","O","O","X","X","X","X"}
- local values = {}
- while ((win and not boardShowsWin) or (not win and boardShowsWin)) and #values ~= 9 do
- for i=1,10 do
- values[i] = valuePool[math.random(1, 10)]
- end
- if checkWins(values) == 1 then
- boardShowsWin = true
- elseif checkWins(values) == 0 then
- boardShowsWin = false
- end
- end
- monitor.setCursorPos(5,3)
- monitor.write("+-+-+-+")
- monitor.setCursorPos(5,4)
- monitor.write("|"..values[1].."|"..values[4].."|"..values[7].."|")
- monitor.setCursorPos(5,5)
- monitor.write("+-+-+-+")
- monitor.setCursorPos(5,6)
- monitor.write("|"..values[2].."|"..values[5].."|"..values[8].."|")
- monitor.setCursorPos(5,7)
- monitor.write("+-+-+-+")
- monitor.setCursorPos(5,8)
- monitor.write("|"..values[3].."|"..values[6].."|"..values[9].."|")
- monitor.setCursorPos(5,9)
- monitor.write("+-+-+-+")
- monitor.setCursorPos(1,10)
- monitor.write("Credits :"..credits - 1)
- end
- local function play(credits)
- random = math.random(1, 10);
- win = false;
- if (random - 1 < 10 * winRate) then
- win = true
- end
- doDisplay(randomValues, win, credits)
- if win then
- turtle.turnRight(1)
- turtle.suck(winAmount)
- turtle.turnLeft(1)
- turtle.drop(winAmount)
- rewardCount = rewardCount - winAmount
- file = fs.open("rewardCount","w")
- file.write(rewardCount)
- file.close()
- end
- end
- local function screenSaver(credits)
- monitor.clear()
- monitor.setCursorPos(1,1)
- monitor.setTextColor(colors.yellow)
- monitor.write("Reward: "..rewardCount)
- monitor.setTextColor(colors.white)
- monitor.setCursorPos(1,2)
- i = string.find(reward, ":")
- monitor.write(winAmount.." "..string.sub(reward, i + 1))
- monitor.setCursorPos(3,5)
- monitor.write("Credits: "..credits, 0)
- if (credits == 0) then
- monitor.setCursorPos(3,7)
- i = string.find(token, ":")
- monitor.write("Add ")
- monitor.setTextColor(colors.yellow)
- monitor.write(string.sub(token, i + 1))
- end
- if (credits > 0) then
- monitor.setCursorPos(1,8)
- monitor.write("Pull the lever")
- monitor.setCursorPos(1,9)
- monitor.write("to play -->")
- end
- end
- adminMenu = {
- "Collect Tokens",
- "Change Token",
- "Add Reward",
- "Change Reward",
- "Exit"
- }
- selectedItem = 1;
- local function showAdminMenu()
- for i=1,#adminMenu do
- if (i == selectedItem) then
- monitor.setTextColor(colors.yellow)
- end
- monitor.setCursorPos(1,2+i)
- monitor.write(adminMenu[i])
- monitor.setTextColor(colors.white)
- end
- end
- local function showAdminScreen()
- monitor.clear()
- monitor.setCursorPos(2,1)
- monitor.setTextColor(colors.red)
- monitor.write("Welcome Admin")
- monitor.setTextColor(colors.white)
- monitor.setCursorPos(1,2)
- showAdminMenu()
- monitor.setCursorPos(1,9)
- monitor.write("Submit:")
- monitor.setCursorPos(1,10)
- monitor.write("Insert Card")
- end
- local function addReward()
- turtle.suckDown()
- turtle.drop()
- monitor.clear()
- monitor.setCursorPos(1,1)
- monitor.write("Add Reward:")
- monitor.setCursorPos(1,2)
- monitor.write(reward)
- monitor.setCursorPos(1,4)
- monitor.write("Current Stock:")
- monitor.setCursorPos(1,5)
- monitor.write(rewardCount)
- monitor.setCursorPos(1,7)
- monitor.write("Pull Lever")
- monitor.setCursorPos(1,8)
- monitor.write("to Exit")
- end
- local function collect(tokenChest)
- turtle.turnRight(1)
- if tokenChest then
- turtle.turnRight(1)
- end
- max = 16
- while max == 16 do
- for i=1,max do
- turtle.suck()
- if turtle.getItemCount(i) ~= 0 and max ~= 16 then
- max = max + 1
- end
- end
- turtle.turnLeft(1)
- if tokenChest then
- turtle.turnLeft(1)
- end
- emptySpace = turtle.getItemSpace()
- for i=1,max do
- turtle.select(i)
- turtle.drop()
- end
- max = emptySpace
- turtle.select(1)
- end
- end
- local function changeToken()
- turtle.suckDown()
- turtle.drop()
- monitor.clear()
- monitor.setCursorPos(1,1)
- monitor.write("Change Token")
- monitor.setCursorPos(1,3)
- monitor.write("Drop the item")
- monitor.setCursorPos(1,5)
- monitor.write("Current Token:")
- monitor.setCursorPos(1,6)
- monitor.write(token)
- os.sleep(2)
- end
- local function changeReward()
- turtle.suckDown()
- turtle.drop()
- monitor.clear()
- monitor.setCursorPos(1,1)
- monitor.write("Change Reward")
- monitor.setCursorPos(1,3)
- monitor.write("Drop the item")
- monitor.setCursorPos(1,5)
- monitor.write("Current Reward:")
- monitor.setCursorPos(1,6)
- monitor.write(reward)
- os.sleep(2)
- end
- local function addCredits()
- turtle.select(1)
- if (turtle.suck(64)) then
- item = turtle.getItemDetail(1)
- print(item.name)
- if (selectedItem == 2) and (item.name ~= "computercraft:disk") then
- tokenFile = fs.open("token",'w')
- tokenFile.write(item.name)
- tokenFile.close()
- tokenCountFile = fs.open("tokenCount",'w')
- tokenCountFile.write(0)
- tokenCountFile.close()
- token = item.name
- monitor.clear()
- monitor.setCursorPos(1,5)
- monitor.write("Token set:")
- monitor.setCursorPos(1,6)
- monitor.write(item.name)
- os.sleep(2)
- collect(true)
- selectedItem = 1
- adminScreen = false
- elseif (selectedItem == 3) then
- if rs.getInput(playSide) then
- monitor.clear()
- showAdminScreen()
- elseif (item.name == reward) then
- turtle.turnRight(1)
- turtle.drop(64)
- turtle.turnLeft(1)
- rewardCount = rewardCount + item.count
- rewardCountFile = fs.open("rewardCount",'w')
- rewardCountFile.write(rewardCount)
- rewardCountFile.close()
- addReward()
- else
- addReward()
- end
- elseif (selectedItem == 4) and (item.name ~= "computercraft:disk") then
- rewardFile = fs.open("reward","w")
- rewardFile.write(item.name)
- rewardFile.close()
- rewardCountFile = fs.open("rewardCount",'w')
- rewardCountFile.write(0)
- rewardCountFile.close()
- reward = item.name
- rewardCount = 0
- monitor.clear()
- monitor.setCursorPos(1,5)
- monitor.write("Reward set:")
- monitor.setCursorPos(1,6)
- monitor.write(item.name)
- os.sleep(2)
- turtle.drop()
- collect(false)
- selectedItem = 1
- adminScreen = false
- elseif (item.name == token) then
- count = item.count
- turtle.turnRight(1)
- turtle.turnRight(1)
- turtle.drop(64)
- turtle.turnLeft(1)
- turtle.turnLeft(1)
- tokenCount = tokenCount + count
- credits = credits + count
- screenSaver(credits)
- elseif (item.name == "computercraft:disk") then
- monitor.clear()
- monitor.setCursorPos(1,5)
- monitor.setTextColor(colors.yellow)
- monitor.write("Authenticating...")
- turtle.dropDown()
- file = fs.open("disk/keycard", "r")
- if file then
- password = file.readAll()
- file.close()
- modem.open(714)
- modem.transmit(816, 714, securityId..":"..diskDrive.getDiskID().."="..password)
- event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- if message then
- turtle.suckDown()
- turtle.drop()
- if not adminScreen then
- showAdminScreen()
- adminScreen = true
- elseif selectedItem == 4 then
- changeReward()
- elseif selectedItem == 3 then
- addReward()
- elseif selectedItem == 2 then
- changeToken()
- elseif selectedItem == 1 then
- collect(true)
- else
- adminScreen = false
- selectedItem = 1
- end
- else
- monitor.clear()
- monitor.setCursorPos(1,5)
- monitor.setTextColor(colors.red)
- monitor.write("Non-Owner Key.")
- end
- end
- turtle.suckDown()
- end
- turtle.drop()
- os.sleep(2)
- end
- end
- local function main()
- credits = 0
- players = radar.getPlayersInRange(2)
- if #players > 0 then
- player = players[1]
- rs.setOutput("bottom", true)
- --print(player)
- else
- rs.setOutput("bottom", false)
- end
- if adminScreen then
- if rs.getInput(playSide) then
- if selectedItem == #adminMenu then
- selectedItem = 1
- else
- selectedItem = selectedItem + 1
- end
- showAdminScreen()
- os.sleep(1)
- end
- else
- screenSaver(credits)
- end
- addCredits()
- while credits > 0 do
- addCredits()
- os.pullEvent("redstone")
- if (rs.getInput(playSide) and credits > 0) then
- play(credits)
- credits = credits - 1
- if (credits == 0) then
- os.sleep(5)
- end
- end
- if (credits == 0 and not adminScreen) then
- screenSaver(0)
- end
- end
- end
- while true do
- main()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement