Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local log = {} -- Logs, contains all the Prison Commands Used..
- local cd = {} -- Players on CoolDown
- local i = 1
- local testing = false -- Bool
- local cooldown = 1 -- CoolDown Length
- local ids = {} -- IDs
- local ids2 = {} -- IDs
- local bypass = {} -- Bypass
- local tester = {} -- Testers
- local folder = script.Resources -- Folder which contains the necessary resources.
- local storage = game:GetService('ReplicatedStorage') -- Replicated Storage
- local arrestFolder = storage:FindFirstChild('ArrestFolder') -- ArrestFolder which holds all the Arrest Tags.
- local function checkPlayer(player) -- Check if the Player is eligible to use the Prison Command
- local p = game.Players:FindFirstChild(player) -- Player Instance (Sloppy, really, since we already have the Player...)
- for _,v in pairs(ids)do -- In Pairs...
- if p:IsInGroup(v) then -- If they are in the Group then...
- if p:GetRankInGroup(v) >= 3 then -- Get their Rank in the group, is over.. rank 3 then...
- return true -- Return true
- end
- else -- Otherwise
- for _,d in pairs(bypass)do -- Get pairs.. in Bypass...
- if d == p.UserId then -- If their UserId is in the Bypass then...
- return true -- Return true
- end
- end
- end
- end
- for _,v in pairs(ids2)do -- Get Pairs
- if p:IsInGroup(v)then -- If they are in theGroup then...
- if p:GetRankInGroup(v) >= 14 then -- If their Rank in the Group is Over... rank 14 then...
- return true -- Return true
- end
- end
- end
- if testing then -- If Testing is True then...
- for _,v in pairs(tester)do -- In Pairs...
- if v == p.UserId then -- If the Player is a Tester then...
- return true -- Return True
- end
- end
- end
- end
- local function findPrisonedPlayer(target) -- Find the Prisoned Player.
- for _,v in pairs(arrestFolder:GetChildren())do -- Get Children of Arrest Folder in Pairs
- if string.match(v.Name:sub(1, target:len()):lower(), (target:lower()))then -- If Target name is equal to a child then
- print('Unjailing Player: '..v.Name)
- return v.Name -- Return Child Name.
- end
- end
- end
- local function findPlayer(target) -- Find Target
- for _, players in pairs(game.Players:GetChildren()) do -- For Pairs.. (Would have been better to use :GetPlayers() honestly )
- if string.match(players.Name:sub(1, target:len()):lower(), (target:lower())) then -- If their name matches the target then
- print('Found Player: '..players.Name)
- return players -- Return the Player Instance
- end
- end
- end
- local function checkCD(sender) -- Check if the Player who is invoking the Command is on CoolDown
- for i,v in pairs(cd)do
- for a,b in pairs(v)do
- if b == sender then
- return true -- If so return true
- end
- end
- end
- end
- local function unjailPlayer(player) -- Unjail Player
- local tag = arrestFolder:FindFirstChild(player) -- Find the Prisoned Players Tag
- tag:Destroy() -- Destroy the Tag
- end
- local function jailPlayer(player, duration, reason, sender, team) -- Jail the Player
- if arrestFolder:FindFirstChild(player) then return end -- If the Player is already in prison then... return
- if checkPlayer(player) then return end -- If the Player can use the Prison System then... return
- if checkCD(sender) then return end -- If the Player is on CoolDown then... return
- local tag = folder.PName:Clone() -- Clone the Tag
- log[#log+1] = { -- Create a Log
- ['Player'] = player,
- ['Duration'] = duration,
- ['Reason'] = reason,
- ['Sender'] = sender,
- ['Team'] = team
- }
- cd[#cd+1] = { -- Create a Cooldown
- ['Player'] = sender,
- ['CoolDown'] = cooldown,
- }
- -- Setting the Target! --
- tag.Name = player
- tag.Value = player
- tag.Reason.Value = reason
- tag.Time.Value = duration*60
- tag.Sentence.Value = duration*60
- tag.Parent = arrestFolder
- tag.Team.Value = team
- tag.Sender.Value = sender
- game.Players[player].Team = game.Teams.Prison -- Team the Target Prison Team
- game.Players[player]:LoadCharacter() -- Respawn the Target
- end
- local cmd1 = ';jail ' -- Commands
- local cmd2 = ';unjail ' -- Commands
- local cmd3 = ';plog' -- Commands (Incomplete; Was going to send a list of the Logs. )
- local function checkCommand(msg, sender) -- Check the Command.
- if msg:sub(1, cmd1:len()):lower()== cmd1:lower() then -- If the Command the player called is equal to... then..
- local mainstring = msg:sub(cmd1:len() + 1) -- The players entire string
- local split = string.split(mainstring, ', ') -- Split the Player String
- if split[2] == ' ' or nil then return end -- If the Second Split, which is the Time, is nil then return
- local duration = split[2] -- The Time sentenced
- local playername = split[1] -- The Target
- local reason = split[3] -- The Reason for Imprisoning the Player.
- local findplayer = findPlayer(playername) -- Find the Target
- local player = game.Players:FindFirstChild(findplayer.Name) -- Find the Target Player Instance
- local team = game.Players:FindFirstChild(findplayer.Name).Team.Name -- Find the Target Players Team
- jailPlayer(player.Name, duration, reason, sender.Name, team) -- Jail the Target
- end
- if msg:sub(1, cmd2:len()):lower() == cmd2:lower() then -- If the Command the player called is ... then....
- local playername = msg:sub(cmd2:len() + 1) -- The Target
- local playertag = findPrisonedPlayer(playername) -- The Target Tag
- unjailPlayer(playertag) -- Unjail the Player
- end
- if msg:sub(1, cmd3:len()):lower()== cmd3:lower() then -- Incomplete Log
- end
- end
- local function inGame(player) -- Check if the Player is in Game
- if game.Players:FindFirstChild(player)then
- return true -- If so, then return true
- end
- end
- local function inPrison(player) -- Check if the Player Is In Prison
- if inGame(player) then -- Check if the Player is In Game
- local prisonarea = game.Workspace.PrisonAreas.PrisonArea -- Find the Prison Center.
- local char = game.Workspace:FindFirstChild(player) -- Find the Prisoned Players Character
- if (char.HumanoidRootPart.Position - prisonarea.Position).Magnitude < 55 then -- If they are within 55 studs from the Center
- return true -- Then Return true
- end
- end
- end
- local ui = script.Arrest -- Arrest Gui
- game.Players.PlayerAdded:Connect(function(player) -- Player Joined
- repeat wait() -- Wait until the Player Character has been added
- until player.Character
- if checkPlayer(player.Name) then -- If the Player is whitelisted then...
- local clone = ui:Clone() -- Clone the Gui
- clone.Parent = player.PlayerGui -- Parent it into the Player
- player.Chatted:Connect(function(msg) -- When the Player Talks
- checkCommand(msg, player) -- Check for Command
- end)
- end
- if arrestFolder:FindFirstChild(player.Name) then -- If the Player who joined is still serving their sentence then...
- player.Team = game.Teams.Prison -- Team the Prisoned Player.
- player:LoadCharacter() -- Respawn the Player
- end
- end)
- -- Deduct the Players Time and Unjail if finished.
- spawn(function() -- Spawn Function; Would have been better to use Coroutine instead
- while true do
- wait(1)
- for i,v in pairs(arrestFolder:GetChildren())do
- v.Time.Value = v.Time.Value-1
- if v.Time.Value == 0 then
- unjailPlayer(v.Name)
- v:Destroy()
- end
- end
- end
- end)
- -- Check if the Player is still within the Area, and if a player is in prison without a tag, re-team and respawn.
- spawn(function()
- while true do
- wait(5)
- for i,v in pairs(game.Players:GetChildren())do
- if arrestFolder:FindFirstChild(v.Name)then
- if v.Team == game.Teams.Prison then
- else
- v.Team = game.Teams.Prison
- v:LoadCharacter()
- end
- else
- if v.Team == game.Teams.Prison then
- if v:IsInGroup(5425370)then
- v.Team = game.Teams.GCR
- else
- v.Team = game.Teams.Civilians
- end
- v:LoadCharacter()
- end
- end
- end
- end
- end)
- -- Deduct CoolDown.
- spawn(function()
- while true do
- wait(1)
- for i,v in pairs(cd)do
- for a,b in pairs(v)do
- if a == 'CoolDown' then
- cd[i][a] = b-1
- if b == 0 then
- table.remove(cd, i)
- end
- end
- end
- end
- end
- end)
- -- Check if the Player is within the prison area, if not, then check if they are in game. If so then respawn the character.
- spawn(function()
- while true do
- wait(2.5)
- for i,v in pairs(arrestFolder:GetChildren())do
- local plyr = v.Name
- if inPrison(v.Name) then
- else
- if inGame(v.Name) then
- local player = game.Players:FindFirstChild(v.Name)
- player:LoadCharacter()
- end
- end
- end
- end
- end)
- -- If a tag is added into the Arrest Folder, check if it is a legitimate Prison. If it does not match the Logs then remove and respawn.
- game.ReplicatedStorage.ArrestFolder.ChildAdded:Connect(function(tag)
- wait(5)
- local ff = false
- for i,v in pairs(log)do
- if tag.Name == log[i]['Player'] then
- if tag.Reason.Value == log[i]['Reason'] then
- if tag.Sender.Value == log[i]['Sender'] then
- ff = true
- warn('True Prison')
- end
- end
- end
- end
- if ff == false then
- warn('False Prison')
- tag:Destroy()
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment