Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --by tayapi1
- --CONFIG
- local captureSpeed = 5
- ----------
- local iterate = table.foreach
- local cmdPosts = setmetatable({}, {
- __call = function(self, action, ...)
- local args = {...}
- if rawequal(action, "initCommandPost") then
- rawset(self, args[1], setmetatable({callSign = args[1]; ownedBy = nil; basePart = args[2]; captureProgress = 0; capturing = false; securing = false; contesting = false}, {
- __call = function(self, action, ...)
- local args = {...}
- if rawequal(action, "setProgress") then
- rawset(self, "captureProgress", args[1])
- elseif rawequal(action, "incrementProgress") then
- rawset(self, "captureProgress", rawget(self, "captureProgress") + args[1])
- if rawget(self, "captureProgress") >= 100 then
- rawset(self, "captureProgress", 0)
- return true
- elseif rawget(self, "captureProgress") < 0 then
- rawset(self, "captureProgress", 0)
- end
- elseif rawequal(action, "toggleCapture") then
- rawset(self, "capturing", args[1])
- if args[1] then
- if rawequal(rawget(self, "securing"), true) then
- rawset(self, "contesting", true)
- else
- rawset(self, "contesting", false)
- end
- end
- elseif rawequal(action, "toggleSecure") then
- rawset(self, "securing", args[1])
- if args[1] then
- if rawequal(rawget(self, "capturing"), true) then
- rawset(self, "contesting", true)
- else
- rawset(self, "contesting", false)
- end
- end
- end
- end
- }))
- end
- end
- })
- local function playersNearCheck(basePart)
- local inRange = {}
- iterate(game.Players:GetChildren(), function(index, player)
- if player.Character and player.Character.PrimaryPart then
- if (basePart.Position - player.Character.PrimaryPart.Position).magnitude < 50 then
- rawset(inRange, player, player.Team)
- end
- end
- end)
- return inRange
- end
- spawn(function() -- seperate thread
- while wait(.8) do -- main controller loop, edit refresh rate here
- iterate(cmdPosts, function(callSign, cmdPost)
- local players = playersNearCheck(rawget(cmdPost, "basePart"))
- if not rawequal(players, {}) then
- local invader, defender
- iterate(players, function(player, team)
- if rawequal(team, rawget(cmdPost,"ownedBy")) then
- defender = true
- else
- invader = team
- end
- end)
- if invader then
- cmdPost("toggleCapture", true)
- else
- cmdPost("toggleCapture", false)
- end
- if defender then
- cmdPost("toggleSecure", true)
- else
- cmdPost("toggleSecure", false)
- end
- if (rawequal(rawget(cmdPost, "capturing"), true) or rawequal(rawget(cmdPost, "securing"), true)) and rawequal(rawget(cmdPost, "contesting"), false) then
- local value = captureSpeed
- if rawequal(rawget(cmdPost, "securing"), true) then value = -captureSpeed end
- local captured = cmdPost("incrementProgress", value)
- if captured and invader then
- rawset(cmdPost, "ownedBy", invader)
- end
- end
- else
- cmdPost("toggleCapture", false)
- cmdPost("toggleSecure", false)
- end
- end)
- end
- end)
- cmdPosts("initCommandPost", "Alpha", workspace.Posts.AlphaPart)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement