Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. --by tayapi1
  2.  
  3. --CONFIG
  4. local captureSpeed = 5
  5.  
  6. ----------
  7. local iterate = table.foreach
  8.  
  9. local cmdPosts = setmetatable({}, {
  10. __call = function(self, action, ...)
  11. local args = {...}
  12. if rawequal(action, "initCommandPost") then
  13. rawset(self, args[1], setmetatable({callSign = args[1]; ownedBy = nil; basePart = args[2]; captureProgress = 0; capturing = false; securing = false; contesting = false}, {
  14. __call = function(self, action, ...)
  15. local args = {...}
  16. if rawequal(action, "setProgress") then
  17. rawset(self, "captureProgress", args[1])
  18. elseif rawequal(action, "incrementProgress") then
  19. rawset(self, "captureProgress", rawget(self, "captureProgress") + args[1])
  20. if rawget(self, "captureProgress") >= 100 then
  21. rawset(self, "captureProgress", 0)
  22. return true
  23. elseif rawget(self, "captureProgress") < 0 then
  24. rawset(self, "captureProgress", 0)
  25. end
  26. elseif rawequal(action, "toggleCapture") then
  27. rawset(self, "capturing", args[1])
  28. if args[1] then
  29. if rawequal(rawget(self, "securing"), true) then
  30. rawset(self, "contesting", true)
  31. else
  32. rawset(self, "contesting", false)
  33. end
  34. end
  35. elseif rawequal(action, "toggleSecure") then
  36. rawset(self, "securing", args[1])
  37. if args[1] then
  38. if rawequal(rawget(self, "capturing"), true) then
  39. rawset(self, "contesting", true)
  40. else
  41. rawset(self, "contesting", false)
  42. end
  43. end
  44. end
  45. end
  46. }))
  47. end
  48. end
  49.  
  50. })
  51.  
  52. local function playersNearCheck(basePart)
  53. local inRange = {}
  54. iterate(game.Players:GetChildren(), function(index, player)
  55. if player.Character and player.Character.PrimaryPart then
  56. if (basePart.Position - player.Character.PrimaryPart.Position).magnitude < 50 then
  57. rawset(inRange, player, player.Team)
  58. end
  59. end
  60. end)
  61. return inRange
  62. end
  63.  
  64. spawn(function() -- seperate thread
  65. while wait(.8) do -- main controller loop, edit refresh rate here
  66. iterate(cmdPosts, function(callSign, cmdPost)
  67. local players = playersNearCheck(rawget(cmdPost, "basePart"))
  68. if not rawequal(players, {}) then
  69. local invader, defender
  70. iterate(players, function(player, team)
  71. if rawequal(team, rawget(cmdPost,"ownedBy")) then
  72. defender = true
  73. else
  74. invader = team
  75. end
  76. end)
  77. if invader then
  78. cmdPost("toggleCapture", true)
  79. else
  80. cmdPost("toggleCapture", false)
  81. end
  82. if defender then
  83. cmdPost("toggleSecure", true)
  84. else
  85. cmdPost("toggleSecure", false)
  86. end
  87. if (rawequal(rawget(cmdPost, "capturing"), true) or rawequal(rawget(cmdPost, "securing"), true)) and rawequal(rawget(cmdPost, "contesting"), false) then
  88. local value = captureSpeed
  89. if rawequal(rawget(cmdPost, "securing"), true) then value = -captureSpeed end
  90. local captured = cmdPost("incrementProgress", value)
  91. if captured and invader then
  92. rawset(cmdPost, "ownedBy", invader)
  93. end
  94. end
  95. else
  96. cmdPost("toggleCapture", false)
  97. cmdPost("toggleSecure", false)
  98. end
  99. end)
  100. end
  101. end)
  102.  
  103. cmdPosts("initCommandPost", "Alpha", workspace.Posts.AlphaPart)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement