JustDoesGames

error for craftos-pc

Jul 7th, 2020
1,638
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.08 KB | None | 0 0
  1. local w,h = term.getSize()
  2. if not term.isColor() then return printError("Advanced Computer Required.") end
  3. local run = true
  4.  
  5. local seed = os.epoch("utc") -- true randomness
  6. math.randomseed(seed)
  7. math.random(1,1) -- to avoid prediction w/ CraftOS-PC
  8.  
  9. local player = {}
  10. player.money = 0
  11. player.location = 1
  12. player.plots = {}
  13.  
  14. local stock = {}
  15. stock.level = 0
  16. stock.value = .1
  17. stock.maxrate = 10 -- 1 in 10 chances (10%)
  18. stock.minrate = 2 -- 1 in 2 chances (50%)
  19. stock.caps = 10
  20.  
  21. --[[
  22.  
  23. Menu engine
  24.  
  25. ]]--
  26.  
  27. function m(x,y,x2,y2,menu)
  28.     menu = menu or error("Failed to load Menu.")
  29.     x,y = x or error("Failed to load x"), y or error("Failed to load y")
  30.     x2,y2 = x2 or error("Failed to load x2"), y2 or error("Failed to load y2")
  31.     local sel, scroll, run, w, h = 1,0,true, term.getSize()
  32.     while run do
  33.         for i=1, y2-y do
  34.             if menu[i+scroll] ~= nil then
  35.                 term.setCursorPos(x,y+i-1)
  36.                 if sel == i then write("> ") else write("  ") end write(menu[i+scroll])
  37.             end
  38.         end
  39.         a,b = os.pullEvent("key")
  40.         if b == keys.w or b == keys.up then
  41.             if sel == 1 and scroll ~= 0 then
  42.                 scroll = scroll - 1
  43.             elseif sel ~= 1 then
  44.                 sel = sel - 1
  45.             end
  46.         elseif b == keys.s or b == keys.down then
  47.             if sel == y2-y and scroll ~= #menu-(y2-y) then
  48.                 scroll = scroll + 1
  49.             elseif sel ~= math.min(y2-y,#menu) then
  50.                 sel = sel + 1
  51.             end
  52.         elseif b == keys.e or b == keys.enter then
  53.             return sel+scroll
  54.         end
  55.     end
  56. end
  57.  
  58. --[[
  59.  
  60. Menu engine
  61.  
  62. ]]--
  63.  
  64. function runMenu()
  65.     while run do
  66.         sleep(5)
  67.     end
  68. end
  69.  
  70. function runStock()
  71.     while run do
  72.         sleep(1)
  73.         local res = math.random(1,math.random(stock.minrate, stock.maxrate))
  74.         if res == 1 then
  75.             term.setTextColor(colors.green)
  76.             stock.level = math.max(stock.level+stock.value, stock.caps)
  77.             res = "^"
  78.         else
  79.             term.setTextColor(colors.red)
  80.             stock.level = math.min(stock.level-stock.value, stock.caps)
  81.             res = "!"
  82.         end
  83.         term.setCursorPos(1,1)
  84.         print("Stock: "..stock.level.." "..res)
  85.     end
  86. end
  87.  
  88. function run()
  89.     parallel.waitForAny(runStock)
  90. end
  91.  
  92. run()
Advertisement
Add Comment
Please, Sign In to add comment