Advertisement
NTins

1Ridav Hexagon Control

Aug 22nd, 2014
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.72 KB | None | 0 0
  1. -- 1Ridav Hexagon control program
  2. --Special for computercraft.ru
  3. --Created by Netins
  4.  
  5. teams=
  6. {
  7.     ["red"]=
  8.         {
  9.         ["name"]="",
  10.         ["pcount"]=0
  11.         },
  12.     ["yellow"]=
  13.         {
  14.         ["name"]="",
  15.         ["pcount"]=0
  16.         },
  17.     ["blue"]=
  18.         {
  19.         ["name"]="",
  20.         ["pcount"]=0
  21.         },
  22.     ["green"]=
  23.         {
  24.         ["name"]="",
  25.         ["pcount"]=0
  26.         }      
  27. }
  28.  
  29. coords=
  30. {
  31.     ["red"]=" -253 21 1040", --red base
  32.     ["yellow"]=" -253 21 1040", --yellow base
  33.     ["blue"]=" -326 21 975", --blue base
  34.     ["green"]=" 326 21 1105" --green base
  35. }
  36.  
  37. tools=
  38. {
  39. " 301 1 66", -- infinite leather boots
  40. " 300 1 76", -- infinite leather pants
  41. " 299 1 81", -- infinite leather tunic
  42. " 298 1 56", -- infinite leather cap
  43. " 267 1 251", -- infinite iron sword
  44. " 400 64" -- pumpkin pie(64)
  45. --""  for something
  46. }
  47.  
  48. teamsList={"red","yellow","blue","green"}
  49.  
  50. cb=peripheral.wrap("back")
  51. p=peripheral.wrap("bottom")
  52. m=peripheral.wrap("top")
  53.  
  54. local gameIsOn=false
  55. local var=1
  56.  
  57. function checkNumber()
  58.     local function getNumber()
  59.         return read()+0
  60.     end
  61.     while true do
  62.         e, mes =pcall(getNumber)
  63.         if type(mes) ~= "number"
  64.             then print("<number> expected, got <string>")
  65.         else break
  66.         end
  67.     end
  68. return mes 
  69. end
  70.  
  71. function getTableLenght(a)
  72.     local b=0
  73.     for i,_ in pairs(a) do
  74.         b=b+1
  75.     end
  76.     return b
  77. end
  78.  
  79.  
  80. term.clear()
  81. term.setCursorPos(1,1)
  82. term.setTextColor(colours.red)
  83. print("WARNING! WHEN BATTLE WILL START, YOUR INVENTORY WILL BE CLEARED!\n\n")
  84. term.setTextColor(colours.white)
  85. print("Welcome to 1Ridav Hexagon!\n")
  86. write("Enter count of teams - ")
  87. while true do
  88.     teamCount=checkNumber()
  89.     if teamCount<=1 then
  90.         print("You need at least 2 teams to start a battle")
  91.     else if teamCount >=5 then
  92.             print("Maxium count of teams is 4")
  93.         else break
  94.         end
  95.     end
  96. end
  97.  
  98. --teams settings
  99.  
  100. for i=1, teamCount do
  101.     print("\nThere are settings for ",i," team")
  102.     write("Choose your team's colour (blue, yellow, red, green) - ")
  103.     --checking color
  104.     while true do
  105.         while true do
  106.             color = read()
  107.             if (color ~= "red") and (color ~= "blue") and  (color ~= "green") and (color ~= "yellow") then
  108.                 print("Invalid color")
  109.             else break
  110.             end
  111.         end
  112.         if getTableLenght(teams[color]) >2 then
  113.             print("Color is occupied")
  114.         else break
  115.         end
  116.     end
  117.     currentTeam=teams[color]   
  118.     write("Choose the name for your team - ")
  119.     while true do
  120.         currentTeam.name=read() -- names of teams can be same
  121.         if currentTeam.name == "" then
  122.             print("Invalid name")
  123.         else break
  124.         end
  125.     end
  126.     write("Enter count of players in the team - ")
  127.     currentTeam.pcount=checkNumber()
  128.     if currentTeam.pcount>=10 then
  129.         print("Wow. Much players.") --xD
  130.     end
  131.    
  132.     --put some sensor methods here
  133.    
  134.     write("Enter players' nicknames - ")
  135.     for i=1,currentTeam.pcount do
  136.         local player = read()
  137.         currentTeam[player]=1
  138.     end
  139.     color,player=nil
  140. end
  141.  
  142. --[[for i,v in pairs(teams) do
  143. print("in ",i)
  144. for c,m in pairs(v) do
  145. print("index - ",c)
  146. print("inside - ",m)
  147. end
  148. end]]
  149.  
  150. cb.setCommand("/say Match started")
  151. cb.runCommand()
  152.  
  153. for i,v in pairs(teams) do
  154.     for a,_ in pairs(v) do
  155.         if a~= "name" then
  156.             cb.setCommand("/tp "..a..coords[i])
  157.             cb.runCommand()
  158.         end
  159.         for n=1,#tools do
  160.             cb.setCommand("/clear "..a)
  161.             cb.runCommand()
  162.             cb.setCommand("/give "..a..tools[n])
  163.             cb.runCommand()
  164.         end
  165.     end
  166. end
  167.  
  168. for _,v in pairs(teams) do
  169.     for player,_ in pairs(v) do
  170.         cb.setCommand("/effect "..player.." 15 1000000 10")
  171.         cb.runCommand()
  172.     end
  173. end
  174. gameIsOn=true
  175. while gameIsOn do
  176.     for teamColor, tab in pairs(teams) do
  177.         for player, lifestat in pairs(tab) do
  178.             if getTableLenght(teams[teamColor]) > 2 and (player ~= "name") and (player ~= "pcount") and teams[teamColor].pcount>0 then
  179.                 pl=p.getPlayerByName(player)
  180.                 health=pl.getHealth()
  181.                 if (health==0) and (teams[teamColor][player]==1) then
  182.                     cb.setCommand("/say Member of "..teamColor.." team - ".."[".. teams[teamColor].name .."]"..player.." - died.")
  183.                     cb.runCommand()
  184.                     teams[teamColor][player]=0
  185.                     teams[teamColor].pcount=teams[teamColor].pcount-1
  186.                 end
  187.                 if teams[teamColor].pcount == 0 then
  188.                     cb.setCommand("/say All players of "..teams[teamColor].name.."["..teamColor.."]" .." team destroyed!")
  189.                     cb.runCommand()
  190.                 end
  191.             end
  192.         end
  193.         -- i'm so sorry for the code below
  194.         if (teams.red.pcount>0) and (teams.yellow.pcount==0) and (teams.blue.pcount==0) and (teams.green.pcount==0) then
  195.             cb.setCommand("/say Red team ("..teams.red.name..") wins!")
  196.             cb.runCommand()
  197.             gameIsOn=false
  198.             winner="red"
  199.             break
  200.         elseif teams.red.pcount==0 and teams.yellow.pcount>0 and teams.blue.pcount==0 and teams.green.pcount==0 then
  201.             cb.setCommand("/say Yellow team ("..teams.yellow.name.. ") wins!")
  202.             cb.runCommand()
  203.             gameIsOn=false
  204.             winner="yellow"
  205.             break
  206.         elseif teams.red.pcount==0 and teams.yellow.pcount==0 and teams.blue.pcount>0 and teams.green.pcount==0 then
  207.             cb.setCommand("/say Blue team ("..teams.blue.name.. ") wins!")
  208.             cb.runCommand()
  209.             gameIsOn=false
  210.             winner="blue"
  211.             break
  212.         elseif teams.red.pcount==0 and teams.yellow.pcount==0 and teams.blue.pcount==0 and teams.green.pcount>0 then
  213.             cb.setCommand("/say Green team ("..teams.green.name.. ") wins!")
  214.             cb.runCommand()
  215.             gameIsOn=false
  216.             winner="green"
  217.             break
  218.         end
  219.     end
  220.     sleep(0.01) -- i'm not sure about this number
  221. end
  222. for _,v in pairs(teams) do
  223.     for i,_ in pairs(v) do
  224.         if i ~= "name" and i~="pcount" then
  225.             cb.setCommand("/effect "..i.." clear")
  226.             cb.runCommand()
  227.             cb.setCommand("/clear "..i)
  228.             cb.runCommand()
  229.             sleep(3) -- waits for the last player
  230.             cb.setCommand("/tp "..i.." -326 39 1040") -- telports to the center of hub
  231.             cb.runCommand()
  232.         end
  233.     end
  234. end
  235.  
  236. for win,_ in pairs(teams[winner]) do
  237. cb.setCommand("/give "..win.." 397 1 4") -- gives creeper head
  238. cb.runCommand()
  239. end
  240.  
  241. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement