Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.12 KB | None | 0 0
  1. admins = {"pighead10","Player"}
  2. teams = {}
  3. rounds = {
  4. "Group stage", --1
  5. "Quarter final", --2
  6. "Semi final", --3
  7. "Final", --4
  8. }
  9. stages = {3,5,7,15,9}
  10. h = Instance.new("Hint",workspace)
  11. tourneytext = "Sword Tournament"
  12. h.Text = tourneytext
  13. round = 1
  14. bluedeaths = 0
  15. reddeaths = 0
  16.  
  17. function isAdmin(name)
  18.     for _,v in pairs(admins) do
  19.         if name:lower() == v:lower() then
  20.             return true
  21.         end
  22.     end
  23. end
  24.  
  25. function getTeam(name)
  26.     local t = 1
  27.     for _,v in pairs(teams) do
  28.         print("name:",name,"taking:",v[1])
  29.         if v[1]:sub(1,name:len()):lower() == name:lower() then
  30.             print("sub:",v[1]:sub(1,name:len()))
  31.             t = t == 1 and v or 2
  32.         end
  33.     end
  34.     if t ~= 1 and t ~= 2 then
  35.         print("team found")
  36.         return t
  37.     else
  38.         return nil
  39.     end
  40. end
  41.  
  42. function addTeam(team,player1,player2,player3,name)
  43.     if team then
  44.         table.insert(teams,team)
  45.     else
  46.         local t = {name,player1,player2,player3}
  47.         table.insert(teams,t)
  48.     end
  49.     print("Team",name,"added")
  50. end
  51.  
  52. function blueDied()
  53.     bluedeaths = bluedeaths + 1
  54. end
  55.  
  56. function redDied()
  57.     reddeaths = reddeaths + 1
  58. end
  59.  
  60. function onChatted(msg, rec,speaker)
  61.     --/add player1 player2 player3
  62.     if msg:lower():sub(1,4) == "/add" then
  63.         print("ADMIN SAID /ADD")
  64.         local n = 6
  65.         local name = ""
  66.         local team = {}
  67.         local success = true
  68.         local space1
  69.         local space2
  70.         local space3
  71.         for i = n,500 do
  72.             n = i
  73.             if i > msg:len() then success = false break end
  74.             if msg:sub(i,i) == " " then
  75.                 space1 = i
  76.                 break
  77.             end
  78.         end
  79.         for i = n+1,500 do
  80.             n = i
  81.             if i > msg:len() then success = false break end
  82.             if msg:sub(i,i) == " " then
  83.                 space2 = i
  84.                 break
  85.             end
  86.         end
  87.         for i = n+1,500 do
  88.             n = i
  89.             if i > msg:len() then success = false break end
  90.             if msg:sub(i,i) == " " then
  91.                 space3 = i
  92.                 break
  93.             end
  94.         end
  95.         if success then
  96.             print("space numbers:",space1,space2,space3)
  97.             print(msg:sub(6,space1),msg:sub(space1,space2),msg:sub(space2,space3),msg:sub(space3))
  98.             addTeam(nil,msg:sub(6,space1),msg:sub(space1,space2),msg:sub(space2,space3),msg:sub(space3))
  99.         end
  100.     elseif msg:lower() == "/showteams" then
  101.         print("showteams")
  102.         local m = Instance.new("Message",speaker.PlayerGui)
  103.         print("message created")
  104.         for _,v in pairs(teams) do
  105.             m.Text = table.concat(v,", ")
  106.             print(table.concat(v," "))
  107.             wait(4)
  108.         end
  109.         m:remove()
  110.         print("message removed")
  111.     elseif msg:sub(1,5) == "/duel" then
  112.         print("ADMIN SAID /DUEL!!!")
  113.         local n
  114.         for i=6,500 do
  115.             if msg:sub(i,i) == "/" then
  116.                 n = i
  117.                 break
  118.             end
  119.         end
  120.         local team1 = getTeam(msg:sub(6,n))
  121.         local team2 = getTeam(msg:sub(n))
  122.         if team1 and team2 then
  123.             --create player variables
  124.             local sr = 0
  125.             local r1 = game.Players[team1[2]]
  126.             local r2 = game.Players[team1[3]]
  127.             local r3 = game.Players[team1[4]]
  128.             local rname = team1[1]
  129.             local sb = 0
  130.             local b1 = game.Players[team2[2]]
  131.             local b2 = game.Players[team2[3]]
  132.             local b3 = game.Players[team2[4]]
  133.             local bname = team2[1]
  134.             if r1 and r2 and r3 and b1 and b2 and b3 then
  135.                 while sr < (rounds[round]+1)/2 and sb < (rounds[round]+1)/2 do
  136.                     local scoretext = rname.." - Red: "..sr.." | "..bname.." - Blue: "..sb.." (Best of "..rounds[round]..")"
  137.                     h.Text = scoretext
  138.  
  139.                     --colour characters
  140.                     b1.Torso.BrickColor = BrickColor.new("Bright blue")
  141.                     b2.Torso.BrickColor = BrickColor.new("Bright blue")
  142.                     b3.Torso.BrickColor = BrickColor.new("Bright blue")
  143.  
  144.                     r1.Torso.BrickColor = BrickColor.new("Bright red")
  145.                     r2.Torso.BrickColor = BrickColor.new("Bright red")
  146.                     r3.Torso.BrickColor = BrickColor.new("Bright red")
  147.  
  148.                     --teleport characters
  149.                     r1:TranslateBy(script.Parent.RedBase.comb1.Position - r1:GetCFrame().p)
  150.                     r2:TranslateBy(script.Parent.RedBase.comb2.Position - r2:GetCFrame().p)
  151.                     r3:TranslateBy(script.Parent.RedBase.comb3.Position - r3:GetCFrame().p)
  152.                    
  153.                     b1:TranslateBy(script.Parent.BlueBase.comb1.Position - b1:GetCFrame().p)
  154.                     b2:TranslateBy(script.Parent.BlueBase.comb2.Position - b2:GetCFrame().p)
  155.                     b3:TranslateBy(script.Parent.BlueBase.comb3.Position - b3:GetCFrame().p)
  156.  
  157.                     --give swords
  158.                     local sword = game.Lighting.LinkedSword
  159.                     sword:clone().Parent = r1
  160.                     sword:clone().Parent = r2
  161.                     sword:clone().Parent = r3
  162.                     sword:clone().Parent = b1
  163.                     sword:clone().Parent = b2
  164.                     sword:clone().Parent = b3
  165.  
  166.                     --register on death
  167.                     local con1 = r1.Humanoid.Died:connect(redDied)
  168.                     local con2 = r2.Humanoid.Died:connect(redDied)
  169.                     local con3 = r3.Humanoid.Died:connect(redDied)
  170.  
  171.                     local con4 = b1.Humanoid.Died:connect(blueDied)
  172.                     local con5 = b2.Humanoid.Died:connect(blueDied)
  173.                     local con6 = b3.Humanoid.Died:connect(blueDied)
  174.  
  175.                     --wait until a team loses
  176.                     repeat wait() until bluedeaths == 3 or reddeaths == 3
  177.                     local mtext = ""
  178.                     if bluedeaths == 3 and reddeaths ~= 3 then
  179.                         mtext = bname.." (Blue) won the duel."
  180.                         bs = bs + 1
  181.                     elseif reddeaths == 3 and bluedeaths ~= 3 then
  182.                         mtext = rname.." (Red) won the duel."
  183.                         rs = rs + 1
  184.                     else
  185.                         mtext = "There was a tie! There must be a rematch."
  186.                     end
  187.  
  188.                     local scoretext = rname.." - Red: "..sr.." | "..bname.." - Blue: "..sb.." (Best of "..rounds[round]..")"
  189.                     h.Text = scoretext
  190.    
  191.                     local ms = Instance.new("Message",workspace)
  192.                     m.Text = mtext
  193.                     wait(5)
  194.                     ms:remove()
  195.  
  196.                     con1:disconnect()
  197.                     con2:disconnect()
  198.                     con3:disconnect()
  199.                     con4:disconnect()
  200.                     con5:disconnect()
  201.                     con6:disconnect()
  202.  
  203.                     bluedeaths = 0
  204.                     reddeaths = 0
  205.                 end
  206.                 if sb > sr then
  207.                     local ms = Instance.new("Message",workspace)
  208.                     ms.Text = bname.." won this round in the "..tourneytext.."!"
  209.                     wait(4)
  210.                     ms:remove()
  211.                     b1.Humanoid.Health = 0
  212.                     b2.Humanoid.Health = 0
  213.                     b3.Humanoid.Health = 0
  214.                 elseif sr > sb then
  215.                     local ms = Instance.new("Message",workspace)
  216.                     ms.Text = rname.." won this round in the "..tourneytext.."!"
  217.                     wait(4)
  218.                     ms:remove()
  219.                     r1.Humanoid.Health = 0
  220.                     r2.Humanoid.Health = 0
  221.                     r3.Humanoid.Health = 0
  222.                 end
  223.                 h.Text = tourneytext
  224.             else
  225.                 local m = Instance.new("Message",workspace)
  226.                 m.Text = "Player missing! Maybe he left, or the name was typed into the team incorrectly!"
  227.                 wait(4)
  228.                 m:remove()
  229.             end
  230.         else
  231.             print("Team is nil! It may be ambiguous!")
  232.             local m = Instance.new("Message",speaker.PlayerGui)
  233.             m.Text = "Team is nil! It may be ambiguous!"
  234.             wait(3)
  235.             m:remove()
  236.         end
  237.     elseif msg:sub(1,8):lower() == "/tourney" then
  238.         local m = msg:sub(9)
  239.         if m then
  240.             tourneytext = m
  241.             h.Text = tourneytext
  242.         end
  243.     elseif msg:sub(1,6):lower() == "/round" then
  244.         local m = tonumber(msg:sub(7))
  245.         if m then
  246.             round = m
  247.         end
  248.     elseif msg:sub(1,8):lower() == "/getteam" then
  249.         local m = msg:sub(9)
  250.         if m then
  251.             local t = getTeam(m)
  252.             if t then
  253.                 local h = Instance.new("Message",speaker.PlayerGui)
  254.                 h.Text = table.concat(t," ")
  255.                 wait(4)
  256.                 h:remove()
  257.             end
  258.         end
  259.     end
  260. end
  261.  
  262. game.Players.PlayerAdded:connect(function(player)
  263.     if isAdmin(player.Name) then
  264.         print("PLAYER ISH ADMIN")
  265.         player.Chatted:connect(function(msg,r) onChatted(msg,r,player) end)
  266.     end
  267. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement