Advertisement
Guest User

miner.lua

a guest
Oct 22nd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.86 KB | None | 0 0
  1. -- the computers coordinates
  2. x = -111
  3. y = 75
  4. z = 61
  5.  
  6. flag = 0
  7.  
  8. rand = math.random(1,20)
  9. -- this is important for knowing where to place the minigame.
  10.  
  11. function shell()
  12.     commands.exec("/fill ~-1 ~1 ~11 ~-23 ~4 ~-10 bedrock")
  13.     commands.exec("/fill ~-3 ~2 ~10 ~-22 ~3 ~-9 air")
  14. end
  15.  
  16. function delshell()
  17.     commands.exec("/fill ~-1 ~1 ~11 ~-23 ~4 ~-10 air")
  18. end
  19.  
  20. function gen()
  21.     --count = 0
  22.     tnarr = {}
  23.    
  24.     -- stone 1 = 1pt
  25.     -- iron 2 = 2pts
  26.     -- gold 3 = 5pts
  27.     -- lapis 4 = 10pts
  28.     -- emerald 5 = 50pts
  29.     -- diamond 6 = 50pts
  30.    
  31.     for k=0,1,1 do -- y coordinates
  32.         tnarr[k] = {}
  33.        
  34.         for j=0,19,1 do -- z coordinates
  35.             tnarr[k][j] = {}
  36.            
  37.             for i=0,19,1 do -- x coordinates
  38.                 tnarr[k][j][i] = 0
  39.                
  40.                 if rand < 12 then
  41.                     commands.exec("/setblock " .. x - 2 - i .. " " .. y + k .. " " .. z - j .. " stone")
  42.                     tnarr[k][j][i] = 1
  43.                    
  44.                 elseif rand > 11 and rand < 15 then
  45.                     commands.exec("/setblock " .. x - 2 - i .. " " .. y + k .. " " .. z - j .. " iron_block")
  46.                     tnarr[k][j][i] = 2
  47.                    
  48.                 elseif rand > 14 and rand < 17 then
  49.                     commands.exec("/setblock " .. x - 2 - i .. " " .. y + k .. " " .. z - j .. " gold_block")
  50.                     tnarr[k][j][i] = 3
  51.                    
  52.                 elseif rand > 16 and rand < 19 then
  53.                     commands.exec("/setblock " .. x - 2 - i .. " " .. y + k .. " " .. z - j .. " lapis_block")
  54.                     tnarr[k][j][i] = 4
  55.                
  56.                 elseif rand == 19 then
  57.                     commands.exec("/setblock " .. x - 2 - i .. " " .. y + k .. " " .. z - j .. " emerald_block")
  58.                     tnarr[k][j][i] = 5
  59.                
  60.                 else
  61.                     commands.exec("/setblock " .. x - 2 - i .. " " .. y + k .. " " .. z - j .. " diamond_block")        
  62.                     tnarr[k][j][i] = 6
  63.                
  64.                 end
  65.                
  66.                 rand = math.random(1,20)
  67.                 --count = count + 1
  68.             end
  69.    
  70.         end
  71.    
  72.     end
  73.     --print(count .. " count")
  74.        
  75. end
  76.  
  77. function playertp(mflag)
  78.     if mflag == 0 then
  79.         commands.exec("/tp @p " .. x-1 .. " " .. y .. " " .. z-8)
  80.         parallel.waitForAny(function() time(60) end,killm)
  81.     elseif mflag == 1 then
  82.         commands.exec("/tp @p " .. x+2 .. " " .. y .. " " .. z-8)
  83.         commands.exec("/w @p Counting up your score, please wait.")
  84.         scoring()
  85.     end
  86. end
  87.  
  88. function time(time) -- number of seconds the game lasts
  89.     --time = 6
  90.     while time > 0 do
  91.         sleep(1)
  92.         time = time - 1
  93.         if time == 5 then
  94.             commands.exec("/w @p Minigame ends in 5...")
  95.         elseif time < 5 and time > 0 then
  96.             commands.exec("/w @p " .. time .. "...")
  97.         end
  98.     end
  99.    
  100.     commands.exec("/w @p Time's up!")
  101.     playertp(1)    
  102. end
  103.  
  104. function killm() -- prevents drops and monsters in area
  105.     while 1 do
  106.         commands.exec("/kill @e[type=item,x=" .. x-10 .. ",y=" .. y .. ",z=" .. z-10 .. ",r=20]")
  107.         commands.exec("/tp @e[type=Skeleton,x=" .. x-10 .. ",y=" .. y .. ",z=" .. z-10 .. ",r=20]")
  108.         commands.exec("/tp @e[type=Zombie,x=" .. x-10 .. ",y=" .. y .. ",z=" .. z-10 .. ",r=20]")
  109.     end
  110. end
  111.  
  112. function scoring()
  113.     score = 0
  114.     st = 0
  115.     ir = 0
  116.     go = 0
  117.     la = 0
  118.     em = 0
  119.     di = 0
  120.  
  121.     for n=0,1,1 do
  122.         for m=0,19,1 do
  123.             for l=0,19,1 do
  124.                 if commands.exec("/testforblock " .. x - 2 - l .. " " .. y + n .. " " .. z - m .. " air") then
  125.                     print(tnarr[n][m][l])
  126.                    
  127.                     if tnarr[n][m][l] == 1 then
  128.                         score = score + 1
  129.                         st = st + 1
  130.                        
  131.                     elseif tnarr[n][m][l] == 2 then
  132.                         score = score + 2
  133.                         ir = ir + 1
  134.            
  135.                     elseif tnarr[n][m][l] == 3 then
  136.                         score = score + 5
  137.                         go = go + 1
  138.                        
  139.                     elseif tnarr[n][m][l] == 4 then
  140.                         score = score + 10
  141.                         la = la + 1
  142.                        
  143.                     elseif tnarr[n][m][l] == 5 then
  144.                         score = score + 50
  145.                         em = em + 1
  146.                        
  147.                     elseif tnarr[n][m][l] == 6 then
  148.                         score = score + 50
  149.                         di = di + 1
  150.                     end
  151.                    
  152.                     bmined = st + ir + go + la + em + di
  153.                 end
  154.             end
  155.         end
  156.     end
  157.    
  158.     commands.exec("/w @p You scored " .. score .. " points!")
  159.     commands.exec("/w @p You mined " .. bmined .. " blocks!")
  160.     commands.exec("/w @p Stone: " .. st .. " Iron: " .. ir .. " Gold: " .. go .. " Lapis: " .. la .. " Emerald: " .. em .. " Diamond: " .. di)
  161. end
  162.  
  163. function clear()
  164.     commands.exec("/fill ".. x-2 .. " " .. y .. " " .. z .. " " .. x-21 .. " " .. y+1 .. " " .. z-19 .." air")
  165. end
  166.  
  167. shell() --for shell generation when computer moved
  168. --testforblock should be true after testing.
  169. --if commands.exec("/testforblock ") == false and flag == 0 then
  170.   --  flag = 1
  171.     --commands.exec("/w @p Please wait for minigame to generate.")
  172.    -- gen() -- creates a 20x20 mine
  173.    -- commands.exec("/w @p Minigame begins in 3...")
  174.    -- sleep(1)
  175.    -- commands.exec("/w @p 2...")
  176.    -- sleep(1)
  177.   --  commands.exec("/w @p 1...")
  178.    -- sleep(1)
  179.    -- commands.exec("/w @p Start!")
  180.    -- playertp(0)
  181.    -- flag = 0
  182. --end
  183.  
  184. --sleep(5)
  185. --clear() -- hope it doesnt delete the world
  186. --delshell()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement