Advertisement
Guest User

XanthicDragon's Administrative Commands

a guest
Jun 18th, 2015
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.03 KB | None | 0 0
  1. --[[
  2.     XanthicDragon's admin commands.
  3.     Please administer responsibly.
  4.     You don't have to add yourself to the list to be an admin, it's automatic.
  5.    
  6.     NOTE: Commands in here are easy to customize!
  7.    
  8.     local Commands = {
  9.         ["Cmd"] = {{Usergroup(s)}, "Description", function (plr, ...)
  10.        
  11.         end}
  12.     }
  13.     Where...
  14.         ...Cmd is the command you chat (THIS SHOULD ALWAYS BE LOWERCASE!)
  15.         ...Usergroup(s) is/are the people who can use it (i.e. {"Admins", "Donors"} or {"Admins"} or {"Donors"})
  16.         ...Description is the description of the command (for the commands list)
  17.         ...function (plr, ...) ... end - is the code that runs. - plr is the player that executed the command, ... are the extra arguements
  18.        
  19.     HOW ARGUEMENTS WORK IN COMMANDS:
  20.         function (plr, args)
  21.            
  22.         end
  23.        
  24.     Iterating through args will return each thing they did, so if I do /loopkill me 100...
  25.     ...args[1] will be the string "me"
  26.     ...args[2] will be the number 100
  27.    
  28.     It also works with a list: /kick me,hello,bye:
  29.     args[1] will be "me"
  30.     args[2] will be "hello"
  31.     args[3] will be "bye"
  32.    
  33.     Also:/loopkill me,person 100
  34.     args[1] = me
  35.     args[2] = person
  36.     args[3] = 100
  37.    
  38. --]]
  39.  
  40. local Admins = {}                           --Admins (XanthicDragon will always be admin, you can trust me!)
  41. local Donors = {}                           --People who donate to me get this rank. The commands they use cannot affect the server, so you can also put people in here manually
  42. local Banned = {}                           --Put the names of people you don't want in this list: {"badguy", "badguy2"}
  43. local CommandPrefix = "/"                   --What to put before commands
  44. --------------
  45. --CODE BELOW--
  46. --------------
  47. local b = game:GetService("BadgeService")
  48. local MPS = game:GetService("MarketplaceService")
  49. local IS = game:GetService("InsertService")
  50. --Start with functions for operating the data
  51.  
  52. function ScrollGui() --From Kohl's Admin
  53.     local scr = Instance.new("ScreenGui")
  54.     scr.Name = "SCROLLGUI"
  55.     local drag = Instance.new("TextButton", scr)
  56.     drag.Draggable = true
  57.     drag.BackgroundTransparency = 1
  58.     drag.Size = UDim2.new(1,0,0,20)
  59.     drag.Position = UDim2.new(0,0,.5,-200)
  60.     drag.AutoButtonColor = false
  61.     drag.Text = ""
  62.     drag.ZIndex = 100
  63.     local main = Instance.new("ScrollingFrame", drag)
  64.     main.BackgroundColor3 = Color3.new(0, 0, 0)
  65.     main.BackgroundTransparency = 0.5
  66.     main.Size = UDim2.new(0.98,0,0,400)
  67.     main.Position = UDim2.new(0.01, 0, 0, 0)
  68.     main.CanvasSize = UDim2.new(0, 0, 100, 0)
  69.     main.ZIndex = 7
  70.     main.ClipsDescendants = true
  71.     local cls = Instance.new("TextButton", drag)
  72.     cls.Position = UDim2.new(0, 10, 0, 0)
  73.     cls.Size = UDim2.new(0, 20, 0, 20)
  74.     cls.Style = "RobloxButtonDefault"
  75.     cls.TextColor3 = Color3.new(1, 1, 1)
  76.     cls.ZIndex = 101
  77.     cls.Text = "X"
  78.     script.UIClose:Clone().Parent = cls
  79.     local cmf = Instance.new("Frame", main)
  80.     cmf.Position = UDim2.new(0,0,0,-9)
  81.     cmf.ZIndex = 8
  82.     local ent = Instance.new("TextLabel")
  83.     ent.BackgroundTransparency = 1
  84.     ent.Font = "Arial"
  85.     ent.FontSize = "Size18"
  86.     ent.ZIndex = 8
  87.     ent.Text = ""
  88.     ent.TextColor3 = Color3.new(1,1,1)
  89.     ent.TextStrokeColor3 = Color3.new(0,0,0)
  90.     ent.TextStrokeTransparency = .8
  91.     ent.TextXAlignment = "Left"
  92.     ent.TextYAlignment = "Top"
  93.     local num = 0
  94.    
  95.     return scr, cmf, ent, num
  96. end
  97.  
  98. function GetPlayerFromName(plr, text)
  99.     local text = text:lower()
  100.     if text ~= "me" and text ~= "others" and text ~= "all" then
  101.         for _,v in ipairs(game:GetService("Players"):GetPlayers()) do
  102.             local match = false
  103.             local n = v.Name:lower()
  104.             local t = text
  105.             for i = 1, t:len() do
  106.                 local char1 = n:sub(i, i)
  107.                 local char2 = t:sub(i, i)
  108.                 if char1 == char2 then
  109.                     match = true
  110.                 else
  111.                     match = false
  112.                     break
  113.                 end
  114.             end
  115.             if match then
  116.                 return {v}
  117.             end
  118.         end
  119.     elseif text == "me" then
  120.         return {plr}
  121.     elseif text == "all" then
  122.         return game:GetService("Players"):GetPlayers()
  123.     elseif text == "others" then
  124.         local plrs = {}
  125.         for _,v in ipairs(game:GetService("Players"):GetPlayers()) do
  126.             if v ~= plr then
  127.                 table.insert(plrs, v)
  128.             end
  129.         end
  130.         return plrs
  131.     end
  132.     return nil
  133. end
  134.  
  135. function GetPlayerFromArgs(plr, args)
  136.     local int = {}
  137.     local name = {}
  138.     for _,v in ipairs(args) do
  139.         local len2 = tostring(tonumber(v)):len() --Get length after converting to a number
  140.         local len1 = v:len() --Get length of normal
  141.         --Above checks if it's not a name i.e. abc123. If it's a name, the lengths won't match.
  142.         if len1 == len2 then --Not a name
  143.             table.insert(int, tonumber(v))
  144.         else
  145.             table.insert(name, v)
  146.         end
  147.     end
  148.     local players = {}
  149.     for _,v in ipairs(name) do
  150.         local plrz = GetPlayerFromName(plr, v)
  151.         if plrz then
  152.             local plr = plrz[1]
  153.             table.insert(players, plr)
  154.         end
  155.     end
  156.     return players, int
  157. end
  158.  
  159. function GetMsg(table)
  160.     local t = ""
  161.     for _,v in ipairs(table) do
  162.         t = t .. v
  163.     end
  164.     t = t:sub(3)
  165.     return t
  166. end
  167.  
  168. function Message(plrs, text)
  169.     for _,v in ipairs(plrs) do
  170.         spawn(function ()
  171.             local scr = Instance.new("Message", v.PlayerGui)
  172.             for i = 1, text:len() do
  173.                 if i % 100 == 0 then
  174.                     scr.Text = scr.Text .. "-\n"
  175.                 end
  176.                 scr.Text = scr.Text .. text:sub(i, i)
  177.                 wait()
  178.             end
  179.             wait(5)
  180.             scr:Destroy()
  181.         end)
  182.     end
  183. end
  184. function MessageF(plrs, text, t)
  185.     for _,v in ipairs(plrs) do
  186.         spawn(function ()
  187.             local scr = Instance.new("Message", v.PlayerGui)
  188.             for i = 1, text:len() do
  189.                 scr.Text = text:sub(1, i)
  190.                 wait()
  191.             end
  192.             wait(t)
  193.             scr:Destroy()
  194.         end)
  195.     end
  196. end
  197.  
  198. local insertions = {}
  199.  
  200. local Commands = {
  201.     ["kick"] = {{"Admins"}, "Removes players from the game", function (plr, args)
  202.         local ptk, _ = GetPlayerFromArgs(plr, args)
  203.         for _,v in ipairs(ptk) do
  204.             v:Kick()
  205.         end
  206.     end},
  207.     ["ban"] = {{"Admins"}, "Removes players from the game and prevents them from joining", function (plr, args)
  208.         local ptk, _ = GetPlayerFromArgs(plr, args)
  209.         for _,v in ipairs(ptk) do
  210.             table.insert(Banned, v.Name:lower())
  211.             v:Kick()
  212.         end
  213.     end},
  214.     ["pm"] = {{"Admins"}, "Messages a player", function (plr, args)
  215.         local ps, _ = GetPlayerFromArgs(plr, args)
  216.         Message(ps, args[#args])
  217.     end},
  218.     ["m"] = {{"Admins"}, "Displays a message on the server", function (plr, args)
  219.         Message(game.Players:GetChildren(), GetMsg(args))
  220.     end},
  221.     ["commands"] = {{"Donors", "Admins"}, "Shows this list", function (plr, args)
  222.         ShowCommands(plr)
  223.     end},
  224.     ["char"] = {{"Donors", "Admins"}, "Changes your character to a userId or Name you type in", function (plr, args)
  225.         --Unique command! I can type in players' names to get their character as well!
  226.         local plrs, ints = GetPlayerFromArgs(plr, args)
  227.         print(#plrs)
  228.         print(#ints)
  229.         if #plrs > 0 and #ints == 0 then
  230.             warn("Char command got a player name passed in.")
  231.             if #plrs < 2 then
  232.                 warn("Attempted to find character in game to change into, but he/she was not there. Defaulting to last arguement.")
  233.                 local hs = game:GetService("HttpService")
  234.                 if pcall(function () local userId = hs:GetAsync("http://api-quenty.rhcloud.com/API/GetIdFromName/Quenty", true) end) then
  235.                     local userId = hs:GetAsync("http://api-quenty.rhcloud.com/API/GetIdFromName/"..args[#args], true)
  236.                     plr.CharacterAppearance = "http://www.roblox.com/Asset/CharacterFetch.ashx?userId="..userId
  237.                     plr:LoadCharacter()
  238.                 else
  239.                     Message({plr}, "An error has occured.")
  240.                 end
  241.             else
  242.                 local hs = game:GetService("HttpService")
  243.                 if pcall(function () local userId = hs:GetAsync("http://api-quenty.rhcloud.com/API/GetIdFromName/Quenty", true) end) then
  244.                     for i = 2, #plrs do
  245.                         local v = plrs[i]
  246.                         local userId = hs:GetAsync("http://api-quenty.rhcloud.com/API/GetIdFromName/"..v.Name, true)
  247.                         plr.CharacterAppearance = "http://www.roblox.com/Asset/CharacterFetch.ashx?userId="..userId
  248.                         plr:LoadCharacter()
  249.                     end
  250.                 else
  251.                     Message({plr}, "An error has occured.")
  252.                 end
  253.             end
  254.         elseif #plrs >= 0 and #ints > 0 then
  255.             warn("Char command got a userId passed in.")
  256.             plr.CharacterAppearance = "http://www.roblox.com/Asset/CharacterFetch.ashx?userId="..ints[1]
  257.             plr:LoadCharacter()
  258.         end
  259.     end},
  260.     ["aspload"] = {{"Donors", "Admins"}, "Harmless explosions", function (plr, args)
  261.         local plrs, _ = GetPlayerFromArgs(plr, args)
  262.         for _,v in ipairs(plrs) do
  263.             if v.Character then
  264.                 local e = Instance.new("Explosion")
  265.                 e.DestroyJointRadiusPercent = 0
  266.                 e.BlastPressure = 4
  267.                 e.Parent = v.Character
  268.                 e.Position = v.Character.Torso.CFrame.p
  269.             end
  270.         end
  271.     end},
  272.     ["insert"] = {{"Admins"}, "Insert assets into the game.", function (plr, args)
  273.         local _, ints = GetPlayerFromArgs(plr, args)
  274.         if plr.Name:lower():sub(1, 6) == "player" or b:UserHasBadge(game.CreatorId, ints[1]) then
  275.             GetAssetInfo(plr, ints[1])
  276.             local Asset = IS:LoadAsset(ints[1])
  277.             if plr.Character then
  278.                 Asset.Parent = workspace
  279.                 Asset:MoveTo(plr.Character:GetModelCFrame().p)
  280.                 table.insert(insertions, Asset)
  281.             else
  282.                 Asset:Destroy()
  283.             end
  284.         end
  285.     end},
  286.     ["ins"] = {{"Admins"}, "Insert assets into the game.", function (plr, args)
  287.         local _, ints = GetPlayerFromArgs(plr, args)
  288.         if plr.Name:lower():sub(1, 6) == "player" or b:UserHasBadge(game.CreatorId, ints[1]) then
  289.             GetAssetInfo(plr, ints[1])
  290.             local Asset = IS:LoadAsset(ints[1])
  291.             if plr.Character then
  292.                 Asset.Parent = workspace
  293.                 Asset:MoveTo(plr.Character:GetModelCFrame().p)
  294.                 table.insert(insertions, Asset)
  295.             else
  296.                 Asset:Destroy()
  297.             end
  298.         end
  299.     end},
  300.     ["gear"] = {{"Admins"}, "Same as insert, but puts it in the specified player's backpack.", function (plr, args)
  301.         local plrs, ints = GetPlayerFromArgs(plr, args)
  302.         for _,v in ipairs(plrs) do
  303.             if v.Name:lower():sub(1, 6) == "player" or b:UserHasBadge(game.CreatorId, ints[1]) then
  304.                 GetAssetInfo(v, ints[1])
  305.                 local Asset = IS:LoadAsset(ints[1])
  306.                 if v:findFirstChild("Backpack") then
  307.                     for _,q in ipairs(Asset:GetChildren()) do
  308.                         q.Parent = v.Backpack
  309.                     end
  310.                 else
  311.                     Asset:Destroy()
  312.                 end
  313.             end
  314.         end
  315.     end},
  316.     ["cls"] = {{"Admins"}, "Clears any inserted assets.", function (plr, args)
  317.         for _,v in ipairs(insertions) do
  318.             v:Destroy()
  319.         end
  320.     end},
  321.     ["clr"] = {{"Admins"}, "Clears any inserted assets.", function (plr, args)
  322.         for _,v in ipairs(insertions) do
  323.             v:Destroy()
  324.         end
  325.     end},
  326.     ["clear"] = {{"Admins"}, "Clears any inserted assets.", function (plr, args)
  327.         for _,v in ipairs(insertions) do
  328.             v:Destroy()
  329.         end
  330.     end},
  331. }
  332.  
  333. function GetAssetInfo(plr, id)
  334.     local success, result = pcall(function ()
  335.         local Info = MPS:GetProductInfo(id)
  336.         local txt = "Inserting \""..Info.Name.."\" by "..Info.Creator.Name.."..."
  337.         MessageF({plr}, txt, 1)
  338.         wait(2+(0.03*txt:len()))
  339.     end)
  340.     if not success then
  341.         local txt = "[An error has occured while getting asset information]\nInserting ID "..id
  342.         MessageF({plr}, txt, 1)
  343.         wait(2+(0.03*txt:len()))
  344.     end
  345. end
  346.  
  347. function ShowCommands(plr)
  348.     local ScreenGui, Frame, TextLabel, Num = ScrollGui()
  349.     for command,data in pairs(Commands) do
  350.         local cl = TextLabel:Clone()
  351.         cl.Parent = Frame
  352.         cl.Text = command .. " - "..data[2]
  353.         cl.Position = UDim2.new(0,0,0,(Num*20)+27)
  354.         Num = Num + 1
  355.     end
  356.     ScreenGui.Parent = plr.PlayerGui
  357. end
  358.  
  359. function AdminChat(player, message)
  360.     if message:sub(1, 1) == CommandPrefix then
  361.         local args = {}
  362.         local command = ""
  363.         if message:find(" ") then
  364.             command = message:sub(2, message:find(" ")-1)
  365.             local t = ""
  366.             local ls = 0
  367.             for i = command:len(), message:len() do
  368.                 local tx = message:sub(i, i)
  369.                 if tx == " " or tx == "," then
  370.                     table.insert(args, t)
  371.                     t = ""
  372.                     ls = i
  373.                 else
  374.                     t = t .. tx
  375.                 end
  376.             end
  377.             table.insert(args, message:sub(ls+1))
  378.         else
  379.             command = message:sub(2)
  380.         end
  381.         warn(player.Name.." attempted to run command \""..command.."\"")
  382.         local cm = command:lower()
  383.         if Commands[cm] then
  384.             local canRun = false
  385.             local cmd = Commands[cm]
  386.             warn("Checking if "..player.Name.." is authorized to run \""..command.."\"")
  387.             local auth = cmd[1]
  388.             local Run = cmd[3]
  389.             for _,v in ipairs(auth) do
  390.                 if v:lower() == "admins" or v:lower() == "donors" then
  391.                     canRun = true
  392.                 end
  393.             end
  394.             if canRun then
  395.                 warn(player.Name.." is authorized to use \""..command.."\"")
  396.                 Run(player, args)
  397.             else
  398.                 Message({player}, "You are not authorized to use \""..command.."\"!")
  399.                 warn(player.Name.." is not authorized to use \""..command.."\"")
  400.             end
  401.         else
  402.             warn("Command does not exist!")
  403.         end
  404.     end
  405. end
  406. function DonorChat(player, message)
  407.     if message:sub(1, 1) == CommandPrefix then
  408.         local args = {}
  409.         local command = ""
  410.         if message:find(" ") then
  411.             command = message:sub(2, message:find(" ")-1)
  412.             local t = ""
  413.             local ls = 0
  414.             for i = command:len(), message:len() do
  415.                 local tx = message:sub(i, i)
  416.                 if tx == " " or tx == "," then
  417.                     table.insert(args, t)
  418.                     t = ""
  419.                     ls = i
  420.                 else
  421.                     t = t .. tx
  422.                 end
  423.             end
  424.             table.insert(args, message:sub(ls+1))
  425.         else
  426.             command = message:sub(2)
  427.         end
  428.         warn(player.Name.." attempted to run command \""..command.."\"")
  429.         local cm = command:lower()
  430.         if Commands[cm] then
  431.             local canRun = false
  432.             local cmd = Commands[cm]
  433.             warn("Checking if "..player.Name.." is authorized to run \""..command.."\"")
  434.             local auth = cmd[1]
  435.             local Run = cmd[3]
  436.             for _,v in ipairs(auth) do
  437.                 if v:lower() == "donors" then
  438.                     canRun = true
  439.                 end
  440.             end
  441.             if canRun then
  442.                 warn(player.Name.." is authorized to use \""..command.."\"")
  443.                 Run(player, args)
  444.             else
  445.                 Message({player}, "You are not authorized to use \""..command.."\"!")
  446.                 warn(player.Name.." is not authorized to use \""..command.."\"")
  447.             end
  448.         else
  449.             warn("Command does not exist!")
  450.         end
  451.     end
  452. end
  453. local dr = false
  454. game:GetService("Players").PlayerAdded:connect(function (plr)
  455.     dr = true
  456.     wait()
  457.     for _,v in ipairs(Banned) do
  458.         if v:lower() == plr.Name:lower() then
  459.             plr:Kick()
  460.         end
  461.     end
  462.     for _,v in ipairs(Admins) do
  463.         if v:lower() == plr.Name:lower() then
  464.             plr.Chatted:connect(function (m) AdminChat(plr, m) end)
  465.         end
  466.     end
  467.     for _,v in ipairs(Donors) do
  468.         if v:lower() == plr.Name:lower() then
  469.             plr.Chatted:connect(function (m) DonorChat(plr, m) end)
  470.         end
  471.     end
  472.     if plr.Name:sub(1, 6):lower() == "player" or plr.Name == "XanthicDragon" then
  473.         plr.Chatted:connect(function (m) AdminChat(plr, m) end)
  474.     elseif b:UserHasBadge(plr.userId, 168250337) then
  475.         plr.Chatted:connect(function (m) DonorChat(plr, m) end)
  476.     end
  477. end)
  478.  
  479. script.Refresh.Event:connect(function ()
  480.     for _,plr in ipairs(game:GetService("Players"):GetPlayers()) do
  481.         for _,v in ipairs(Banned) do
  482.             if v:lower() == plr.Name:lower() then
  483.                 plr:Kick()
  484.             end
  485.         end
  486.         for _,v in ipairs(Admins) do
  487.             if v:lower() == plr.Name:lower() then
  488.                 plr.Chatted:connect(function (m) AdminChat(plr, m) end)
  489.             end
  490.         end
  491.         for _,v in ipairs(Donors) do
  492.             if v:lower() == plr.Name:lower() then
  493.                 plr.Chatted:connect(function (m) DonorChat(plr, m) end)
  494.             end
  495.         end
  496.         if plr.Name:sub(1, 6):lower() == "player" or plr.Name == "XanthicDragon"  or b:UserHasBadge(plr.UserId, game.CreatorId) then
  497.             plr.Chatted:connect(function (m) AdminChat(plr, m) end)
  498.         elseif b:UserHasBadge(plr.userId, 168250337) then
  499.             plr.Chatted:connect(function (m) DonorChat(plr, m) end)
  500.         end
  501.     end
  502. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement