### Server Setup: Requiring and Initializing Cmdr Source: https://context7.com/evaera/cmdr/llms.txt Require the Cmdr server module in ServerScriptService to bootstrap the console UI, set up replication, and make Registry and Dispatcher available. Adjust the path to your Cmdr installation. ```lua -- ServerScriptService/CmdrSetup.server.luau local ServerScriptService = game:GetService("ServerScriptService") -- Adjust path to wherever Cmdr is installed (e.g. ServerStorage, ServerPackages) local Cmdr = require(ServerScriptService.Packages.Cmdr) -- Load all built-in commands (optional) Cmdr.Registry:RegisterDefaultCommands() -- Register your own commands from a folder -- Cmdr.Registry:RegisterCommandsIn(ServerScriptService.MyCommands) -- Register your own types from a folder -- Cmdr.Registry:RegisterTypesIn(ServerScriptService.MyTypes) -- Register hooks from a folder (runs on both server and client) -- Cmdr.Registry:RegisterHooksIn(ServerScriptService.MyHooks) ``` -------------------------------- ### Client Setup: Requiring CmdrClient Source: https://context7.com/evaera/cmdr/llms.txt Require CmdrClient from a LocalScript in StarterPlayerScripts. This module is automatically placed in ReplicatedStorage by the server module. Configure activation keys and other client-side behaviors. ```lua -- StarterPlayerScripts/CmdrClient.client.luau local ReplicatedStorage = game:GetService("ReplicatedStorage") local CmdrClient = require(ReplicatedStorage:WaitForChild("CmdrClient")) -- Set one or more keys that open/close the console (default is F2) CmdrClient:SetActivationKeys({ Enum.KeyCode.F2, Enum.KeyCode.Backquote }) -- Optional tweaks CmdrClient:SetPlaceName("My Game") -- Label shown on the console title bar CmdrClient:SetEnabled(true) -- Enable/disable activation via keys CmdrClient:SetActivationUnlocksMouse(true) -- Free the mouse when the console opens CmdrClient:SetHideOnLostFocus(true) -- Auto-hide when user clicks away CmdrClient:SetMashToEnable(false) -- Require 5 quick presses to enable ``` -------------------------------- ### Built-in Prefixed Union Types and Console Usage Source: https://context7.com/evaera/cmdr/llms.txt Illustrates automatic built-in prefixed union types like 'players', 'color3', and 'playerId'. Shows console usage examples for these types, demonstrating how prefixes like '%' and '#' are used for specific type matching. ```lua -- Automatic built-in prefixed unions (no extra work needed): -- players → "players % teamPlayers" (% selects by team name) -- color3 → "color3 # hexColor3 ! brickColor3" -- playerId → "playerId # integer" -- Console usage examples: -- teleport %RedTeam SomePlayer (teleport everyone on RedTeam to SomePlayer) -- color #FF5733 (pass a hex colour) ``` -------------------------------- ### Registering Specific Default Command Groups Source: https://github.com/evaera/cmdr/blob/master/docs/10-commands.md Register only a subset of default commands by passing an array of group names to the RegisterDefaultCommands function. This example registers only the 'Help' and 'DefaultUtil' groups. ```lua Cmdr.Registry:RegisterDefaultCommands({"Help", "DefaultUtil"}) ``` -------------------------------- ### Register Custom Integer Type in Cmdr Source: https://github.com/evaera/cmdr/blob/master/docs/12-types.md This example demonstrates how to define and register a custom 'integer' type with Cmdr. It includes functions for transforming input text, validating the parsed value, and parsing the final value. The type definition is returned as a function that accepts the registry. ```lua local intType = { Transform = function(text) return tonumber(text) end, Validate = function(value) return value ~= nil and value == math.floor(value), "Only whole numbers are valid." end, Parse = function(value) return value end, } return function(registry) registry:RegisterType("integer", intType) end ``` -------------------------------- ### Register AfterRun Hook for Logging and Output Modification Source: https://github.com/evaera/cmdr/blob/master/docs/11-hooks.md This hook runs after a command has executed. It can be used for logging command responses or modifying the final output by returning a string. This example registers the hook directly on the server. ```lua Cmdr.Registry:RegisterHook("AfterRun", function(context) print(context.Response) -- see the actual response from the command execution return "Returning a string from this hook replaces the response message with this text" end) ``` -------------------------------- ### Registering a Subset of Default Commands with a Filter Function Source: https://github.com/evaera/cmdr/blob/master/docs/10-commands.md Use a filter function to selectively register default commands based on a condition. This example registers commands with names shorter than 6 characters. ```lua Cmdr.Registry:RegisterDefaultCommands(function(cmd) return #cmd.Name < 6 -- This is absurd... but possible! end) ``` -------------------------------- ### Resolving Argument Value Operators with the 'resolve' Command Source: https://github.com/evaera/cmdr/blob/master/docs/10-commands.md The 'resolve' command retrieves the true value of argument operators for a given type. Examples show resolving '.', '*', '**', and '?' operators for the 'players' type. ```lua resolve players . ``` ```lua resolve players * ``` ```lua resolve players ** ``` ```lua resolve players ? ``` -------------------------------- ### Dynamic Argument with Inline Enum Type Source: https://github.com/evaera/cmdr/blob/master/docs/10-commands.md This example demonstrates a dynamic argument where the type of the second argument ('Player') changes based on the value of the first argument ('Action'). The 'Action' argument uses an inline enum type. ```lua return { Name = "allowlist", Aliases = {}, Description = "Add or remove a player from the allow list.", Group = "Admin", Args = { -- This is an example of a dynamic inline type function(context) return { Type = context.Cmdr.Util.MakeEnumType("option", {"add", "remove"}), Name = "Action", Description = "Add or remove", } end, -- This is an example of a dynamic argument function(context) local action = context:GetArgument(1):GetValue() return { Type = if action == "add" then `playerId` else `allowlistPlayer`, Name = "Player", Description = `The player to {action} from the allow list.` } end, }, } ``` -------------------------------- ### Define Prefixed Union Types for Arguments Source: https://github.com/evaera/cmdr/blob/master/docs/10-commands.md Specify multiple types for a single argument using prefixes. The type is determined by the prefix the user provides. For example, 'string # number' allows a string or a number prefixed with '#'. ```lua Type = "string # number @ player % team" ``` -------------------------------- ### Override Default Message Event Handler Source: https://github.com/evaera/cmdr/blob/master/docs/14-networkeventhandlers.md Replace the default system message handler with a custom function to process announcement messages differently. This example prints the announcement text and the player who sent it to the client's console. ```lua CmdrClient:HandleEvent("Message", function (text, player) print("Announcement from", player.Name, text) end) ``` -------------------------------- ### Initialize Cmdr Client and Set Activation Keys Source: https://github.com/evaera/cmdr/blob/master/docs/02-setup.md Require the CmdrClient module from ReplicatedStorage and set activation keys for the console. This script should be placed in StarterPlayerScripts. ```lua -- This is a local/client script you would create in StarterPlayerScripts, for example local ReplicatedStorage = game:GetService("ReplicatedStorage") local Cmdr = require(ReplicatedStorage:WaitForChild("CmdrClient")) -- Optional. Configurable, and you can choose multiple keys Cmdr:SetActivationKeys({ Enum.KeyCode.F2 }) -- You can call any extra methods here, like SetPlaceName, or access the registry to register a hook on the client only (if you want to!) ``` -------------------------------- ### Cmdr Meta-Commands: run, bind, alias Source: https://context7.com/evaera/cmdr/llms.txt Compose commands using command strings with argument substitution, sub-command interpolation, and sequencing/piping. Use `run` to execute immediately, `bind` for key presses or chat, and `alias` to create new commands. ```shell -- Run: execute a composed command string immediately run echo ${echo hello} world -- Output: "hello world" -- Chaining with && and piping output with || run echo evaera && announce "Welcome, ||!" -- First echoes "evaera", then announces "Welcome, evaera!" -- Bind: run a command string on a key press (client-side) bind F announce "F in the chat" -- Bind to a player's chat messages (@prefix = player, $1 = chat text) bind @Player1 echo Player1 said: $1 -- Alias: create a new named command from a command string alias "goodbye|Kicks a player with a farewell." announce Farewell $1{player|Player}! && kick $1{player|Player} -- Now "goodbye SomePlayer" announces and then kicks them -- Alias with embedded hover (kick whoever your mouse is over) alias pointer_kick kick ${hover} ``` -------------------------------- ### Programmatically Kick Players on Server Source: https://context7.com/evaera/cmdr/llms.txt Shows how to use Dispatcher:EvaluateAndRun on the server to execute a command string, such as kicking a player. This is useful for server-initiated actions like scheduled events or admin commands. ```lua -- ServerScriptService/EventHandler.server.luau local ServerScriptService = game:GetService("ServerScriptService") local Cmdr = require(ServerScriptService.Packages.Cmdr) -- Kick all players when the round ends local function onRoundEnd() local Players = game:GetService("Players") for _, player in ipairs(Players:GetPlayers()) do local result = Cmdr.Dispatcher:EvaluateAndRun( "kick " .. player.Name, player, -- executor (the player who "runs" it) { Data = nil } ) print("kick result:", result) end end ``` -------------------------------- ### Server-to-Client Messaging with Cmdr Source: https://context7.com/evaera/cmdr/llms.txt Send messages back to the executor's console, or to specific or all clients. Use `context:Reply` for the executor, `context:SendEvent` for a single client, and `context:BroadcastEvent` for all clients. ```lua -- CmdrCommands/AlertServer.luau return function(context, message) -- Send a plain line to the console of the executor only context:Reply("Broadcasting alert to all players...") -- Fire the "ShowAlert" handler on every client, passing the message and executor context:BroadcastEvent("ShowAlert", message, context.Executor) -- Or target a single player's client: -- context:SendEvent(somePlayer, "ShowAlert", message, context.Executor) return "Alert sent." end ``` -------------------------------- ### Server Implementation for PlantTree Command Source: https://context7.com/evaera/cmdr/llms.txt The server-side implementation for the 'planttree' command, which receives client-side data (position) and places a tree model in the workspace. ```lua -- CmdrCommands/PlantTreeServer.luau return function(context) local position = context:GetData() -- Vector3 from the client Data function if typeof(position) ~= "Vector3" then return "Could not determine target position." end local tree = game.ReplicatedStorage.TreeModel:Clone() tree:SetPrimaryPartCFrame(CFrame.new(position)) tree.Parent = workspace return "Tree planted at " .. tostring(position) end ``` -------------------------------- ### CmdrClient:Run — Running Commands Programmatically (Client) Source: https://context7.com/evaera/cmdr/llms.txt Enables running commands on the client as the local player, intended for hard-coded invocations rather than user input. Raises an error for invalid commands or arguments. ```APIDOC ## CmdrClient:Run — Running Commands Programmatically (Client) Invokes a command on the client as the local player. Raises an error if the command or arguments are invalid—intended for hard-coded invocations, not user input. ```lua -- StarterPlayerScripts/AbilityController.client.luau local ReplicatedStorage = game:GetService("ReplicatedStorage") local CmdrClient = require(ReplicatedStorage:WaitForChild("CmdrClient")) -- Bind an ability key that triggers a Cmdr command game:GetService("UserInputService").InputBegan:Connect(function(input, processed) if processed then return end if input.KeyCode == Enum.KeyCode.Q then -- Equivalent to the user typing "cast_ability fireball" local result = CmdrClient:Run("cast_ability", "fireball") print("ability result:", result) end end) ``` ``` -------------------------------- ### Register Default Commands on Server Source: https://github.com/evaera/cmdr/blob/master/docs/02-setup.md Register default commands and optionally commands from a custom folder on the server. This script should be placed in ServerScriptService. ```lua -- This is a script you would create in ServerScriptService, for example local ServerScriptService = game:GetService("ServerScriptService") local Cmdr = require(path.to.Cmdr) -- e.g. ServerScriptService.Packages.Cmdr Cmdr:RegisterDefaultCommands() -- Optional: This loads the default set of commands that Cmdr comes with. -- Cmdr:RegisterCommandsIn(ServerScriptService.CmdrCommands) -- Optional: Register commands from your own folder. -- You can also register types or hooks here: read on or check the API reference! ``` -------------------------------- ### Programmatically Run Client Command Source: https://context7.com/evaera/cmdr/llms.txt Demonstrates using CmdrClient:Run on the client to invoke a command as if the local player typed it. This method raises an error for invalid commands or arguments and is intended for hard-coded invocations. ```lua -- StarterPlayerScripts/AbilityController.client.luau local ReplicatedStorage = game:GetService("ReplicatedStorage") local CmdrClient = require(ReplicatedStorage:WaitForChild("CmdrClient")) -- Bind an ability key that triggers a Cmdr command game:GetService("UserInputService").InputBegan:Connect(function(input, processed) if processed then return end if input.KeyCode == Enum.KeyCode.Q then -- Equivalent to the user typing "cast_ability fireball" local result = CmdrClient:Run("cast_ability", "fireball") print("ability result:", result) end end) ``` -------------------------------- ### Create a Fuzzy Finder Utility Source: https://context7.com/evaera/cmdr/llms.txt Demonstrates creating a reusable fuzzy search function using Util.MakeFuzzyFinder. This utility performs case-insensitive fuzzy matching against a list of strings and can return all matches or the best match. ```lua local Cmdr = require(ServerScriptService.Packages.Cmdr) local Util = Cmdr.Util -- Build a fuzzy finder over a list of strings local findWeapon = Util.MakeFuzzyFinder({ "Sword", "Bow", "Staff", "Dagger", "Crossbow" }) -- Search: returns array of all matches (substring) print(findWeapon("bow")) -- { "Bow", "Crossbow" } -- returnFirst = true: returns only the best match or nil print(findWeapon("dag", true)) -- "Dagger" -- matchStart = true: only matches at the beginning of the string print(findWeapon("s", false, true)) -- { "Sword", "Staff" } ``` -------------------------------- ### Persistent Command State with Registry:GetStore Source: https://context7.com/evaera/cmdr/llms.txt Retrieve a persistent table for tracking command state across invocations. The same table is returned for a given name throughout the server's lifetime. ```lua -- CmdrCommands/BanServer.luau return function(context, targets) local bannedIds = context:GetStore("BannedPlayers") -- persistent table for _, player in ipairs(targets) do bannedIds[player.UserId] = true player:Kick("You have been banned.") end return string.format("Banned %d player(s).", #targets) end ``` ```lua -- Check bans in a BeforeRun hook registry:RegisterHook("BeforeRun", function(context) local bannedIds = context.Dispatcher.Registry:GetStore("BannedPlayers") if bannedIds[context.Executor.UserId] then return "You are banned from running commands." end end) ``` -------------------------------- ### Dispatcher:EvaluateAndRun — Running Commands Programmatically (Server) Source: https://context7.com/evaera/cmdr/llms.txt Allows for programmatic execution of command strings on the server, simulating user input. Useful for server-initiated actions like scheduled events or admin commands. ```APIDOC ## Dispatcher:EvaluateAndRun — Running Commands Programmatically (Server) Parses and executes a command string on behalf of a player without any UI interaction. Useful for scheduled events, NPC commands, or server-triggered admin actions. ```lua -- ServerScriptService/EventHandler.server.luau local ServerScriptService = game:GetService("ServerScriptService") local Cmdr = require(ServerScriptService.Packages.Cmdr) -- Kick all players when the round ends local function onRoundEnd() local Players = game:GetService("Players") for _, player in ipairs(Players:GetPlayers()) do local result = Cmdr.Dispatcher:EvaluateAndRun( "kick " .. player.Name, player, -- executor (the player who "runs" it) { Data = nil } ) print("kick result:", result) end end ``` ``` -------------------------------- ### Using Argument Value Operators with the 'kill' Command Source: https://github.com/evaera/cmdr/blob/master/docs/10-commands.md Demonstrates the use of argument value operators for the 'players' type with the 'kill' command. '*' targets all players, while '**' targets all players except the sender. ```lua kill * ``` ```lua kill ** ``` -------------------------------- ### Registry:RegisterCommandsIn - Registering Custom Commands Source: https://context7.com/evaera/cmdr/llms.txt Scans a container (Folder or Model) for ModuleScripts and registers every command definition found. Scripts whose name contains 'Server' are kept server-side only. Paired scripts (Foo.luau + FooServer.luau) are automatically linked. ```lua -- ServerScriptService/CmdrSetup.server.luau local ServerScriptService = game:GetService("ServerScriptService") local Cmdr = require(ServerScriptService.Packages.Cmdr) -- Register all commands inside a folder called "CmdrCommands" Cmdr.Registry:RegisterCommandsIn(ServerScriptService.CmdrCommands) -- Optionally filter which commands get registered Cmdr.Registry:RegisterCommandsIn(ServerScriptService.CmdrCommands, function(cmd) return cmd.Group == "Admin" -- Only register commands in the "Admin" group end) ``` -------------------------------- ### Client-Side Command Execution with ClientRun Source: https://context7.com/evaera/cmdr/llms.txt Adds client-side logic to a command using `ClientRun`. If `ClientRun` returns a string, the command remains client-side; returning `nil` falls through to the server. ```lua -- CmdrCommands/MyPos.luau return { Name = "mypos", Description = "Prints the local player's current world position.", Group = "DefaultUtil", Args = {}, ClientRun = function(context) local Players = game:GetService("Players") local char = Players.LocalPlayer.Character if char and char:FindFirstChild("HumanoidRootPart") then local pos = char.HumanoidRootPart.Position return string.format("%.1f, %.1f, %.1f", pos.X, pos.Y, pos.Z) end return "No character found." end, } ``` -------------------------------- ### Pass Client Data to Server with Data Function Source: https://context7.com/evaera/cmdr/llms.txt Uses a `Data` function to gather client-only information, like mouse position, and pass it to the server implementation via `context:GetData()`. ```lua -- CmdrCommands/PlantTree.luau return { Name = "planttree", Description = "Plants a tree at the admin's cursor position.", Group = "Admin", Args = {}, -- Runs on the client; return value is available on the server Data = function(context) return game:GetService("Players").LocalPlayer:GetMouse().Hit.Position end, } ``` -------------------------------- ### Implement Teleport Command Server Logic Source: https://github.com/evaera/cmdr/blob/master/docs/10-commands.md This Lua module provides the server-side implementation for the 'teleport' command. It takes a CommandContext and the defined arguments, then teleports the specified players to the target player's position. Ensure the target player has a HumanoidRootPart for teleportation. ```lua -- These arguments are guaranteed to exist and be correctly typed. return function (context, fromPlayers, toPlayer) if toPlayer.Character and toPlayer:FindFirstChild("HumanoidRootPart") then local position = toPlayer.Character.HumanoidRootPart.CFrame for _, player in ipairs(fromPlayers) do if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then player.Character.HumanoidRootPart.CFrame = position end end return "Teleported players." end return "Target player has no character." end ``` -------------------------------- ### Define an alias with a command description Source: https://github.com/evaera/cmdr/blob/master/docs/13-metacommands.md A description for the alias command itself can be provided by prefixing the command name with the description in quotes, separated by a pipe. ```lua alias "goodbye|Kills a player." kill $1{player|Player|The player you want to kill.} ``` -------------------------------- ### Register BeforeRun and AfterRun Hooks Source: https://context7.com/evaera/cmdr/llms.txt Registers 'BeforeRun' and 'AfterRun' hooks to intercept command execution. 'BeforeRun' can cancel commands, and 'AfterRun' can modify responses or log executions. A 'BeforeRun' hook is required for live servers. ```lua -- ServerScriptService/Hooks/PermissionsHook.luau -- This ModuleScript is loaded via Cmdr.Registry:RegisterHooksIn(folder) return function(registry) -- Permissions: block DefaultAdmin commands from non-owners registry:RegisterHook("BeforeRun", function(context) if context.Group == "DefaultAdmin" then if context.Executor.UserId ~= game.CreatorId then return "You don't have permission to run admin commands." end end -- Return nil (or nothing) to allow the command to proceed end, 0) -- third argument is priority; lower runs first -- Logging: record every command execution on the server registry:RegisterHook("AfterRun", function(context) print(string.format( "[CmdrLog] %s ran '%s' → %s", context.Executor.Name, context.RawText, tostring(context.Response) )) -- Return nil to keep the original response visible to the user end) end ``` -------------------------------- ### Registry:RegisterDefaultCommands - Loading Built-In Commands Source: https://context7.com/evaera/cmdr/llms.txt Registers the bundled set of admin, debug, and utility commands. Accepts an optional group filter (array of group name strings or a predicate function) for fine-grained control. ```lua -- Load only specific groups of built-in commands Cmdr.Registry:RegisterDefaultCommands({ "DefaultAdmin", "Help" }) -- Or use a predicate for fine-grained control Cmdr.Registry:RegisterDefaultCommands(function(cmd) -- Only register commands whose names are 8 characters or fewer return #cmd.Name <= 8 end) -- Available built-in groups: -- "DefaultAdmin" → announce, bring, kick, teleport, kill, respawn, to -- "DefaultDebug" → blink, thru, position, version, fetch, uptime, ... -- "DefaultUtil" → alias, bind, unbind, run, echo, var, history, ... -- "Help" → help ``` -------------------------------- ### Implement Heal Command Server Logic Source: https://context7.com/evaera/cmdr/llms.txt Provides the server-side implementation for the 'heal' command, restoring health to specified targets. Uses context:Reply to send feedback to the executor. ```lua -- CmdrCommands/HealServer.luau (server implementation) -- Receives CommandContext followed by parsed argument values in order. return function(context, targets, amount) for _, player in ipairs(targets) do local char = player.Character if char then local hum = char:FindFirstChildOfClass("Humanoid") if hum then hum.Health = math.min(hum.Health + amount, hum.MaxHealth) end end end -- context:Reply sends a line back to the executor's console context:Reply(string.format("Healed %d player(s) for %d HP.", #targets, amount)) return string.format("Healed %d player(s).", #targets) end ``` -------------------------------- ### Register BeforeRun Hook in ModuleScript Source: https://github.com/evaera/cmdr/blob/master/docs/11-hooks.md This hook is executed before a command runs. It can be used for permissions by returning a string to block the command. Ensure at least one BeforeRun hook is registered for commands to run in a live game. ```lua return function (registry) registry:RegisterHook("BeforeRun", function(context) if context.Group == "DefaultAdmin" and context.Executor.UserId ~= game.CreatorId then return "You don't have permission to run this command" end end) end ``` -------------------------------- ### Define a Heal Command Source: https://context7.com/evaera/cmdr/llms.txt Defines a 'heal' command with player targets and an optional amount. Requires a paired server module for implementation. ```lua -- CmdrCommands/Heal.luau (definition) return { Name = "heal", Aliases = { "hp" }, Description = "Restores a player's health to full.", Group = "Admin", Args = { { Type = "players", -- built-in listable type → {Player} Name = "targets", Description = "Players to heal", }, { Type = "integer", Name = "amount", Description = "HP to restore (default: full)", Optional = true, Default = 100, }, }, } ``` -------------------------------- ### Run an embedded command Source: https://github.com/evaera/cmdr/blob/master/docs/13-metacommands.md Use the `run` command to execute a command string. Embedded commands within the string are evaluated before execution. The literal syntax `{{...}}` prevents word splitting of the output. ```lua run ${{"echo kill me"}} ``` -------------------------------- ### Create an alias for targeting Source: https://github.com/evaera/cmdr/blob/master/docs/13-metacommands.md An alias can be created to target entities, such as the one the mouse is hovering over, using embedded commands like `${hover}`. ```lua alias pointer_of_death kill ${hover} ``` -------------------------------- ### Define alias arguments with types and descriptions Source: https://github.com/evaera/cmdr/blob/master/docs/13-metacommands.md Alias arguments can be specified with types, names, and descriptions using the format `$1{type|Name|Description}`. Name and description are optional. ```lua alias goodbye kill $1{player|Player|The player you want to kill.} ``` ```lua alias goodbye kill $1{player|Player} ``` ```lua alias goodbye kill $1{player} ``` -------------------------------- ### Create a custom command with `alias` Source: https://github.com/evaera/cmdr/blob/master/docs/13-metacommands.md The `alias` command creates a new command from a command string. It supports arguments like `$1` and can chain commands with `&&`. ```lua alias farewell announce Farewell, $1! && kill $1 ``` -------------------------------- ### Registering an Enum Type Source: https://github.com/evaera/cmdr/blob/master/docs/12-types.md This snippet demonstrates how to register a new Enum type named 'Place' with a predefined list of valid string values. When a command argument uses this type, it must be one of the specified strings. ```lua return function (registry) registry:RegisterType("place", registry.Cmdr.Util.MakeEnumType("Place", {"World 1", "World 2", "World 3", "Final World"})) end ``` -------------------------------- ### Define a Teleport Command Source: https://github.com/evaera/cmdr/blob/master/docs/10-commands.md This Lua module defines the metadata for a 'teleport' command, including its name, aliases, description, group, and arguments. This definition is used by Cmdr to understand how the command should be invoked. ```lua return { Name = "teleport", Aliases = { "tp" }, Description = "Teleports a player or set of players to one target.", Group = "Admin", Args = { { Type = "players", Name = "from", Description = "The players to teleport", }, { Type = "player", Name = "to", Description = "The player to teleport to", }, }, } ``` -------------------------------- ### Chain commands with `run` Source: https://github.com/evaera/cmdr/blob/master/docs/13-metacommands.md Commands within a `run` string can be chained using `&&`. The `||` operator can access the previous command's output. ```lua run echo evaera && kill || ``` -------------------------------- ### Add Cmdr via Wally Source: https://github.com/evaera/cmdr/blob/master/docs/01-installation.md Use this TOML snippet to add Cmdr as a server dependency in your project's wally.toml file. The caret symbol ensures automatic upgrades to compatible versions. ```toml [server-dependencies] Cmdr = "evaera/cmdr@^1.9.0" ``` -------------------------------- ### Register Client-Side Network Event Handler Source: https://context7.com/evaera/cmdr/llms.txt Registers a callback for a named network event. This can override default behaviors or handle custom events. Ensure CmdrClient is required and available. ```lua -- StarterPlayerScripts/CmdrClient.client.luau local ReplicatedStorage = game:GetService("ReplicatedStorage") local CmdrClient = require(ReplicatedStorage:WaitForChild("CmdrClient")) -- Override the built-in "Message" handler used by the `announce` command CmdrClient:HandleEvent("Message", function(text, senderPlayer) -- Show a custom GUI notification instead of the default chat message local gui = game.Players.LocalPlayer.PlayerGui:FindFirstChild("AnnouncementGui") if gui then gui.Label.Text = string.format("[%s]: %s", senderPlayer.Name, text) gui.Frame.Visible = true task.delay(5, function() gui.Frame.Visible = false end) end end) -- Handle a custom event fired by your own server commands CmdrClient:HandleEvent("ShowLeaderboard", function(data) -- data is whatever the server command passed to BroadcastEvent updateLeaderboardUI(data) end) ``` -------------------------------- ### Util.MakeFuzzyFinder — Fuzzy Search Utility Source: https://context7.com/evaera/cmdr/llms.txt Provides a reusable function for case-insensitive fuzzy matching against a list of strings, instances, or EnumItems. Exact matches are prioritized. ```APIDOC ## Util.MakeFuzzyFinder — Fuzzy Search Utility Returns a reusable search function that performs case-insensitive fuzzy matching against a set of strings, instances, or EnumItems. Exact matches are always placed first. ```lua local Cmdr = require(ServerScriptService.Packages.Cmdr) local Util = Cmdr.Util -- Build a fuzzy finder over a list of strings local findWeapon = Util.MakeFuzzyFinder({ "Sword", "Bow", "Staff", "Dagger", "Crossbow" }) -- Search: returns array of all matches (substring) print(findWeapon("bow")) -- { "Bow", "Crossbow" } -- returnFirst = true: returns only the best match or nil print(findWeapon("dag", true)) -- "Dagger" -- matchStart = true: only matches at the beginning of the string print(findWeapon("s", false, true)) -- { "Sword", "Staff" } ``` ``` -------------------------------- ### Register Custom 'gameMode' Argument Type Source: https://context7.com/evaera/cmdr/llms.txt Defines a custom argument type 'gameMode' that uses fuzzy matching against a predefined list of modes. It includes optional Transform, Validate, and Autocomplete functions, and a required Parse function. ```lua -- MyTypes/GameModeType.luau return function(registry) local MODES = { "Survival", "Creative", "Adventure", "Spectator" } local findMode = registry.Cmdr.Util.MakeFuzzyFinder(MODES) registry:RegisterType("gameMode", { -- Transform raw text before validation (optional) Transform = function(text) return text -- pass-through; fuzzy finder handles matching end, -- Return true if valid, or (false, errorMessage) if not Validate = function(text) return findMode(text, true) ~= nil, string.format("%q is not a valid game mode.", text) end, -- Provide autocomplete suggestions Autocomplete = function(text) return findMode(text) end, -- Return the final value passed to the command implementation Parse = function(text) return findMode(text, true) -- returns the matched string end, }) end ``` -------------------------------- ### Register 'difficulty' Argument Type using MakeEnumType Source: https://context7.com/evaera/cmdr/llms.txt Quickly registers a new argument type 'difficulty' using the MakeEnumType helper. This is suitable for small, fixed sets of string options and automatically provides autocomplete capabilities. ```lua -- MyTypes/DifficultyType.luau return function(registry) registry:RegisterType( "difficulty", registry.Cmdr.Util.MakeEnumType("Difficulty", { "Easy", "Normal", "Hard", "Nightmare" }) ) end ``` ```lua -- Usage in a command definition: Args = { { Type = "difficulty", Name = "level", Description = "Game difficulty" }, } -- Implementation receives the matched string, e.g. "Hard" ``` -------------------------------- ### Util.MakeEnumType — Quick Enum Type Helper Source: https://context7.com/evaera/cmdr/llms.txt A utility function to quickly create an autocomplete-capable argument type from a simple array of strings, ideal for a fixed set of options. ```APIDOC ## Util.MakeEnumType — Quick Enum Type Helper Creates a fully functional autocomplete-capable type from a simple array of strings. Ideal for small, fixed sets of options. ```lua -- MyTypes/DifficultyType.luau return function(registry) registry:RegisterType( "difficulty", registry.Cmdr.Util.MakeEnumType("Difficulty", { "Easy", "Normal", "Hard", "Nightmare" }) ) end ``` ```lua -- Usage in a command definition: Args = { { Type = "difficulty", Name = "level", Description = "Game difficulty" }, } -- Implementation receives the matched string, e.g. "Hard" ``` ``` -------------------------------- ### Registry:RegisterType / RegisterTypesIn — Custom Argument Types Source: https://context7.com/evaera/cmdr/llms.txt Defines how to register custom argument types with the Cmdr registry. Custom types are ModuleScripts that return a function accepting the Registry, and can implement Parse, Transform, Validate, Autocomplete, ValidateOnce, Default, and Listable. ```APIDOC ## Registry:RegisterType / RegisterTypesIn — Custom Argument Types Types are `ModuleScript`s that return a function accepting the Registry. Call `registry:RegisterType` inside that function. Each type implements `Parse` (required), plus optional `Transform`, `Validate`, `Autocomplete`, `ValidateOnce`, `Default`, and `Listable`. ```lua -- MyTypes/GameModeType.luau return function(registry) local MODES = { "Survival", "Creative", "Adventure", "Spectator" } local findMode = registry.Cmdr.Util.MakeFuzzyFinder(MODES) registry:RegisterType("gameMode", { -- Transform raw text before validation (optional) Transform = function(text) return text -- pass-through; fuzzy finder handles matching end, -- Return true if valid, or (false, errorMessage) if not Validate = function(text) return findMode(text, true) ~= nil, string.format("%q is not a valid game mode.", text) end, -- Provide autocomplete suggestions Autocomplete = function(text) return findMode(text) end, -- Return the final value passed to the command implementation Parse = function(text) return findMode(text, true) -- returns the matched string end, }) end ``` ``` -------------------------------- ### Define Union Type Argument in Cmdr Source: https://context7.com/evaera/cmdr/llms.txt Define a command argument that accepts either a string or an integer, where the integer must be prefixed with '#'. This is useful for arguments that can be identified by name or ID. ```lua -- Command accepting a string OR a number (prefixed with #) Args = { { Type = "string # integer", Name = "target", Description = "Player name or numeric user ID", }, } -- User types: evaera → implementation receives string "evaera" -- User types: #123456789 → implementation receives number 123456789 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.