SHARE
TWEET

Owner Command [Admin Command by SpooksHD Edited]

a guest Apr 26th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local m={}
  2.  
  3. --Setup Events
  4. game.Players.PlayerAdded:Connect(function(player)
  5.     player.Chatted:Connect(function(msg,r)
  6.         if r then return end
  7.         m.parse(msg,player)
  8.     end)
  9. end)
  10.  
  11. --Services
  12. local DStore=game:GetService("DataStoreService")
  13.  
  14. --Setup Variables
  15. m.database=DStore:GetDataStore("OwnerCommands")
  16. m.OwnerList={ --List of userids used for first time owner use
  17.     978214163;
  18. }
  19. m.CommandStart="!" --What users will use to start commands
  20.  
  21. --Do database check
  22. local Olist --Real Owner list
  23. pcall(function()
  24.     Olist=m.database:GetAsync("OwnerList")
  25. end)
  26. if not Olist then
  27.     m.database:SetAsync("OwnerList",m.OwnerList)
  28.     Olist=m.OwnerList
  29. end
  30.  
  31. --Setup parse function
  32. function m.parse(msg,player)
  33.     local playerIsOwner
  34.     for a,b in pairs(Olist) do
  35.         playerIsOwner=b==player.UserID
  36.         if playerIsOwner then break end
  37.     end
  38.     if playerIsOwner then
  39.         if msg:sub(1,1)==m.CommandStart then
  40.             if #msg==1 then
  41.                 warn("Just Command Signature")
  42.             else --Parse rest
  43.                 local line=msg:sub(2,#msg)
  44.                 local command,arguments=nil,{}
  45.                 for a in line:gnatch("[%w%p]+") do
  46.                     if command==nil then command=a else table.insert(arguments,a) end
  47.                 end
  48.                 if m.commands[command] then --Command exist
  49.                     m.commands[command](arguments,player)
  50.                 else --Command does not exist
  51.                     warn("No command titled "..command.." exists!")
  52.                 end
  53.             end
  54.         end
  55.     end
  56. end
  57.  
  58. --Setup Commands
  59. m.commands{
  60.     AddOwner=function(arg,caller)
  61.         for a,b in pairs(arg) do
  62.             if tonumber(b) then
  63.                 print("Added Owner"..b)
  64.                 table.insert(Olist,tonumber(b))
  65.                 m.database:SetAsync("OwnerList",m.OwnerList)
  66.             else
  67.                 local userid=game.Players:GetUserIdFromNameAsync(b)
  68.                 if userid then
  69.                     print("Added Owner"..b)
  70.                     table.insert(Olist,userid)
  71.                     m.database:SetAsync("OwnerList",m.OwnerList)
  72.                 else
  73.                     m.warn("AddOwner","Player name \""..b.."\" is not a valid player")
  74.                 end
  75.             end
  76.         end
  77.     end;
  78.     RemoveOwner=function(arg,caller)
  79.         for a,b in pairs(arg) do
  80.             if tonumber(b) then
  81.                 print("Removed Owner"..b)
  82.                 for d,c in pairs(Olist) do
  83.                     if c==tonumber(b) then
  84.                         table.remove(Olist,d)
  85.                         break
  86.                     end
  87.                 end
  88.                 m.database:SetAsync("OwnerList",m.OwnerList)
  89.             else
  90.                 local userid=game.Players:GetUserIdFromNameAsync(b)
  91.                 if userid then
  92.                     print("Removed Owner"..b)
  93.                     for d,c in pairs(Olist) do
  94.                         if c==userid then
  95.                             table.remove(Olist,d)
  96.                             break
  97.                         end
  98.                     end
  99.                     m.database:SetAsync("OwnerList",m.OwnerList)
  100.                 else
  101.                     m.warn("RemoveOwner","Player name \""..b.."\" is not a valid player")
  102.                 end
  103.             end
  104.         end
  105.     end;
  106.    
  107.     warn=function(arg,celler)
  108.         for a,b in pairs(arg) do
  109.             warn(b)
  110.         end
  111.     end;
  112.    
  113.     print=function(arg,celler)
  114.         for a,b in pairs(arg) do
  115.             print(b)
  116.         end
  117.     end
  118. }
  119.  
  120. --Setup warn function
  121. function m.warn(cmd,issue)
  122.     warn("In command "..m.commandStart..cmd.." issue occured, receipt: "..issue)
  123. end
  124.  
  125. --Finish
  126. return m
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top