Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local w,h = term.getSize()
- if not term.isColor() then return printError("Advanced Computer Required.") end
- local run = true
- local seed = os.epoch("utc") -- true randomness
- math.randomseed(seed)
- math.random(1,1) -- to avoid prediction w/ CraftOS-PC
- local player = {}
- player.money = 0
- player.location = 1
- player.plots = {}
- local stock = {}
- stock.level = 0
- stock.value = .1
- stock.maxrate = 10 -- 1 in 10 chances (10%)
- stock.minrate = 2 -- 1 in 2 chances (50%)
- stock.caps = 10
- --[[
- Menu engine
- ]]--
- function m(x,y,x2,y2,menu)
- menu = menu or error("Failed to load Menu.")
- x,y = x or error("Failed to load x"), y or error("Failed to load y")
- x2,y2 = x2 or error("Failed to load x2"), y2 or error("Failed to load y2")
- local sel, scroll, run, w, h = 1,0,true, term.getSize()
- while run do
- for i=1, y2-y do
- if menu[i+scroll] ~= nil then
- term.setCursorPos(x,y+i-1)
- if sel == i then write("> ") else write(" ") end write(menu[i+scroll])
- end
- end
- a,b = os.pullEvent("key")
- if b == keys.w or b == keys.up then
- if sel == 1 and scroll ~= 0 then
- scroll = scroll - 1
- elseif sel ~= 1 then
- sel = sel - 1
- end
- elseif b == keys.s or b == keys.down then
- if sel == y2-y and scroll ~= #menu-(y2-y) then
- scroll = scroll + 1
- elseif sel ~= math.min(y2-y,#menu) then
- sel = sel + 1
- end
- elseif b == keys.e or b == keys.enter then
- return sel+scroll
- end
- end
- end
- --[[
- Menu engine
- ]]--
- function runMenu()
- while run do
- sleep(5)
- end
- end
- function runStock()
- while run do
- sleep(1)
- local res = math.random(1,math.random(stock.minrate, stock.maxrate))
- if res == 1 then
- term.setTextColor(colors.green)
- stock.level = math.max(stock.level+stock.value, stock.caps)
- res = "^"
- else
- term.setTextColor(colors.red)
- stock.level = math.min(stock.level-stock.value, stock.caps)
- res = "!"
- end
- term.setCursorPos(1,1)
- print("Stock: "..stock.level.." "..res)
- end
- end
- function run()
- parallel.waitForAny(runStock)
- end
- run()
Advertisement
Add Comment
Please, Sign In to add comment