# Custom Commands

To let Pixel Administration know that you want to expand its command library with more commands, you'll first need to make a folder for your custom commands. It's recommended that you put it inside of ServerScriptService mostly for safety and compatibility reasons.

Lets make a server script inside of the custom commands folder you've created. You can name it whatever, or just leave it as "Script". It wont really matter. What you'll want to do next is add this code inside of that script.

{% code lineNumbers="true" %}

```lua
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PSStorage = ReplicatedStorage:WaitForChild("PA - Storage") -- The storage folder that's generated by Pixel Administration when you join.
local Modules = PSStorage.Modules -- The modules folder inside of Pixel Administration
local Commands = require(Modules.Commands) -- The commands module for Pixel Administration

Commands:SetCustomCommandsFolder(script.Parent) -- Adds the custom command folder which is the folder you put the script in.
```

{% endcode %}

Now that you've set up your custom commands folder and registered it with Pixel Administration, you'll want to start creating your own commands. Each command needs to be structured in a specific way for Pixel Administration to recognize and execute it properly.

To create a new command, insert a ModuleScript into your custom commands folder. The name of the ModuleScript will be used as the command's identifier, so make sure it's descriptive and unique. Inside this ModuleScript, you'll need to return a table that follows Pixel Administration's command structure.

{% code lineNumbers="true" %}

```lua
return {
    CmdName = "YourCommandName", -- This should match your ModuleScript's name
    CmdDesc = "A brief description of what your command does",
    CmdIcon = "rbxassetid://123456789", -- Optional: An icon for your command
    IsServerCommand = true, -- Set to false if it should run on the client instead
    Aliases = {"alias1", "alias2"}, -- Optional: Alternative names for your command
    
    Arguments = {
        {
            Name = "ArgumentName", -- The name for the argument.
            Type = "Players", -- The argument's type.
            Description = "Argument Description.", -- The argument's description.
            Optional = false, -- If the argument is optional.
            Default = nil -- The default value if the argument was skipped (only for optional arguments).
        }
    },
    
    OnActivated = function(arguments, executor) -- The function that runs when the command is ran.
        return {Success = true, Message = "Your command executed successfully!"}
    end
}
```

{% endcode %}

Command types such as "Players", "Players", and "String" are all supported arguments that will be handled by the command bar, and Pixel Administration's command services. When entering a string inside of Pixel Administration's command bar, you can type it in without being enclosed by quotes, but that requires no spaces, otherwise it will move on to the next argument since it found a space. To fix that you can enclose it in quotes so it supports spaces in your string. The "Players" argument will allow you to include multiple players (but with a comma after each player). The "Player" argument is like the "Players" argument, but only accepts one player.

Now lets talk about the OnActivated function since it's not documented in this example script. The return function is optional, but will return a notification to the person that ran the command. Here's one showing how you could handle each player in a players argument (for multiple players) for OnActivated since it might be more difficult:

{% code lineNumbers="true" %}

```lua
OnActivated = function(arguments, executor)
   local targetPlayers = arguments["Players"] -- Get the players from the arguments
   
   for _, player in ipairs(targetPlayers) do -- Loops through every player in the "Players" argument.
       print("Player:", player.Name) -- Prints "Player: (player's username)" to the output.
   end
end
```

{% endcode %}

<figure><img src="https://1445404073-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuYzhZD76M7Bw9euOnkJi%2Fuploads%2FYqZkxCeL71qIwelsp9HH%2Fimage.png?alt=media&#x26;token=dd31ec49-247d-439d-ba5f-e3f2738253bd" alt=""><figcaption></figcaption></figure>

If you want to add custom suggestions to your command arguments, you can extend your argument definitions with suggestion functions. This makes your commands much more user-friendly since players won't have to remember exact names or values.

{% code lineNumbers="true" %}

```lua
Arguments = {
    {
        Name = "ItemName",
        Type = "String",
        Description = "The name of the item to use.",
        
        CustomSuggestions = {
            ItemName = function()
                local suggestions = {}
                local itemsFolder = game.ServerStorage:FindFirstChild("Items")
                
                if itemsFolder then
                    for _, item in ipairs(itemsFolder:GetChildren()) do
                        table.insert(suggestions, {
                            text = item.Name,
                            icon = "rbxassetid://123456789",
                            info = {name = "Item", color = Color3.fromRGB(100, 200, 255)}
                        })
                    end
                end
                
                return suggestions
            end
        }
    }
}
```

{% endcode %}
