Advertisement
wv1106

russian roulette don't install use the installer

Apr 15th, 2021 (edited)
796
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.40 KB | None | 0 0
  1. --------------------------------------------
  2. -- to play this please use the installer
  3. -------------things to change------------------
  4. local limit = 10                --the minimum to play
  5. local perc = 0.15               --how much you earn each shot (100% = 1.00 and 1% = 0.01)
  6. ------------------------------
  7.  
  8.  
  9.  
  10.  
  11.  
  12. local amount = limit
  13. local earn = 0
  14. local death = false
  15. local earned = 0
  16. local ongoing = true
  17. local enter = true
  18. -----------------------------------
  19.  
  20. one = true
  21. two = true
  22. three = true
  23. four = true
  24. five = true
  25. six = true
  26.  
  27. function readCard()
  28.     if not fs.exists("disk/creds.lua") then
  29.         os.reboot()
  30.     end
  31.     local Card = fs.open("disk/creds.lua", "r")
  32.     data = Card.readAll()
  33.     Card.close()
  34.     a, b = string.find(data, "11066011")
  35.     c, d = string.find(data, "11077011")
  36.     creds = tonumber(string.sub(data, b+1, c-1))
  37.     if creds < limit then
  38.         paintutils.drawFilledBox(1, 1, 51, 19, colors.green)
  39.         term.clear()
  40.         term.setCursorPos(5, 10)
  41.         term.write("{you don't have enough credits to continiue}")
  42.         while fs.exists("disk/") do
  43.             sleep(0,5)
  44.         end
  45.         os.reboot()
  46.     end
  47. end
  48. function writeCard()
  49.     if not fs.exists("disk/creds.lua") then
  50.         os.reboot()
  51.     end
  52.     local Card = fs.open("disk/creds.lua", "w")
  53.     data = (tostring(math.random(1, 163456)).."11066011"..tostring(creds).."11077011"..tostring(math.random(1, 163456)))
  54.     Card.write(tostring(data))
  55.     Card.close()
  56.     disk.setLabel("bottom", tostring(creds).."$")
  57. end
  58. local chamber = paintutils.loadImage("images/chamber.nfp")
  59. local revolver = paintutils.loadImage("images/revolver.nfp")
  60. function insert_card()
  61.     paintutils.drawFilledBox(1, 1, 51, 19, colors.black)
  62.     paintutils.drawImage(revolver, 14, 2)
  63.     while not fs.exists("disk/") do
  64.         term.clear()
  65.         paintutils.drawFilledBox(1, 1, 51, 19, colors.black)
  66.         paintutils.drawImage(revolver, 14, 2)
  67.         term.setCursorPos(16, 10)
  68.         term.setBackgroundColor(colors.black)
  69.         term.write("{please insert card}")
  70.         sleep(1)
  71.     end
  72.     term.clear()
  73. end
  74. function insert_amount()
  75.     amount = limit
  76.     paintutils.drawFilledBox(1, 1, 51, 19, colors.black)
  77.     enter = true
  78.     while enter do
  79.         if not fs.exists("disk/creds.lua") then
  80.             os.reboot()
  81.         end
  82.         term.clear()
  83.         term.setCursorPos(18, 6)
  84.         term.write("{bidding amount}")
  85.         term.setCursorPos(2, 7)
  86.         term.write("every shot you take you earn "..(perc * 100).."% of your amount")
  87.         term.setCursorPos(24, 10)
  88.         term.write("|"..amount.."$|")
  89.         local event, key, is_held = os.pullEvent("key")  
  90.         while key==keys.up and amount < creds do
  91.            
  92.             amount = amount+1
  93.             term.setCursorPos(24, 10)
  94.             term.clear()
  95.             term.write("|"..amount.."$|")
  96.             term.setCursorPos(18, 6)
  97.             term.write("{bidding amount}")
  98.             term.setCursorPos(2, 7)
  99.             term.write("every shot you take you earn "..(perc * 100).."% of your amount")
  100.             key = nil
  101.             local event, key, is_held = os.pullEvent("key")  
  102.         end
  103.         while key==keys.down and amount>limit do
  104.             amount = amount-1
  105.             term.setCursorPos(24, 10)
  106.             term.clear()
  107.             term.write("|"..amount.."$|")
  108.             term.setCursorPos(18, 6)
  109.             term.write("{bidding amount}")
  110.             term.setCursorPos(2, 7)
  111.             term.write("every shot you take you earn "..(perc * 100).."% of your amount")
  112.             key = nil
  113.             local event, key, is_held = os.pullEvent("key")  
  114.         end
  115.         key = nil
  116.         local event, key, is_held = os.pullEvent("key")
  117.         if key==keys.enter then
  118.             enter = false
  119.         end
  120.     end
  121.     creds = creds - amount
  122.     writeCard()
  123.     if not fs.exists("disk/creds.lua") then
  124.         os.reboot()
  125.     end
  126.     earn = amount * perc
  127. end
  128. function died()
  129.     paintutils.drawFilledBox(1, 1, 51, 19, colors.white)
  130.     sleep(1)
  131.     term.setCursorPos(22, 9)
  132.     term.blit("You died", "77777777", "00000000")
  133.     sleep(3)
  134. end
  135. function game()
  136.     paintutils.drawFilledBox(1, 1, 51, 19, colors.black)
  137.     term.clear()
  138.     term.setCursorPos(40, 8)
  139.     term.setTextColor(1)
  140.     term.write(earned.."$ earned")
  141.     local bullet = math.random(6)
  142.     paintutils.drawImage(chamber, 5, 4)
  143.     ongoing = true
  144.     local event, kb, x, y = os.pullEvent()
  145.     while ongoing == true do
  146.         local event, kb, x, y = os.pullEvent()
  147.         if event == "mouse_click" then
  148.             term.setCursorPos(20, 1)
  149.             if (24 <= x) and (x <= 26) and (5 <= y) and (y <= 6) and (one == true) then           --1
  150.                 if bullet == 1 then
  151.                     ongoing = false
  152.                     death = true
  153.                     died()
  154.                 else
  155.                     earned = earned + earn
  156.                     one = false
  157.                     term.blit("1 is empty", "1111111111", "ffffffffff")
  158.                     paintutils.drawFilledBox(24, 5, 26, 6, colors.black)
  159.                 end
  160.             elseif (30 <= x) and (x <= 32) and (8 <= y) and (y <= 9) and (two == true) then       --2
  161.                 if bullet == 2 then
  162.                     ongoing = false
  163.                     death = true
  164.                     died()
  165.                 else
  166.                     earned = earned + earn
  167.                     two = false
  168.                     term.blit("2 is empty", "1111111111", "ffffffffff")
  169.                     paintutils.drawFilledBox(30, 8, 32, 9, colors.black)
  170.                 end
  171.             elseif (30 <= x) and (x <= 32) and (12 <= y) and (y <= 13) and (three == true) then     --3
  172.                 if bullet == 3 then
  173.                     ongoing = false
  174.                     death = true
  175.                     died()
  176.                 else
  177.                     earned = earned + earn
  178.                     three = false
  179.                     term.blit("3 is empty", "1111111111", "ffffffffff")
  180.                     paintutils.drawFilledBox(30, 12, 32, 13, colors.black)
  181.                 end
  182.             elseif (24 <= x) and (x <= 26) and (15 <= y) and (y <= 16) and (four == true) then     --4
  183.                 if bullet == 4 then
  184.                     ongoing = false
  185.                     death = true
  186.                     died()
  187.                 else
  188.                     earned = earned + earn
  189.                     four = false
  190.                     term.blit("4 is empty", "1111111111", "ffffffffff")
  191.                     paintutils.drawFilledBox(24, 15, 26, 16, colors.black)
  192.                 end
  193.             elseif (18 <= x) and (x <= 20) and (12 <= y) and (y <= 13) and (five == true) then     --5
  194.                 if bullet == 5 then
  195.                     ongoing = false
  196.                     death = true
  197.                     died()
  198.                 else
  199.                     earned = earned + earn
  200.                     five = false
  201.                     term.blit("5 is empty", "1111111111", "ffffffffff")
  202.                     paintutils.drawFilledBox(18, 12, 20, 13, colors.black)
  203.                 end
  204.             elseif (18 <= x) and (x <= 20) and (8 <= y) and (y <= 9) and (six == true) then       --6
  205.                 if bullet == 6 then
  206.                     ongoing = false
  207.                     death = true
  208.                     died()
  209.                 else
  210.                     earned = earned + earn
  211.                     six = false
  212.                     term.blit("6 is empty", "1111111111", "ffffffffff")
  213.                     paintutils.drawFilledBox(18, 8, 20, 9, colors.black)
  214.                 end
  215.             end
  216.             term.setCursorPos(40, 8)
  217.             term.write(earned.."$ earned")
  218.         elseif kb == keys.enter then
  219.             term.setCursorPos(15, 1)
  220.             term.blit("you spun the chamber", "11111111111111111111", "ffffffffffffffffffff")
  221.             sleep(1)
  222.             one = true
  223.             two = true
  224.             three = true
  225.             four = true
  226.             five = true
  227.             six = true
  228.             ongoing = false
  229.         end
  230.     end
  231. end
  232.  
  233. while 1 do
  234.     earned = 0
  235.     insert_card()
  236.     readCard()
  237.     insert_amount()
  238.     writeCard()
  239.     death = false
  240.     one = true
  241.     two = true
  242.     three = true
  243.     four = true
  244.     five = true
  245.     six = true
  246.     while death == false do
  247.         game()
  248.     end
  249.     readCard()
  250.     creds = creds + earned
  251.     writeCard()
  252. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement