CommandBarService
A module to manage the registering and running of commands made with Cmdr
Setting Up
Giving Yourself Permissions To Run Commands
- Locate the permissions module in
ServerScriptService.server.Services.CommandBarService.Hooks -
Add your UserId to the
Ownerstable
Warning
All members of Owners are able to run commands regardless of whether or not they have been distinctly given permission in the command description module. I recommend only including yourself or the account that manages the game in this table.
Creating Commands
- Locate the commands folder in
ServerScriptService.server.Services.CommandBarService - Create a new folder give it the a name of the command you want to create
Test - Create a module with the same name as the folder that returns a description of the command
return { Name = "test", Aliases = {}, Description = "Test.", Group = "Owners, Admins, Moderators", --The string just has to contain everyone that has access to these commands and is checked by the Hooks.Permissions BeforeRun function Args = { { Type = "string", Name = "input", Description = "some input", }, }, } - Next we create the module to actually run when a command is run and give it the same name as the folder but add
Serverto the end. This is used byCommandBarServiceto identify the module to handle the running of the command
Permissions
Cmdr uses a BeforeRun and AfterRun system called hooks to filter attempts to run a command and serve as a way to bind functions to after events run.
- To register hooks navigate to the Hooks folder in
ServerScriptService.server.Services.CommandBarService - Create a module that similar to this to register new hooks
--!strict
--[[
{C.G.T}
-[Permissions]---------------------------------------
A module made to determine if a player has the permissions run a commands .
Members:
Functions:
Members [ClassName]:
Methods [ClassName]:
--]]
local SETTINGS = {}
----- Loaded Modules -----
local Players = game:GetService("Players")
----- Module Table -----
local Permissions
----- Private Variables -----
local Groups = {
Owners = { 69420 },
Admins = {},
Moderators = {},
--You can also use functions as a member check 💯
-- AccountIsOverADayOld = function(user_id)
-- local player = Players:GetPlayerByUserId(user_id)
-- if player then
-- if player.AccountAge > 1 then
-- return true
-- end
-- end
-- return false
-- end,
}
----- Private functions -----
----- Public -----
Permissions = function(registry)
registry:RegisterHook("BeforeRun", function(context)
if table.find(Groups.Owners, context.Executor.UserId) then
return
end
for group_name: string, member_check: { number } | () -> boolean | nil in pairs(Groups) do
if type(member_check) == "table" then
if string.find(group_name, context.Group) then
if table.find(member_check, context.Executor.UserId) then
return
end
end
elseif type(member_check) == "function" then
local success, response = pcall(member_check, context.Executor.UserId)
if success == true and response == true then
return
end
end
end
return "You do not meet the requirements to run this command"
end)
end
----- Initialize & Connections -----
return Permissions
- This module is included in
C.G.Tand is responsible for determining who has permissions to run commands -
You can give yourself permissions to run commands by adding your
UserIdto theGroupstable.local Groups = { Owners = { 69420 }, Admins = {}, Moderators = {}, --You can also use functions as a member check 💯 -- AccountIsOverADayOld = function(user_id) -- local player = Players:GetPlayerByUserId(user_id) -- if player then -- if player.AccountAge > 1 then -- return true -- end -- end -- return false -- end, } -
Lastly make sure you give yourself other members of your team permission to run the command by including their group in the description module.
return { Name = "test", Aliases = {}, Description = "Test.", Group = "Owners, Admins, Moderators", --The string just has to contain everyone that has access to these commands and is checked by the Hooks.Permissions BeforeRun function Args = { { Type = "string", Name = "input", Description = "some input", }, }, } - Members of Groups can either be a table or a function the purpose of having functions is to allow you to add additional logic, examples include checking account age, playtime, is a member of the star creator group e.t.c