Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("json")
- local payment_address = "kyrfkvj8zf"
- local op_account = {
- key = "29f9dd35355280c902cfb1db1ca60bbe85b450a252fccc1b61ec24185ec5748a-000",
- address = "kjleqwua7g" -- old: 6vmsG8mGC&xH5+y> new:
- }
- local monitor = peripheral.wrap("top")
- monitor.setTextScale(0.5)
- local markedTransactions = {}
- local investments = {}
- local transactionID = -1
- local player = nil
- local bet = 0
- local playProgress = 0
- local slotA = 0
- local slotB = 0
- local slotC = 0
- local pot = 0
- local function saveMarkedTransactions()
- local fh = fs.open("markedTransactions.dat", "w")
- for k, v in pairs(markedTransactions) do
- fh.writeLine(tostring(k))
- end
- fh.flush()
- fh.close()
- end
- local function updateInvestments()
- local buffer = http.get("http://krist.ceriat.net/addresses/" .. op_account.address .. "/transactions")
- local data = json.decode(buffer.readAll())
- buffer.close()
- if not data.ok then
- error(json.encodePretty(data))
- end
- for i = 1, data.count - 1 do
- local transaction = data.transactions[i]
- if transaction.id > transactionID and not markedTransactions[transaction.id] and transaction.from ~= op_account.address then
- markedTransactions[transaction.id] = true
- saveMarkedTransactions()
- transactionID = transaction.id
- if transaction.value > 0 then
- local newValue
- if investments[transaction.from] then
- newValue = investments[transaction.from] + transaction.value
- else
- newValue = transaction.value
- end
- investments[transaction.from] = newValue
- end
- end
- end
- end
- local function sendKrist(address, amount)
- local buffer = http.post("http://krist.ceriat.net/transactions/", "privatekey=" .. op_account.key .. "&to=" .. address .. "&amount=" .. tostring(amount))
- local data = json.decode(buffer.readAll())
- buffer.close()
- if data.ok then
- return true
- else
- return false, data
- end
- end
- local function displayNonPlaying()
- monitor.setBackgroundColor(colors.yellow)
- for y = 1, 11 do
- monitor.write(" ")
- monitor.setCursorPos(1, y)
- end
- monitor.setCursorPos(1, 2)
- monitor.write(" Send KST to:")
- monitor.setCursorPos(1, 3)
- monitor.write(" kslot.kst")
- monitor.setCursorPos(1, 4)
- monitor.write(" to bet!")
- monitor.setCursorPos(1, 6)
- monitor.write(" Jackpot:")
- monitor.setCursorPos(9 - tostring(pot):len(), 7)
- monitor.write(tostring(pot))
- end
- local function writeSlot(x, y, id)
- monitor.setCursorPos(x, y)
- monitor.setBackgroundColor(colors.red)
- if id == 0 then
- monitor.write("\1")
- elseif id == 1 then
- monitor.write("\2")
- elseif id == 2 then
- monitor.write("\3")
- elseif id == 3 then
- monitor.write("\4")
- end
- end
- local function displayPlaying()
- monitor.setBackgroundColor(colors.yellow)
- for y = 1, 11 do
- monitor.write(" ")
- monitor.setCursorPos(1, y)
- end
- monitor.setCursorPos(1, 1)
- monitor.write(" Player:")
- monitor.setCursorPos(1, 2)
- monitor.write(" " .. player)
- monitor.setCursorPos(6 - tostring(bet):len(), 3)
- monitor.write("Bet: " .. bet)
- monitor.setCursorPos(1, 8)
- monitor.write(" Jackpot:")
- monitor.setCursorPos(9 - tostring(pot):len(), 9)
- monitor.write(tostring(pot))
- writeSlot(6, 6, slotA)
- writeSlot(8, 6, slotB)
- writeSlot(10, 6, slotC)
- end
- local function jackpot()
- monitor.setBackgroundColor(colors.yellow)
- for y = 1, 11 do
- monitor.write(" ")
- monitor.setCursorPos(1, y)
- end
- monitor.setCursorPos(1, 2)
- monitor.write(" Jackpot!")
- monitor.setCursorPos(1, 3)
- monitor.write(player .. " wins")
- monitor.setCursorPos(7 - tostring(pot):len(), 4)
- monitor.write(tostring(pot) .. " KST!")
- sleep(1)
- local ok, err = sendKrist(player, pot)
- if not ok then print(json.encodePretty(err)) end
- pot = 0
- end
- local function loss()
- monitor.setBackgroundColor(colors.yellow)
- for y = 1, 11 do
- monitor.write(" ")
- monitor.setCursorPos(1, y)
- end
- monitor.setCursorPos(1, 4)
- monitor.write(" Loss!")
- local cut = math.floor(0.1 * bet)
- pot = pot - cut
- sendKrist(payment_address, cut)
- sleep(1)
- end
- local function play()
- investments[player] = 0
- pot = pot + bet
- playProgress = 0
- while playProgress < 15 do
- playProgress = playProgress + 1
- slotA = math.random(1, 3)
- slotB = math.random(1, 3)
- slotC = math.random(1, 3)
- displayPlaying()
- sleep(0.1)
- end
- sleep(1)
- if slotA == slotB and slotA == slotC then
- jackpot()
- else
- loss()
- end
- player = nil
- bet = 0
- end
- local function needsToPlay()
- player = nil
- bet = 0
- for k, v in pairs(investments) do
- if v > 0 then
- player = k
- bet = v
- break
- end
- end
- return player and bet
- end
- local buffer = http.get("http://krist.ceriat.net/addresses/" .. op_account.address)
- local data = json.decode(buffer.readAll())
- buffer.close()
- if not data.ok then
- error(json.encodePretty(data))
- end
- pot = data.address.balance
- if fs.exists("markedTransactions.dat") then
- local fh = fs.open("markedTransactions.dat", "r")
- local line = fh.readLine()
- while line do
- markedTransactions[tostring(line)] = true
- line = fh.readLine()
- end
- fh.close()
- end
- while true do
- updateInvestments()
- if needsToPlay() then
- play()
- else
- displayNonPlaying()
- end
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement