Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.40 KB | None | 0 0
  1. local event = workspace.OfficialEvent -- this is the event to communicate between scripts
  2. local guievent = workspace.GUIEvent -- this even to communicate with GUIs
  3. local ucrtimer = workspace.UCREvent
  4. local raidertimer = workspace.RaiderEvent
  5. local objectiveevent = workspace.ObjectiveEvent
  6. local officialevent = workspace.Official
  7. local message = workspace.MessageToPlayers -- there is a script in a textlabel in a screengui, which receives the events
  8. local PointsService = game:GetService("PointsService")
  9.  
  10. if(game.Workspace:findFirstChild("TimeMessage")~=nil) then -- just removing waste
  11. game.Workspace.TimeMessage:Destroy()
  12. end
  13. if(game.Workspace:findFirstChild("WinMessage")~=nil) then
  14. game.Workspace.WinMessage:Destroy()
  15. end
  16.  
  17. --print("Flag Tester Loaded.")
  18.  
  19. --// All the flags. 0 means DEFENDER holds it, 1 means ATTACKER holds it.
  20. flags =
  21. {
  22. [script.Parent:findFirstChild("Main Island")] = 0,
  23. [script.Parent:findFirstChild("UCR Island")] = 0,
  24. [script.Parent:findFirstChild("Raider Island")] = 0,
  25. [script.Parent:findFirstChild("Middle Island")] = 0
  26. }
  27.  
  28. --h = Instance.new("Hint",workspace)
  29. --h.Name = "TimeMessage"
  30. m = Instance.new("Message",workspace)
  31. m.Name = "WinMessage"
  32.  
  33. control = 0 -- 0 means raiders have no flags, 1 means one, etc. You have to have 2 flags to be gaining points
  34. dwintime = 4000 -- 1 and a half hours (90 minutes)
  35. rwintime = 1700 -- 30 minutes
  36. time = 0 -- raider timer, i.e. time with 2+ flags
  37. elapsed = 0 -- defender timer, i.e. total time for game
  38. ENDGAME = false -- basically if win conditions are met it stops the script
  39. numraiders = 0 -- number of raiders
  40. numdefenders = 0 -- number of defenders (ally + us)
  41. raidstarted = false
  42. count = 0
  43.  
  44. function Update(cond)
  45.     if cond == 0 then
  46.         ucrtimer:Fire(elapsed)
  47.         raidertimer:Fire(time)
  48.     elseif cond == 1 then
  49.         ENDGAME = true
  50.         for i,v in pairs(game.Players:GetChildren()) do
  51.             if v.TeamColor == game.Teams.Whites.TeamColor then
  52.                 v.leaderstats.Cash.Value = v.leaderstats.Cash.Value+2500
  53.                 PointsService:AwardPoints(v.userId, 2500)
  54.             end
  55.         end
  56.         m.Text = ("Whites have successfully raided ORIION!")
  57.         wait(15)
  58.         time = 0
  59.         elapsed = 0
  60.         ENDGAME = false
  61.         raidstarted = false
  62.         --kickRaiders()
  63.         wait(10)
  64.     elseif cond == 2 then
  65.         ENDGAME = true
  66.         for i,v in pairs(game.Players:GetChildren()) do
  67.             if v.TeamColor == game.Teams.Reds.TeamColor then
  68.                 v.leaderstats.Cash.Value = v.leaderstats.Cash.Value+2500
  69.                 PointsService:AwardPoints(v.userId, 2500)
  70.             end
  71.         end
  72.         m.Text = ("Reds have successfully defended ORIION!")
  73.         wait(15)
  74.         time = 0
  75.         elapsed = 0
  76.         ENDGAME = false
  77.         raidstarted = false
  78.         m.Text = ""
  79.         --kickRaiders()
  80.         wait(10)
  81.     end
  82. end
  83.  
  84. function kickRaiders()
  85.     for i,v in pairs(game.Players:GetChildren()) do
  86.         if v.TeamColor == game.Teams.Raiders.TeamColor then
  87.             script.LocalScript:Clone().Parent = v
  88.         end
  89.     end
  90. end
  91.  
  92. for key, value in pairs(flags) do
  93.     --print("hiiii")
  94.     key.CurrentOwner.Changed:connect(function(owner)
  95.         if (owner == BrickColor.New("Bright red")) and value == 1 then
  96.             control = control - 1
  97.             value = 0
  98.         elseif (owner == BrickColor.new("Bright green")) and value == 1 then
  99.             control = control - 1
  100.             value = 0
  101.         elseif (owner == BrickColor.White()) and value == 0 then
  102.             control = control + 1
  103.             value = 1
  104.         end
  105.     end)
  106. end
  107. repeat wait(1) until #(game.Players:GetChildren())>0
  108.  
  109. while wait(1) do
  110.    
  111. while ENDGAME == false do
  112.     --wait(1)
  113.     numraiders = 0 -- initalizes at 0
  114.     numdefenders = 0 -- initalizes at 0
  115.  
  116.     if not raidstarted then
  117.         for i,v in pairs(game.Players:GetChildren()) do
  118.             if v.TeamColor == BrickColor.White() then
  119.                 numraiders = numraiders + 1 -- if there is an enemy, increase # of enemies
  120.             elseif (v.TeamColor == BrickColor.new("Bright green") or v.TeamColor == BrickColor.new("Bright red")) then
  121.                 numdefenders = numdefenders + 1 -- if there is a defender, increase # of defenders
  122.             end
  123.         end
  124.         if (numdefenders >= 2 and numraiders >= 2) then -- checks for required numbers of enemies and defenders
  125.             message:Fire("RAID IS OFFICIAL")
  126.             officialevent:Fire(1)
  127.             wait(10)
  128.             raidstarted = true     
  129.         end
  130.     else
  131.         count = count + 1
  132.         if count>20 then
  133.             count = 0
  134.             for i,v in pairs(game.Players:GetChildren()) do
  135.                 if v.TeamColor == BrickColor.White() then
  136.                     numraiders = numraiders + 1 -- if there is an enemy, increase # of enemies
  137.                 elseif (v.TeamColor == BrickColor.new("Bright green") or v.TeamColor == BrickColor.new("Bright red")) then
  138.                     numdefenders = numdefenders + 1 -- if there is a defender, increase # of defenders
  139.                 end
  140.             end
  141.             if (numdefenders < 2 or numraiders < 2) then -- checks for required numbers of enemies and defenders
  142.                 message:Fire("RAID PAUSED. TOO FEW REDS OR WHITES")
  143.                 officialevent:Fire(2)
  144.                 wait(10)
  145.                 raidstarted = false
  146.             end
  147.         end
  148.         elapsed = elapsed + 1
  149.         if control == 0 then -- If the raiders have no flags
  150.             if time > 1 then -- the raid timer will decrease by 2
  151.                 time = time - 2
  152.             elseif time > 0 then
  153.                 time = time - 1 -- this is here so it doesn't go into the negatives accidentally
  154.             end
  155.         elseif control >= 2 then -- If the raiders have 2 or more flags
  156.             time = time + 1 -- the raid timer will go up by 1
  157.         end
  158.         Update(0) -- updates hint at the top of the screen 
  159.     end
  160.  
  161.    
  162.     if ((elapsed == dwintime) or (((elapsed + rwintime) - time) > dwintime)) then Update(2) -- defender win
  163.     elseif time == rwintime then Update(1) -- raider win
  164.     end
  165. end
  166. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement