FCKJesus

casino

Sep 14th, 2020
1,831
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local gg = {}
  2. local component = require("component")
  3. local gpu = component.gpu
  4. local term = require("term")
  5. local event = require("event")
  6. local unicode = require("unicode")
  7. local fs = require("filesystem")
  8. local internet = require("internet")
  9. local chat = component.chat_box
  10.  
  11. chat.setName("§r§6Рулетка§7§l")
  12. chat.setDistance(10)
  13.  
  14. function gg.com(command) --Выполнить команду
  15.     if (component.isAvailable("opencb")) then
  16.         local _,c = component.opencb.execute(command)
  17.         return c
  18.     end
  19. end
  20.  
  21. function gg.money(nick) --Баланс игрока
  22.     local c = gg.com("money " .. nick)
  23.     local _, b = string.find(c, "Баланс: §f")
  24.     local balance
  25.     if string.find(c, "Emeralds") ~= nil then
  26.         balance = unicode.sub(c, b - 16, unicode.len(c) - 10)
  27.     else
  28.         balance = unicode.sub(c, b - 16, unicode.len(c) - 9)
  29.     end
  30.     return (balance)
  31. end
  32. function gg.checkMoney(nick,money) --Чекнуть, баланс, если хватает, то снять бабки
  33.     local balance = gg.money(nick)
  34.     balance = string.sub(balance, 1, string.len(balance) - 3)
  35.     if string.find(balance, "-") ~= nil then
  36.         return false
  37.     else
  38.         balance = string.gsub(balance,",","")
  39.         if tonumber(balance) < money then
  40.             return false
  41.         else
  42.             gg.com("money take " .. nick .. " " .. money)
  43.             return true
  44.         end
  45.     end
  46. end
  47.  
  48. function localsay(msg) chat.say("§e".. msg) end
  49.  
  50. local values = {[0] = 'z','r','b','r','b','r','b','r','b','r','b','b','r','b','r','b','r','b','r','r','b','r','b','r','b','r','b','r','b','b','r','b','r','b','r','b','r'}
  51. local wheel = {0,32,15,19,4,21,2,25,17,34,6,27,13,36,11,30,8,23,10,5,24,16,33,1,20,14,31,9,22,18,29,7,28,12,35,3,26,0,32,15,19,4,21,2,25,17}
  52. local red = {1,3,5,7,9,12,14,16,18,19,21,23,25,27,30,32,34,36}
  53. local black = {2,4,6,8,10,11,13,15,17,20,22,24,26,28,29,31,33,35}
  54.  
  55. function drawNumber(left,top,number)
  56.   if(values[number] == 'r') then gpu.setBackground(0xff0000)
  57.   elseif(values[number] == 'b') then gpu.setBackground(0x000000)
  58.   else gpu.setBackground(0x00ff00) end
  59.   gpu.fill(left,top,6,3,' ')
  60.   gpu.set(left+2,top+1,tostring(number))
  61. end
  62.  
  63. function getColor(number)
  64.     if(number == 0) then return "" end
  65.     for i = 1,#red do
  66.         if(red[i] == number) then return "(красное)" end
  67.     end
  68.     return "(чёрное)" end
  69.  
  70. gpu.setResolution(112,21)
  71. gpu.setBackground(0xffffff)
  72. term.clear()
  73. gpu.setForeground(0x000000)
  74. gpu.set(103,14,"Ставки:")
  75. gpu.set(103,15,"ЛКМ 1 ЭМ")
  76. gpu.set(103,16,"ПКМ 10 ЭМ")
  77. gpu.setForeground(0x777777)
  78. gpu.set(103,18,"Авторы:")
  79. gpu.set(103,19,"krovyaka")
  80. gpu.set(103,20,"GooodGame")
  81. gpu.setForeground(0xffffff)
  82. gpu.setBackground(0x00ff00)
  83. gpu.fill(13,2,5,11,' ')
  84. gpu.set(15,7,"0")
  85. for i = 1, 36 do
  86.   drawNumber(19+math.floor((i-1)/3)*7,2+((3-i)%3*4),i)
  87. end
  88. gpu.setBackground(0x34a513)
  89. gpu.fill(103,2,9,3,' ') gpu.fill(103,6,9,3,' ') gpu.fill(103,10,9,3,' ')
  90. gpu.set(106,3,"2к1") gpu.set(106,7,"2к1") gpu.set(106,11,"2к1")
  91. gpu.fill(19,14,27,3, ' ') gpu.fill(47,14,27,3, ' ') gpu.fill(75,14,27,3, ' ')
  92. gpu.set(28,15,"первая 12") gpu.set(56,15,"вторая 12") gpu.set(84,15,"третья 12")
  93. gpu.fill(19,18,13,3,' ') gpu.fill(33,18,13,3,' ')  gpu.fill(75,18,13,3,' ')  gpu.fill(89,18,13,3,' ')
  94. gpu.set(22,19,"1 до 18") gpu.set(38,19,"Чёт") gpu.set(79,19,"Нечёт") gpu.set(91,19,"19 до 36")
  95. gpu.setBackground(0xff0000) gpu.fill(47,18,13,3,' ') gpu.set(50,19,"Красное")
  96. gpu.setBackground(0x000000) gpu.fill(61,18,13,3,' ') gpu.set(64,19,"Чёрное")
  97. gpu.setBackground(0xffb109) gpu.fill(3,2,8,19,' ')
  98. gpu.setBackground(0xffda54) gpu.fill(3,9,8,5,' ')
  99.  
  100. function Roll()
  101.   local current = math.random(1,35)
  102.   for i = 1,math.random(30,50) do
  103.     current = current + 1
  104.     if (current == 38) then current = 1 end
  105.     drawNumber(4,2,wheel[current+4])
  106.     drawNumber(4,6,wheel[current+3])
  107.     drawNumber(4,10,wheel[current+2])
  108.     drawNumber(4,14,wheel[current+1])
  109.     drawNumber(4,18,wheel[current])
  110.     os.sleep(i/140)
  111.   end
  112.   return wheel[current+2]
  113. end
  114.  
  115. function getNumberClick(left,top)
  116.   if(top==5) or (top==9) or (left%7==4) then return 0 end
  117.   return (math.floor((left-18)/7)*3) + math.floor(4-(top-1)/4)
  118. end
  119.  
  120.  
  121. Bets = {}
  122. function resetBets() Bets={} for i = 0,36 do Bets[i] = {} end end
  123.  
  124. function placeBet(nick,number,money)  
  125.   if(Bets[number][nick]==nil) then Bets[number][nick]=money else Bets[number][nick] = Bets[number][nick] + money end
  126. end
  127.  
  128. function placeBetByTable(t,nick,money) for i = 1,#t do placeBet(nick,t[i],money) end end
  129.  
  130. function fixClicks(left,top)
  131.   return not((left<13) or (top<2) or (left>111) or (top>20) or (left<19 and top>12) or (left==18) or (left==46) or (left==102) or (top==12) or (top==17) or (((left>18)and(left<102)and(top>1)and(top<13)) and getNumberClick(left,top)==0) or (top>17 and top<21 and (left==32 or left==46 or left==60 or left==74 or left==88)) or (left>101 and top>12) or (left>102 and (top == 5 or top==9))) end
  132.  
  133. local endbets = 0
  134.  
  135. while true do
  136.   resetBets()
  137.   endbets = 0
  138.   while endbets==0 or (endbets>os.time()) do
  139.     local _,_,left,top,clicktype,p = event.pull(3,"touch")
  140.     if(p~=nil) then
  141.       local number,money = 0,1+clicktype*9
  142.       if(fixClicks(left,top)) then
  143.         if (gg.checkMoney(p,money)) then
  144.           if(endbets == 0) then endbets = os.time()+1080 localsay("Рулетка крутится через 15 сек после первой ставки.") end  
  145.           if(left>18)and(left<102)and(top>1)and(top<13) then
  146.             number = getNumberClick(left,top)
  147.           end
  148.           if number > 0 then placeBet(p,number,money*36) localsay(p.." поставил "..money.." на "..number )
  149.           elseif (left>12)and(left<18)and(top>1)and(top<13) then localsay(p.." поставил "..money.." на 0") placeBet(p,0,money*36)
  150.           elseif (left>18)and(left<46)and(top>13)and(top<17) then localsay(p.." поставил "..money.." на первую 12") money = money*3 for i = 1, 12 do placeBet(p,i,money) end
  151.           elseif (left>46)and(left<74)and(top>13)and(top<17) then localsay(p.." поставил "..money.." на вторую 12") money = money*3 for i = 13, 24 do placeBet(p,i,money) end
  152.           elseif (left>74)and(left<102)and(top>13)and(top<17) then localsay(p.." поставил "..money.." на третью 12") money = money*3 for i = 25, 36 do placeBet(p,i,money) end
  153.           elseif (left>18)and(left<32)and(top>17)and(top<21) then localsay(p.." поставил "..money.." на 1 до 18") money = money*2 for i = 1, 18 do placeBet(p,i,money) end
  154.           elseif (left>32)and(left<46)and(top>17)and(top<21) then localsay(p.." поставил "..money.." на чётное") money = money*2 for i = 2,36,2 do placeBet(p,i,money) end
  155.           elseif (left>46)and(left<60)and(top>17)and(top<21) then localsay(p.." поставил "..money.." на красное") placeBetByTable(red,p,money*2)
  156.           elseif (left>60)and(left<74)and(top>17)and(top<21) then localsay(p.." поставил "..money.." на чёрное") placeBetByTable(black,p,money*2)
  157.           elseif (left>74)and(left<88)and(top>17)and(top<21) then localsay(p.." поставил "..money.." на нечётное") money = money*2 for i = 1,35,2 do placeBet(p,i,money) end
  158.           elseif (left>88)and(left<102)and(top>17)and(top<21) then localsay(p.." поставил "..money.." на 19 до 36") money = money*2 for i = 19, 36 do placeBet(p,i,money) end
  159.           elseif (left>102)and(left<112)and(top>1)and(top<5) then localsay(p.." поставил "..money.." на 2к1 (верхний ряд)") money = money*3 for i = 3,36,3 do placeBet(p,i,money) end
  160.           elseif (left>102)and(left<112)and(top>5)and(top<9) then localsay(p.." поставил "..money.." на 2к1 (средний ряд)") money = money*3 for i = 2,35,3 do placeBet(p,i,money) end
  161.           elseif (left>102)and(left<112)and(top>9)and(top<13) then localsay(p.." поставил "..money.." на 2к1 (нижний ряд)") money = money*3 for i = 1,34,3 do placeBet(p,i,money) end
  162.           end
  163.         else localsay("§c"..p..", у вас нет столько денег.") end
  164.       end
  165.     end
  166.   end
  167.   localsay("Колесо крутится... Сумма ставок на игру: "  ..  (function() local sum = 0 for k,v in pairs(Bets) do for k1,v1 in pairs(v) do sum = sum + v1 end end return sum/36 end)())
  168.   local out = Roll()
  169.   localsay("Выпало число " .. out .. " " .. getColor(out))
  170.   for p,money in pairs(Bets[out]) do gg.com("money give " .. p .." ".. money) localsay(p.." выиграл "..money) end
  171. end
RAW Paste Data