Skip to content

Instantly share code, notes, and snippets.

@MyNameIsKodos
Created April 29, 2016 16:53
Show Gist options
  • Save MyNameIsKodos/4bd33e4ffb5fc06dc8899c3206cd7e6d to your computer and use it in GitHub Desktop.
Save MyNameIsKodos/4bd33e4ffb5fc06dc8899c3206cd7e6d to your computer and use it in GitHub Desktop.
local component = require("component")
local shell = require("shell")
local timeapi = require("timeapi")
local op = component.openprinter
local args, options = shell.parse(...)
local player = options.player
local amt = options.amount
function timestamp(zone)
tostring(zone)
return timeapi.date("%Y-%m-%d %H:%M", zone)
end
local timestamp = timestamp("utc")
local function isSane(tbl, newnum)
for _, j in ipairs(tbl) do
if j == newnum then
return false
end
end
return true
end
local function drawNumbers()
local tbl = {}
repeat
local newnum = math.random(1,20)
if isSane(tbl, newnum) then
table.insert(tbl, newnum)
end
until #tbl == 3
return tbl
end
-- init printer
op.clear()
op.setTitle(" ")
for x = 1,(amt or 1) do -- For every ticket we want to print, do this
local nums = drawNumbers()
op.setTitle("Lotto Ticket")
op.writeln(options.player .. "'s §1L§2o§3t§4t§5o§r Ticket")
op.writeln(" ")
op.writeln("Your randomly selected")
op.writeln("numbers are as follows")
op.writeln(" ")
op.writeln(nums[1] .. " - " .. nums[2] .. " - " .. nums[3])
op.writeln(" ")
op.writeln("This lotto has been")
op.writeln("brought to you by ")
op.writeln("Miss Fortune and ")
op.writeln("Sir Prize, and was")
op.writeln("paid for by Soluna")
op.writeln("Technologies.")
op.writeln(" ")
op.writeln("Soluna Technologies:")
op.writeln("Innovation at the ")
op.writeln("speed of light.")
op.writeln(" ")
op.writeln(timestamp)
local prnt, err = op.print()
if not prnt then
io.stderr:write(err)
end
op.clear()
op.setTitle(" ")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment