1x_Gacha

Prison Command | Server | Explained

Sep 11th, 2020 (edited)
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.94 KB | None | 0 0
  1. local log = {} -- Logs, contains all the Prison Commands Used..
  2.  
  3. local cd = {} -- Players on CoolDown
  4.  
  5. local i = 1
  6.  
  7. local testing = false -- Bool
  8. local cooldown = 1 -- CoolDown Length
  9.  
  10. local ids = {} -- IDs
  11. local ids2 = {} -- IDs
  12. local bypass = {} -- Bypass
  13. local tester = {} -- Testers
  14. local folder = script.Resources -- Folder which contains the necessary resources.
  15. local storage = game:GetService('ReplicatedStorage') -- Replicated Storage
  16. local arrestFolder = storage:FindFirstChild('ArrestFolder') -- ArrestFolder which holds all the Arrest Tags.
  17.  
  18.  
  19.  
  20.  
  21. local function checkPlayer(player) -- Check if the Player is eligible to use the Prison Command
  22.     local p = game.Players:FindFirstChild(player) -- Player Instance (Sloppy, really, since we already have the Player...)
  23.     for _,v in pairs(ids)do -- In Pairs...
  24.         if p:IsInGroup(v) then -- If they are in the Group then...
  25.             if p:GetRankInGroup(v) >= 3 then -- Get their Rank in the group, is over.. rank 3 then...
  26.                 return true --  Return true
  27.             end
  28.         else -- Otherwise
  29.             for _,d in pairs(bypass)do -- Get pairs.. in Bypass...
  30.                 if d == p.UserId then -- If their UserId is in the Bypass then...
  31.                     return true -- Return true
  32.                 end
  33.             end
  34.         end
  35.     end
  36.     for _,v in pairs(ids2)do -- Get Pairs
  37.         if p:IsInGroup(v)then -- If they are in theGroup then...
  38.             if p:GetRankInGroup(v) >= 14 then -- If their Rank in the Group is Over... rank 14 then...
  39.                 return true -- Return true
  40.             end
  41.         end
  42.     end
  43.     if testing then -- If Testing is True then...
  44.         for _,v in pairs(tester)do -- In Pairs...
  45.             if v == p.UserId then -- If the Player is a Tester then...
  46.                 return true -- Return True
  47.             end
  48.         end
  49.     end
  50. end
  51.  
  52. local function findPrisonedPlayer(target) -- Find the Prisoned Player.
  53.     for _,v in pairs(arrestFolder:GetChildren())do -- Get Children of Arrest Folder in Pairs
  54.        
  55.         if string.match(v.Name:sub(1, target:len()):lower(), (target:lower()))then -- If Target name is equal to a child then
  56.             print('Unjailing Player: '..v.Name)
  57.             return v.Name -- Return Child Name.
  58.         end
  59.     end
  60. end
  61.  
  62. local function findPlayer(target) -- Find Target
  63.     for _, players in pairs(game.Players:GetChildren()) do -- For Pairs.. (Would have been better to use :GetPlayers() honestly )
  64.        
  65.     if string.match(players.Name:sub(1, target:len()):lower(), (target:lower())) then -- If their name matches the target then
  66.             print('Found Player: '..players.Name)
  67.             return players -- Return the Player Instance
  68.         end
  69.     end
  70. end
  71.  
  72. local function checkCD(sender) -- Check if the Player who is invoking the Command is on CoolDown
  73.     for i,v in pairs(cd)do
  74.         for a,b in pairs(v)do
  75.         if b == sender then
  76.             return true -- If so return true
  77.             end
  78.         end
  79.     end
  80. end
  81.  
  82. local function unjailPlayer(player) -- Unjail Player
  83.     local tag = arrestFolder:FindFirstChild(player) -- Find the Prisoned Players Tag
  84.    
  85.     tag:Destroy() -- Destroy the Tag
  86. end
  87.  
  88. local function jailPlayer(player, duration, reason, sender, team) -- Jail the Player
  89.     if arrestFolder:FindFirstChild(player) then return end -- If the Player is already in prison then... return
  90.     if checkPlayer(player) then return end -- If the Player can use the Prison System then... return
  91.     if checkCD(sender) then return end -- If the Player is on CoolDown then... return
  92.     local tag = folder.PName:Clone() -- Clone the Tag
  93.     log[#log+1] = { -- Create a Log
  94.                 ['Player'] = player,   
  95.                 ['Duration'] = duration,
  96.                 ['Reason'] = reason,
  97.                 ['Sender'] = sender,
  98.                 ['Team'] = team
  99.     }
  100.    
  101.     cd[#cd+1] = { -- Create a Cooldown
  102.             ['Player'] = sender,
  103.             ['CoolDown'] = cooldown,
  104.         }
  105.     -- Setting the Target! --
  106.  
  107.     tag.Name = player
  108.     tag.Value = player
  109.     tag.Reason.Value = reason
  110.     tag.Time.Value = duration*60
  111.     tag.Sentence.Value = duration*60
  112.     tag.Parent = arrestFolder
  113.     tag.Team.Value = team
  114.     tag.Sender.Value = sender
  115.        
  116.     game.Players[player].Team = game.Teams.Prison -- Team the Target Prison Team
  117.     game.Players[player]:LoadCharacter() -- Respawn the Target
  118.    
  119. end
  120.  
  121. local cmd1 = ';jail ' -- Commands
  122. local cmd2 = ';unjail ' -- Commands
  123. local cmd3 = ';plog' -- Commands (Incomplete; Was going to send a list of the Logs. )
  124.  
  125. local function checkCommand(msg, sender) -- Check the Command.
  126.     if msg:sub(1, cmd1:len()):lower()== cmd1:lower() then -- If the Command the player called is equal to... then..
  127.     local mainstring = msg:sub(cmd1:len() + 1) -- The players entire string
  128.     local split = string.split(mainstring, ', ') -- Split the Player String
  129.     if split[2] == ' ' or nil then return end -- If the Second Split, which is the Time, is nil then return
  130.     local duration = split[2] -- The Time sentenced
  131.     local playername = split[1] -- The Target
  132.     local reason = split[3] -- The Reason for Imprisoning the Player.
  133.     local findplayer = findPlayer(playername) -- Find the Target
  134.     local player = game.Players:FindFirstChild(findplayer.Name) -- Find the Target Player Instance
  135.     local team = game.Players:FindFirstChild(findplayer.Name).Team.Name -- Find the Target Players Team
  136.     jailPlayer(player.Name, duration, reason, sender.Name, team) -- Jail the Target
  137.     end
  138.    
  139.     if msg:sub(1, cmd2:len()):lower() == cmd2:lower() then -- If the Command the player called is ... then....
  140.         local playername = msg:sub(cmd2:len() + 1) -- The Target
  141.         local playertag = findPrisonedPlayer(playername) -- The Target Tag
  142.         unjailPlayer(playertag) -- Unjail the Player
  143.     end
  144.    
  145.     if msg:sub(1, cmd3:len()):lower()== cmd3:lower() then -- Incomplete Log
  146.        
  147.     end
  148. end
  149.  
  150. local function inGame(player) -- Check if the Player is in Game
  151.     if game.Players:FindFirstChild(player)then
  152.         return true -- If so, then return true
  153.     end
  154. end
  155.  
  156. local function inPrison(player) -- Check if the Player Is In Prison
  157.     if inGame(player) then -- Check if the Player is In Game
  158.     local prisonarea = game.Workspace.PrisonAreas.PrisonArea -- Find the Prison Center.
  159.     local char = game.Workspace:FindFirstChild(player) -- Find the Prisoned Players Character
  160.     if (char.HumanoidRootPart.Position - prisonarea.Position).Magnitude < 55 then -- If they are within 55 studs from the Center
  161.         return true -- Then Return true
  162.         end
  163.     end
  164. end
  165.  
  166. local ui = script.Arrest -- Arrest Gui
  167.  
  168. game.Players.PlayerAdded:Connect(function(player) -- Player Joined
  169.     repeat wait() -- Wait until the Player Character has been added
  170.        
  171.     until player.Character
  172.    
  173.     if checkPlayer(player.Name) then -- If the Player is whitelisted then...
  174.         local clone = ui:Clone() -- Clone the Gui
  175.         clone.Parent = player.PlayerGui -- Parent it into the Player
  176.         player.Chatted:Connect(function(msg) -- When the Player Talks
  177.         checkCommand(msg, player) -- Check for Command
  178.         end)
  179.     end
  180.    
  181.     if arrestFolder:FindFirstChild(player.Name) then -- If the Player who joined is still serving their sentence then...
  182.         player.Team = game.Teams.Prison -- Team the Prisoned Player.
  183.         player:LoadCharacter() -- Respawn the Player
  184.     end
  185.        
  186. end)
  187.  
  188. -- Deduct the Players Time and Unjail if finished.
  189. spawn(function() -- Spawn Function; Would have been better to use Coroutine instead
  190. while true do
  191.     wait(1)
  192.     for i,v in pairs(arrestFolder:GetChildren())do
  193.         v.Time.Value = v.Time.Value-1
  194.         if v.Time.Value == 0 then
  195.             unjailPlayer(v.Name)
  196.             v:Destroy()
  197.             end
  198.         end
  199.     end
  200. end)
  201.  
  202.  
  203.  
  204. -- Check if the Player is still within the Area, and if a player is in prison without a tag, re-team and respawn.
  205. spawn(function()
  206. while true do
  207.     wait(5)
  208.     for i,v in pairs(game.Players:GetChildren())do
  209.         if arrestFolder:FindFirstChild(v.Name)then
  210.             if v.Team == game.Teams.Prison then
  211.             else
  212.                 v.Team = game.Teams.Prison
  213.                 v:LoadCharacter()
  214.             end
  215.         else
  216.             if v.Team == game.Teams.Prison then
  217.                 if v:IsInGroup(5425370)then
  218.                     v.Team = game.Teams.GCR
  219.                 else
  220.                     v.Team = game.Teams.Civilians
  221.                 end
  222.                     v:LoadCharacter()
  223.                 end
  224.             end
  225.         end
  226.     end
  227. end)
  228.  
  229.  
  230. -- Deduct CoolDown.
  231. spawn(function()
  232.     while true do
  233.         wait(1)
  234.         for i,v in pairs(cd)do
  235.             for a,b in pairs(v)do
  236.                 if a == 'CoolDown' then
  237.                     cd[i][a] = b-1 
  238.                     if b == 0 then
  239.                         table.remove(cd, i)
  240.                     end
  241.                 end
  242.             end
  243.         end
  244.     end
  245. end)
  246.  
  247. -- Check if the Player is within the prison area, if not, then check if they are in game. If so then respawn the character.
  248. spawn(function()
  249.     while true do
  250.         wait(2.5)
  251.         for i,v in pairs(arrestFolder:GetChildren())do
  252.             local plyr = v.Name
  253.             if inPrison(v.Name) then
  254.        
  255.             else
  256.                 if inGame(v.Name) then
  257.                     local player = game.Players:FindFirstChild(v.Name)
  258.                     player:LoadCharacter()
  259.                 end
  260.             end
  261.         end
  262.     end
  263. end)
  264.  
  265. -- 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.
  266.  
  267. game.ReplicatedStorage.ArrestFolder.ChildAdded:Connect(function(tag)
  268.     wait(5)
  269.     local ff = false
  270.     for i,v in pairs(log)do
  271.         if tag.Name == log[i]['Player'] then
  272.             if tag.Reason.Value == log[i]['Reason'] then
  273.                 if tag.Sender.Value == log[i]['Sender'] then
  274.                     ff = true
  275.                     warn('True Prison')
  276.                 end
  277.             end
  278.         end
  279.     end
  280.     if ff == false then
  281.         warn('False Prison')
  282.         tag:Destroy()
  283.     end
  284. end)
Advertisement
Add Comment
Please, Sign In to add comment